Skip to content

Commit 0ce54e6

Browse files
committed
Updates to no_implicit_prelude and no_std.
* Fix: no_implicit_prelude behaves differently in 2015. * Try to make it clearer how standard library stuff is injected into the crate.
1 parent 3847261 commit 0ce54e6

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/items/extern-crates.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ useful for crates that only need to be linked, but are never referenced, and
6565
will avoid being reported as unused.
6666

6767
The [`macro_use` attribute] works as usual and import the macro names
68-
into the macro-use prelude.
68+
into the [`macro_use` prelude].
6969

7070
## The `no_link` attribute
7171

@@ -77,6 +77,7 @@ crate to access only its macros.
7777
[RFC 940]: https://github.com/rust-lang/rfcs/blob/master/text/0940-hyphens-considered-harmful.md
7878
[`macro_use` attribute]: ../macros-by-example.md#the-macro_use-attribute
7979
[extern prelude]: ../names/preludes.md#extern-prelude
80+
[`macro_use` prelude]: ../names/preludes.md#macro_use-prelude
8081

8182
<script>
8283
(function() {

src/names/preludes.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,21 @@ alloc/test limitation.
5959
6060
### The `no_std` attribute
6161
62+
By default, the standard library is automatically included in the crate root
63+
module. The [`std`] crate is added to the root, along with an implicit
64+
[`macro_use` attribute] pulling in all macros exported from `std` into the
65+
[`macro_use` prelude]. Both [`core`] and [`std`] are added to the [extern
66+
prelude]. The [standard library prelude] includes everything from the
67+
[`std::prelude::v1`] module.
68+
6269
The *`no_std` [attribute]* may be applied at the crate level to prevent the
6370
[`std`] crate from being automatically added into scope. It does three things:
6471
6572
* Prevents `std` from being added to the [extern prelude](#extern-prelude).
6673
* Uses [`core::prelude::v1`] in the [standard library prelude] instead of
6774
[`std::prelude::v1`].
68-
* Injects the [`core`] crate into the crate root instead of `std`.
75+
* Injects the [`core`] crate into the crate root instead of [`std`], and pulls
76+
in all macros exported from `core` in the [`macro_use` prelude].
6977
7078
> **Note**: Using the core prelude over the standard prelude is useful when
7179
> either the crate is targeting a platform that does not support the standard
@@ -112,7 +120,12 @@ on a module to indicate that it should not automatically bring the [standard
112120
library prelude], [extern prelude], or [tool prelude] into scope for that
113121
module or any of its descendants.
114122
115-
This attribute does not affect the [language prelude] or [`macro_use` prelude].
123+
This attribute does not affect the [language prelude].
124+
125+
> **Edition Differences**: In the 2015 edition, the `no_implicit_prelude`
126+
> attribute does not affect the [`macro_use` prelude], and all macros exported
127+
> from the standard library are still included in the `macro_use` prelude.
128+
> Starting in the 2018 edition, it will remove the `macro_use` prelude.
116129
117130
[`alloc`]: ../../alloc/index.html
118131
[`Box`]: ../../std/boxed/struct.Box.html

0 commit comments

Comments
 (0)