@@ -124,6 +124,18 @@ newly-built, as appropriate).
124124- [ * What should the "always" and "off" values of ` build-std ` be named?* ] [ unresolved-config-values ]
125125- [ * What should ` build-std-crate ` be named?* ] [ unresolved-build-std-crate-name ]
126126
127+ ## Interactions with ` #![no_std] `
128+ [ interactions-with-no_std ] : #interactions-with-no_std
129+
130+ Behaviour of crates using ` #![no_std] ` will change even if the standard library
131+ is rebuilt and passed via ` --extern ` to rustc. Due to ` #![no_std] ` , rustc will
132+ not automatically attempt to load std, but if the user writes ` extern crate std `
133+ then the rebuilt std will be found.
134+
135+ * See the following sections for rationale/alternatives:*
136+
137+ - [ * Why not replace ` #![no_std] ` as the source-of-truth for whether a crate depends on ` std ` ?* ] [ rationale-replace-no_std ]
138+
127139## ` restricted_std `
128140[ restricted_std ] : #restricted_std
129141
@@ -643,6 +655,28 @@ which further limits potential use cases to those without `target-modifiers`.
643655
644656↩ [ * Proposal* ] [ proposal ]
645657
658+ ## Why not replace ` #![no_std] ` as the source-of-truth for whether a crate depends on ` std ` ?
659+ [ rationale-replace-no_std ] : #why-not-replace-no_std-as-the-source-of-truth-for-whether-a-crate-depends-on-std
660+
661+ Crates can currently use the crate attribute ` #![no_std] ` to indicate a lack of
662+ dependency on ` std ` . With ` Cargo.toml ` being used to express a dependency on the
663+ standard library (or lack thereof), it is unintuitive for there to be two
664+ sources-of-truth for this information.
665+
666+ ` #![no_std] ` serves two purposes - it stops the compiler from loading ` std ` from
667+ the sysroot and adding ` extern crate std ` , and it prevents the user from
668+ depending on anything from ` std ` accidentally.
669+
670+ ` #![no_std] ` could hypothetically be replaced by a lint to prevent use of the
671+ standard library and a change to the compiler so that it loads the ` std `
672+ speculatively unless it is used.
673+
674+ However, while rustc does have some support for speculatively loading crates, it
675+ is not possible to do so and not declare them as a dependency in cross-crate
676+ metadata.
677+
678+ ↩ [ * Interactions with ` #![no_std] ` * ] [ interactions-with-no_std ]
679+
646680### Why remove ` restricted_std ` ?
647681[ rationale-remove-restricted-std ] : #why-remove-restricted_std
648682
0 commit comments