Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/names/preludes.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ r[names.preludes.extern.no_std]
### The `no_std` attribute

r[names.preludes.extern.no_std.intro]
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].
By default, the standard library is automatically included in the crate root module. The [`std`] crate is added to the root. Both [`core`] and [`std`] are added to the [extern prelude]. Standard library macros are imported via [use declarations] and are *not* part of the [`macro_use` prelude].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [std] crate is added to the root.

Is this sentence needed? I.e., is there any sense in which "the std crate is added to the root" but the core crate is not, or that this is not covered by "Both [core] and [std] are added to the [extern prelude]"?

My reading of the old text is that the sentence was there to support the restrictive clause (that erroneously was preceded by a comma, making the clause seem non-restrictive, i.e. that the part before the comma could stand on its own without the part after it):

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].

Copy link
Contributor

@traviscross traviscross Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, maybe this language and the line below

It does three things... Injects the [core] crate into the crate root instead of [std].

are leftovers from Rust 2015.

In Rust 2018 and later, this is a valid library:;

use ::core as c1;
use ::std as c2;

But it's not in Rust 2015. It gives the error

error[E0432]: unresolved import `core`
 --> src/lib.rs:1:5
  |
1 | use ::core as c1;
  |     ^^^^^^^^^^^^ no `core` in the root

unless #![no_std] is used, in which case it accepts that line but not use ::std. Interestingly, I don't see this documented specifically in the 2018 edition guide:

https://doc.rust-lang.org/nightly/edition-guide/rust-2018/path-changes.html

Perhaps this is simply an artifact of the change to make crates in the extern prelude accessible to use declarations. Did that then make it fully unobservable whether core is separately added to the crate root or not, or is there still some way to tell?

cc @ehuss

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking, this is all covered in:

I'm going to go get that merged.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll wait for #1913 to be merged and will update this PR on that.


r[names.preludes.extern.no_std.allowed-positions]
The *`no_std` [attribute]* may be applied at the crate level to prevent the
Expand All @@ -97,8 +93,7 @@ r[names.preludes.extern.no_std.extern]
r[names.preludes.extern.no_std.module]
* Affects which module is used to make up the [standard library prelude] (as described above).
r[names.preludes.extern.no_std.core]
* Injects the [`core`] crate into the crate root instead of [`std`], and pulls
in all macros exported from `core` in the [`macro_use` prelude].
* Injects the [`core`] crate into the crate root instead of [`std`].

> [!NOTE]
> Using the core prelude over the standard prelude is useful when either the crate is targeting a platform that does not support the standard library or is purposefully not using the capabilities of the standard library. Those capabilities are mainly dynamic memory allocation (e.g. `Box` and `Vec`) and file and network capabilities (e.g. `std::fs` and `std::io`).
Expand Down