Skip to content

Commit e464933

Browse files
ehusstraviscross
authored andcommitted
Rewrite no_std
The current text was a little bit of a mess and had some subtle inaccuracies. This reworks so that the intro follows the template, and just generally introduces the attribute. `allowed-positions` now just specifies the allowed positions. I reworked the behavior changes caused by no_std into proper separate rules. `std` is not injected into the crate root anymore starting with edition 2018.
1 parent 4f50d52 commit e464933

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/names/preludes.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ r[names.preludes.extern.no_std]
8080
### The `no_std` attribute
8181
8282
r[names.preludes.extern.no_std.intro]
83-
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].
83+
The *`no_std` [attribute][attributes]* is used to prevent the automatic linking of the [`std`] crate, deferring to [`core`] instead.
8484
8585
> [!EXAMPLE]
8686
> <!-- ignore: test infrastructure can't handle no_std -->
@@ -98,18 +98,16 @@ r[names.preludes.extern.no_std.syntax]
9898
The `no_std` attribute uses the [MetaWord] syntax and thus does not take any inputs.
9999
100100
r[names.preludes.extern.no_std.allowed-positions]
101-
The *`no_std` [attribute]* may be applied at the crate level to prevent the [`std`] crate from being automatically added into scope.
101+
The `no_std` attribute may only be applied to the crate root.
102102
103-
It does three things:
104103
105-
r[names.preludes.extern.no_std.extern]
106-
* Prevents `std` from being added to the [extern prelude](#extern-prelude).
107104
r[names.preludes.extern.no_std.module]
108-
* Affects which module is used to make up the [standard library prelude] (as described above).
109-
r[names.preludes.extern.no_std.core]
110-
* Injects the [`core`] crate into the crate root instead of [`std`], and pulls in all macros exported from `core` in the [`macro_use` prelude].
105+
The `no_std` attribute changes the [standard library prelude] to use the `core` prelude instead of `std`.
111106
107+
r[names.preludes.extern.no_std.inject]
108+
By default, the [`std`] crate is injected into the [extern prelude], and all macros exported from `std` are added to the [`macro_use` prelude].
112109
110+
If the `no_std` attribute is specified, then the [`core`] crate is used instead of `std`, and similarly all macros exported from `core` are placed into the [`macro_use` prelude].
113111
114112
r[names.preludes.lang]
115113
## Language prelude

0 commit comments

Comments
 (0)