Skip to content

Commit cd0f699

Browse files
authored
Merge pull request #1136 from mattheww/2022-01_preludes
Update the Preludes chapter for the 2021 edition changes to the standard library prelude
2 parents fe434ed + 0181f23 commit cd0f699

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/names/preludes.md

+25-9
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@ 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.
22+
The module used depends on the crate's edition, and on whether the [`no_std` attribute] is applied to the crate:
23+
24+
Edition | `no_std` not applied | `no_std` applied
25+
--------| --------------------------- | ----------------------------
26+
2015 | [`std::prelude::rust_2015`] | [`core::prelude::rust_2015`]
27+
2018 | [`std::prelude::rust_2018`] | [`core::prelude::rust_2018`]
28+
2021 | [`std::prelude::rust_2021`] | [`core::prelude::rust_2021`]
29+
30+
31+
> **Note**:
32+
>
33+
> [`std::prelude::rust_2015`] and [`std::prelude::rust_2018`] have the same contents as [`std::prelude::v1`].
34+
>
35+
> [`core::prelude::rust_2015`] and [`core::prelude::rust_2018`] have the same contents as [`core::prelude::v1`].
2436
2537
## Extern prelude
2638

@@ -63,15 +75,13 @@ By default, the standard library is automatically included in the crate root
6375
module. The [`std`] crate is added to the root, along with an implicit
6476
[`macro_use` attribute] pulling in all macros exported from `std` into the
6577
[`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.
78+
prelude].
6879
6980
The *`no_std` [attribute]* may be applied at the crate level to prevent the
7081
[`std`] crate from being automatically added into scope. It does three things:
7182
7283
* 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`].
84+
* Affects which module is used to make up the [standard library prelude] (as described above).
7585
* Injects the [`core`] crate into the crate root instead of [`std`], and pulls
7686
in all macros exported from `core` in the [`macro_use` prelude].
7787
@@ -129,14 +139,20 @@ This attribute does not affect the [language prelude].
129139
130140
[`alloc`]: ../../alloc/index.html
131141
[`Box`]: ../../std/boxed/struct.Box.html
132-
[`core::prelude::v1`]: ../../core/prelude/index.html
142+
[`core::prelude::v1`]: ../../core/prelude/v1/index.html
143+
[`core::prelude::rust_2015`]: ../../core/prelude/rust_2015/index.html
144+
[`core::prelude::rust_2018`]: ../../core/prelude/rust_2018/index.html
145+
[`core::prelude::rust_2021`]: ../../core/prelude/rust_2021/index.html
133146
[`core`]: ../../core/index.html
134147
[`extern crate`]: ../items/extern-crates.md
135148
[`macro_use` attribute]: ../macros-by-example.md#the-macro_use-attribute
136149
[`macro_use` prelude]: #macro_use-prelude
137150
[`no_std` attribute]: #the-no_std-attribute
138151
[`no_std` attribute]: #the-no_std-attribute
139-
[`std::prelude::v1`]: ../../std/prelude/index.html
152+
[`std::prelude::v1`]: ../../std/prelude/v1/index.html
153+
[`std::prelude::rust_2015`]: ../../std/prelude/rust_2015/index.html
154+
[`std::prelude::rust_2018`]: ../../std/prelude/rust_2018/index.html
155+
[`std::prelude::rust_2021`]: ../../std/prelude/rust_2021/index.html
140156
[`std`]: ../../std/index.html
141157
[`test`]: ../../test/index.html
142158
[attribute]: ../attributes.md

0 commit comments

Comments
 (0)