Skip to content

Commit dfc94ed

Browse files
committed
Update for 2021 edition standard library prelude changes
1 parent 5e89e63 commit dfc94ed

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/names/preludes.md

+24-7
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,22 @@ There are several different preludes:
1818

1919
## Standard library prelude
2020

21-
The standard library prelude includes names from the [`std::prelude::v1`]
22-
module. If the [`no_std` attribute] is used, then it instead uses the names
23-
from the [`core::prelude::v1`] module.
21+
Each crate has a standard library prelude, which consists of the names from a single standard library module. The module used depends on the crate's edition, and on whether the [`no_std` attribute] is applied to the crate:
22+
23+
Edition | `no_std` not applied | `no_std` applied
24+
--------| --------------------------- | ----------------------------
25+
2015 | [`std::prelude::rust_2015`] | [`core::prelude::rust_2015`]
26+
2018 | [`std::prelude::rust_2018`] | [`core::prelude::rust_2018`]
27+
2021 | [`std::prelude::rust_2021`] | [`core::prelude::rust_2021`]
28+
29+
This choice of prelude is in effect throughout the crate, including code generated by macros defined in crates with a different edition or `no_std` attribute.
30+
31+
32+
> **Note**:
33+
>
34+
> [`std::prelude::rust_2015`] and [`std::prelude::rust_2018`] have the same contents as [`std::prelude::v1`].
35+
>
36+
> [`core::prelude::rust_2015`] and [`core::prelude::rust_2018`] have the same contents as [`core::prelude::v1`].
2437
2538
## Extern prelude
2639

@@ -63,15 +76,13 @@ By default, the standard library is automatically included in the crate root
6376
module. The [`std`] crate is added to the root, along with an implicit
6477
[`macro_use` attribute] pulling in all macros exported from `std` into the
6578
[`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.
79+
prelude].
6880
6981
The *`no_std` [attribute]* may be applied at the crate level to prevent the
7082
[`std`] crate from being automatically added into scope. It does three things:
7183
7284
* Prevents `std` from being added to the [extern prelude](#extern-prelude).
73-
* Uses [`core::prelude::v1`] in the [standard library prelude] instead of
74-
[`std::prelude::v1`].
85+
* Affects which module is used to make up the [standard library prelude] (as described above).
7586
* Injects the [`core`] crate into the crate root instead of [`std`], and pulls
7687
in all macros exported from `core` in the [`macro_use` prelude].
7788
@@ -130,13 +141,19 @@ This attribute does not affect the [language prelude].
130141
[`alloc`]: ../../alloc/index.html
131142
[`Box`]: ../../std/boxed/struct.Box.html
132143
[`core::prelude::v1`]: ../../core/prelude/index.html
144+
[`core::prelude::rust_2015`]: ../../core/prelude/index.html
145+
[`core::prelude::rust_2018`]: ../../core/prelude/index.html
146+
[`core::prelude::rust_2021`]: ../../core/prelude/index.html
133147
[`core`]: ../../core/index.html
134148
[`extern crate`]: ../items/extern-crates.md
135149
[`macro_use` attribute]: ../macros-by-example.md#the-macro_use-attribute
136150
[`macro_use` prelude]: #macro_use-prelude
137151
[`no_std` attribute]: #the-no_std-attribute
138152
[`no_std` attribute]: #the-no_std-attribute
139153
[`std::prelude::v1`]: ../../std/prelude/index.html
154+
[`std::prelude::rust_2015`]: ../../std/prelude/index.html
155+
[`std::prelude::rust_2018`]: ../../std/prelude/index.html
156+
[`std::prelude::rust_2021`]: ../../std/prelude/index.html
140157
[`std`]: ../../std/index.html
141158
[`test`]: ../../test/index.html
142159
[attribute]: ../attributes.md

0 commit comments

Comments
 (0)