From dfc94edcb60e73abca67cec9162f7bf57dc9bc9b Mon Sep 17 00:00:00 2001 From: Matthew Woodcraft Date: Sat, 15 Jan 2022 14:49:07 +0000 Subject: [PATCH 1/2] Update for 2021 edition standard library prelude changes --- src/names/preludes.md | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index 4c1568ada..fc8c50315 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -18,9 +18,22 @@ There are several different preludes: ## Standard library prelude -The standard library prelude includes names from the [`std::prelude::v1`] -module. If the [`no_std` attribute] is used, then it instead uses the names -from the [`core::prelude::v1`] module. +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: + +Edition | `no_std` not applied | `no_std` applied +--------| --------------------------- | ---------------------------- +2015 | [`std::prelude::rust_2015`] | [`core::prelude::rust_2015`] +2018 | [`std::prelude::rust_2018`] | [`core::prelude::rust_2018`] +2021 | [`std::prelude::rust_2021`] | [`core::prelude::rust_2021`] + +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. + + +> **Note**: +> +> [`std::prelude::rust_2015`] and [`std::prelude::rust_2018`] have the same contents as [`std::prelude::v1`]. +> +> [`core::prelude::rust_2015`] and [`core::prelude::rust_2018`] have the same contents as [`core::prelude::v1`]. ## Extern prelude @@ -63,15 +76,13 @@ By default, the standard library is automatically included in the crate root module. The [`std`] crate is added to the root, along with an implicit [`macro_use` attribute] pulling in all macros exported from `std` into the [`macro_use` prelude]. Both [`core`] and [`std`] are added to the [extern -prelude]. The [standard library prelude] includes everything from the -[`std::prelude::v1`] module. +prelude]. The *`no_std` [attribute]* may be applied at the crate level to prevent the [`std`] crate from being automatically added into scope. It does three things: * Prevents `std` from being added to the [extern prelude](#extern-prelude). -* Uses [`core::prelude::v1`] in the [standard library prelude] instead of - [`std::prelude::v1`]. +* Affects which module is used to make up the [standard library prelude] (as described above). * Injects the [`core`] crate into the crate root instead of [`std`], and pulls in all macros exported from `core` in the [`macro_use` prelude]. @@ -130,6 +141,9 @@ This attribute does not affect the [language prelude]. [`alloc`]: ../../alloc/index.html [`Box`]: ../../std/boxed/struct.Box.html [`core::prelude::v1`]: ../../core/prelude/index.html +[`core::prelude::rust_2015`]: ../../core/prelude/index.html +[`core::prelude::rust_2018`]: ../../core/prelude/index.html +[`core::prelude::rust_2021`]: ../../core/prelude/index.html [`core`]: ../../core/index.html [`extern crate`]: ../items/extern-crates.md [`macro_use` attribute]: ../macros-by-example.md#the-macro_use-attribute @@ -137,6 +151,9 @@ This attribute does not affect the [language prelude]. [`no_std` attribute]: #the-no_std-attribute [`no_std` attribute]: #the-no_std-attribute [`std::prelude::v1`]: ../../std/prelude/index.html +[`std::prelude::rust_2015`]: ../../std/prelude/index.html +[`std::prelude::rust_2018`]: ../../std/prelude/index.html +[`std::prelude::rust_2021`]: ../../std/prelude/index.html [`std`]: ../../std/index.html [`test`]: ../../test/index.html [attribute]: ../attributes.md From 0181f237f508a8109d99db76a4a5ab48d6132b93 Mon Sep 17 00:00:00 2001 From: Matthew Woodcraft Date: Thu, 20 Jan 2022 21:27:26 +0000 Subject: [PATCH 2/2] 2021 edition standard library prelude changes: address review comments --- src/names/preludes.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/names/preludes.md b/src/names/preludes.md index fc8c50315..00a112948 100644 --- a/src/names/preludes.md +++ b/src/names/preludes.md @@ -18,7 +18,8 @@ There are several different preludes: ## Standard library prelude -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: +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: Edition | `no_std` not applied | `no_std` applied --------| --------------------------- | ---------------------------- @@ -26,8 +27,6 @@ Edition | `no_std` not applied | `no_std` applied 2018 | [`std::prelude::rust_2018`] | [`core::prelude::rust_2018`] 2021 | [`std::prelude::rust_2021`] | [`core::prelude::rust_2021`] -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. - > **Note**: > @@ -140,20 +139,20 @@ This attribute does not affect the [language prelude]. [`alloc`]: ../../alloc/index.html [`Box`]: ../../std/boxed/struct.Box.html -[`core::prelude::v1`]: ../../core/prelude/index.html -[`core::prelude::rust_2015`]: ../../core/prelude/index.html -[`core::prelude::rust_2018`]: ../../core/prelude/index.html -[`core::prelude::rust_2021`]: ../../core/prelude/index.html +[`core::prelude::v1`]: ../../core/prelude/v1/index.html +[`core::prelude::rust_2015`]: ../../core/prelude/rust_2015/index.html +[`core::prelude::rust_2018`]: ../../core/prelude/rust_2018/index.html +[`core::prelude::rust_2021`]: ../../core/prelude/rust_2021/index.html [`core`]: ../../core/index.html [`extern crate`]: ../items/extern-crates.md [`macro_use` attribute]: ../macros-by-example.md#the-macro_use-attribute [`macro_use` prelude]: #macro_use-prelude [`no_std` attribute]: #the-no_std-attribute [`no_std` attribute]: #the-no_std-attribute -[`std::prelude::v1`]: ../../std/prelude/index.html -[`std::prelude::rust_2015`]: ../../std/prelude/index.html -[`std::prelude::rust_2018`]: ../../std/prelude/index.html -[`std::prelude::rust_2021`]: ../../std/prelude/index.html +[`std::prelude::v1`]: ../../std/prelude/v1/index.html +[`std::prelude::rust_2015`]: ../../std/prelude/rust_2015/index.html +[`std::prelude::rust_2018`]: ../../std/prelude/rust_2018/index.html +[`std::prelude::rust_2021`]: ../../std/prelude/rust_2021/index.html [`std`]: ../../std/index.html [`test`]: ../../test/index.html [attribute]: ../attributes.md