Skip to content

insignificant fix to rust manual and tutorial #12362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,35 +752,35 @@ mod task {
#### View items

~~~~ {.ebnf .gram}
view_item : extern_mod_decl | use_decl ;
view_item : extern_crate_decl | use_decl ;
~~~~

A view item manages the namespace of a module.
View items do not define new items, but rather, simply change other items' visibility.
There are several kinds of view item:

* [`extern crate` declarations](#extern-mod-declarations)
* [`extern crate` declarations](#extern-crate-declarations)
* [`use` declarations](#use-declarations)

##### Extern mod declarations
##### Extern crate declarations

~~~~ {.ebnf .gram}
extern_mod_decl : "extern" "mod" ident [ '(' link_attrs ')' ] ? [ '=' string_lit ] ? ;
extern_crate_decl : "extern" "crate" ident [ '(' link_attrs ')' ] ? [ '=' string_lit ] ? ;
link_attrs : link_attr [ ',' link_attrs ] + ;
link_attr : ident '=' literal ;
~~~~

An _`extern crate` declaration_ specifies a dependency on an external crate.
The external crate is then bound into the declaring scope
as the `ident` provided in the `extern_mod_decl`.
The external crate is then bound into the declaring scope as the `ident` provided
in the `extern_crate_decl`.

The external crate is resolved to a specific `soname` at compile time, and a
runtime linkage requirement to that `soname` is passed to the linker for
loading at runtime. The `soname` is resolved at compile time by scanning the
compiler's library path and matching the optional `crateid` provided as a string literal
against the `crateid` attributes that were declared on the external crate when
it was compiled. If no `crateid` is provided, a default `name` attribute is
assumed, equal to the `ident` given in the `extern_mod_decl`.
assumed, equal to the `ident` given in the `extern_crate_decl`.

Four examples of `extern crate` declarations:

Expand Down Expand Up @@ -813,7 +813,7 @@ module item. These declarations may appear at the top of [modules](#modules) and

*Note*: Unlike in many languages,
`use` declarations in Rust do *not* declare linkage dependency with external crates.
Rather, [`extern crate` declarations](#extern-mod-declarations) declare linkage dependencies.
Rather, [`extern crate` declarations](#extern-crate-declarations) declare linkage dependencies.

Use declarations support a number of convenient shortcuts:

Expand Down
19 changes: 6 additions & 13 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,7 @@ reject the previous example if the arm with the wildcard pattern was
omitted.

A powerful application of pattern matching is *destructuring*:
matching in order to bind names to the contents of data
types.
matching in order to bind names to the contents of data types.

> ***Note:*** The following code makes use of tuples (`(f64, f64)`) which
> are explained in section 5.3. For now you can think of tuples as a list of
Expand Down Expand Up @@ -2726,7 +2725,8 @@ pub mod barn {

In short, `mod foo;` is just syntactic sugar for `mod foo { /* content of <...>/foo.rs or <...>/foo/mod.rs */ }`.

This also means that having two or more identical `mod foo;` declarations somewhere in your crate hierarchy is generally a bad idea,
This also means that having two or more identical `mod foo;` declarations
somewhere in your crate hierarchy is generally a bad idea,
just like copy-and-paste-ing a module into multiple places is a bad idea.
Both will result in duplicate and mutually incompatible definitions.

Expand Down Expand Up @@ -3074,11 +3074,6 @@ fn main() {
It's a bit weird, but it's the result of shadowing rules that have been set that way because
they model most closely what people expect to shadow.

## Package ids

If you use `extern crate`, per default `rustc` will look for libraries in the library search path (which you can
extend with the `-L` switch).

## Crate metadata and settings

For every crate you can define a number of metadata items, such as link name, version or author.
Expand All @@ -3096,14 +3091,13 @@ Therefore, if you plan to compile your crate as a library, you should annotate i
// `lib.rs`

# #[crate_type = "lib"];
// Package ID
#[crate_id = "farm#2.5"];

// ...
# fn farm() {}
~~~~

You can also specify package ID information in a `extern crate` statement. For
You can also specify crate id information in a `extern crate` statement. For
example, these `extern crate` statements would both accept and select the
crate define above:

Expand Down Expand Up @@ -3161,7 +3155,7 @@ Now compile and run like this (adjust to your platform if necessary):
Notice that the library produced contains the version in the file name
as well as an inscrutable string of alphanumerics. As explained in the previous paragraph,
these are both part of Rust's library versioning scheme. The alphanumerics are
a hash representing the crates package ID.
a hash representing the crates id.

## The standard library and the prelude

Expand Down Expand Up @@ -3231,8 +3225,7 @@ library. You can link to a library such as `extra` with an `extern crate extra;
[extra library]: extra/index.html

Right now `extra` contains those definitions directly, but in the future it will likely just
re-export a bunch of 'officially blessed' crates that get managed with a
package manager.
re-export a bunch of 'officially blessed' crates that get managed with a package manager.

# What next?

Expand Down