@@ -40,9 +40,17 @@ extern crate hello_world; // hyphen replaced with an underscore
4040
4141## Extern Prelude
4242
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 imported with `extern crate orig_name as
47+ new_name` , then the symbol ` new_name` is instead 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 in the crate root.
51+
52+ The [ ` no_implicit_prelude ` ] attribute can be used on a module to disable
53+ prelude lookups within that module.
4654
4755> ** Edition Differences** : In the 2015 edition, crates in the extern prelude
4856> cannot be referenced via [ use declarations] , so it is generally standard
@@ -52,28 +60,20 @@ need for specifying `extern crate`.
5260> the extern prelude, so it is considered unidiomatic to use ` extern crate ` .
5361
5462> ** 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).
63+ > [ ` alloc ` ] , and [ ` test ` ] , are not automatically included with the ` --extern `
64+ > flag when using Cargo. They must be brought into scope with an `extern
65+ > crate` declaration, even in the 2018 edition.
5966>
6067> ``` rust
6168> extern crate proc_macro;
62- > // Cannot reference `proc_macro` directly because it is not in the extern prelude.
63- > // use proc_macro::TokenStream;
64- > // Instead, you must reference the item in scope from the `extern crate`
65- > // declaration.
66- > use self :: proc_macro :: TokenStream ;
69+ > use proc_macro :: TokenStream ;
6770> ```
6871
6972<! --
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
73+ The proc_macro / alloc / test limitation may be lifted if the `-- extern `
74+ flag is stabilized and used . See tracking issue
75+ https : // github.com/rust-lang/rust/issues/57288 and the unstable
76+ `-- extern ` flag added in https : // github.com/rust-lang/rust/pull/54116.
7777- ->
7878
7979## Underscore Imports
@@ -91,6 +91,8 @@ into the macro-use prelude.
9191[`#[macro_use]` attribute]: attributes. html#macro - related- attributes
9292[`alloc`]: https: // doc.rust-lang.org/alloc/
9393[`crate :: `]: paths. html#crate
94+ [`no_implicit_prelude`]: items/ modules. html#prelude- items
95+ [`no_std`]: crates- and- source- files. html#preludes- and- no_std
9496[`proc_macro`]: https: // doc.rust-lang.org/proc_macro/
9597[`self:: `]: paths. html#self
9698[`test`]: https: // doc.rust-lang.org/test/
0 commit comments