Skip to content

Commit 8064fd5

Browse files
committed
1a: document interactions with no_std
1 parent 6156c10 commit 8064fd5

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

text/0000-build-std/4-stage-1a.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

text/0000-build-std/5-stage-1b.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ files ([?][rationale-cargo-lock]).
144144
145145
*See the following sections for rationale/alternatives:*
146146
147-
- [*Why not replace `#![no_std]` as the source-of-truth for whether a crate depends on `std`?*][rationale-replace-no_std]
148147
- [*Why explicitly declare dependencies on the standard library in `Cargo.toml`?*][rationale-why-explicit-deps]
149148
- [*Why disallow builtin dependencies to be combined with other sources?*][rationale-builtin-other-sources]
150149
- [*Why disallow builtin dependencies on other crates?*][rationale-no-builtin-other-crates]
@@ -539,28 +538,6 @@ This stage has no implications for the following Cargo subcommands:
539538
This section aims to justify all of the decisions made in the proposed design
540539
from [*Proposal*][proposal] and discuss why alternatives were not chosen.
541540
542-
## Why not replace `#![no_std]` as the source-of-truth for whether a crate depends on `std`?
543-
[rationale-replace-no_std]: #why-not-replace-no_std-as-the-source-of-truth-for-whether-a-crate-depends-on-std
544-
545-
Crates can currently use the crate attribute `#![no_std]` to indicate a lack of
546-
dependency on `std`. With `Cargo.toml` being used to express a dependency on the
547-
standard library (or lack thereof), it is unintuitive for there to be two
548-
sources-of-truth for this information.
549-
550-
`#![no_std]` serves two purposes - it stops the compiler from loading `std` from
551-
the sysroot and adding `extern crate std`, and it prevents the user from
552-
depending on anything from `std` accidentally.
553-
554-
`#![no_std]` could hypothetically be replaced by a lint to prevent use of the
555-
standard library and a change to the compiler so that it loads the `std`
556-
speculatively unless it is used.
557-
558-
However, while rustc does have some support for speculatively loading crates, it
559-
is not possible to do so and not declare them as a dependency in cross-crate
560-
metadata.
561-
562-
↩ [*Proposal*][proposal]
563-
564541
## Why explicitly declare dependencies on the standard library in `Cargo.toml`?
565542
[rationale-why-explicit-deps]: #why-explicitly-declare-dependencies-on-the-standard-library-in-cargotoml
566543

0 commit comments

Comments
 (0)