@@ -40,9 +40,17 @@ extern crate hello_world; // hyphen replaced with an underscore
40
40
41
41
## Extern Prelude
42
42
43
- External crates provided to the compiler are added to the "extern prelude"
44
- which exposes the crate names into lexical scope of every module without the
45
- need for specifying ` extern crate ` .
43
+ External crates imported with ` extern crate ` in the root module or provided to
44
+ the compiler (as with the ` --extern ` flag with ` rustc ` ) are added to the
45
+ "extern prelude". Crates in the extern prelude are in scope in the entire
46
+ crate, including inner modules. If renamed as in `extern crate orig_name as
47
+ new_name` , then the symbol ` new_name` is added to the prelude.
48
+
49
+ The ` core ` crate is always added to the extern prelude. The ` std ` crate
50
+ is added as long as the [ ` no_std ` ] attribute is not specified.
51
+
52
+ The [ ` no_implicit_prelude ` ] attribute can be used on a module to disable
53
+ prelude lookups within that module.
46
54
47
55
> ** Edition Differences** : In the 2015 edition, crates in the extern prelude
48
56
> cannot be referenced via [ use declarations] , so it is generally standard
@@ -51,11 +59,13 @@ need for specifying `extern crate`.
51
59
> Beginning in the 2018 edition, [ use declarations] can reference crates in
52
60
> the extern prelude, so it is considered unidiomatic to use ` extern crate ` .
53
61
54
- > ** Note** : Additional crates that ship with ` rustc ` , such as [ ` proc_macro ` ] ,
55
- > [ ` alloc ` ] , and [ ` test ` ] , currently aren't available in the extern prelude
56
- > and must be brought into scope with an ` extern crate ` declaration, even in
57
- > the 2018 edition. ` use ` paths must reference the ` extern crate ` item (such
58
- > as using [ ` crate:: ` ] or [ ` self:: ` ] path prefixes).
62
+ > ** Note** : Crates not explicitly named with the ` --extern ` flag with ` rustc `
63
+ > are not included in the extern prelude. This means that additional crates
64
+ > that ship with ` rustc ` , such as [ ` proc_macro ` ] , [ ` alloc ` ] , and [ ` test ` ] ,
65
+ > currently aren't available in the extern prelude and must be brought into
66
+ > scope with an ` extern crate ` declaration, even in the 2018 edition. ` use `
67
+ > paths must reference the ` extern crate ` item (such as using [ ` crate:: ` ] or
68
+ > [ ` self:: ` ] path prefixes).
59
69
>
60
70
> ``` rust
61
71
> extern crate proc_macro;
@@ -67,13 +77,10 @@ need for specifying `extern crate`.
67
77
> ```
68
78
69
79
<! --
70
- Possible upcoming changes that will change this :
71
- The `extern_crate_item_prelude ` unstable feature allows `extern crate ` to
72
- update the extern prelude in certain situations, see
73
- https: // github.com/rust-lang/rust/pull/54658
74
- Unstable `-- extern proc_macro` flag that would force the crate into the
75
- extern prelude.
76
- https: // github.com/rust-lang/rust/pull/54116
80
+ The proc_macro / alloc / test limitation may be lifted if the `-- extern `
81
+ flag is stabilized and used . See tracking issue
82
+ https : // github.com/rust-lang/rust/issues/57288 and the unstable
83
+ `-- extern ` flag added in https : // github.com/rust-lang/rust/pull/54116.
77
84
- ->
78
85
79
86
## Underscore Imports
@@ -91,6 +98,8 @@ into the macro-use prelude.
91
98
[`#[macro_use]` attribute]: attributes. html#macro - related- attributes
92
99
[`alloc`]: https: // doc.rust-lang.org/alloc/
93
100
[`crate :: `]: paths. html#crate
101
+ [`no_implicit_prelude`]: items/ modules. html#prelude- items
102
+ [`no_std`]: crates- and- source- files. html#preludes- and- no_std
94
103
[`proc_macro`]: https: // doc.rust-lang.org/proc_macro/
95
104
[`self:: `]: paths. html#self
96
105
[`test`]: https: // doc.rust-lang.org/test/
0 commit comments