Skip to content

Commit e17bfbb

Browse files
committed
Don't use a conditional no_std attribute.
1 parent d087aeb commit e17bfbb

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/doc/src/reference/features-examples.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,24 @@ usually builds with the feature off.
4747
Some packages want to support both [`no_std`] and `std` environments. This is
4848
useful for supporting embedded and resource-constrained platforms, but still
4949
allowing extended capabilities for platforms that support the full standard
50-
library. The [`memchr`] package defines a [`std` feature] that is [enabled by
51-
default][memchr-default]. At the top of the library, it [conditionally enables
52-
the `no_std` attribute][memchr-nostd]. Then, in various places in the code, it
53-
uses `#[cfg(feature = "std")]` attributes to conditionally enable extra
54-
functionality. For example, when `std` is enabled, it can do [runtime CPU
55-
feature detection].
50+
library.
51+
52+
The [`wasm-bindgen`] package defines a [`std` feature][wasm-bindgen-std] that
53+
is [enabled by default][wasm-bindgen-default]. At the top of the library, it
54+
[unconditionally enables the `no_std` attribute][wasm-bindgen-no_std]. This
55+
ensures that `std` and the [`std` prelude] are not automatically in scope.
56+
Then, in various places in the code ([example1][wasm-bindgen-cfg1],
57+
[example2][wasm-bindgen-cfg2]), it uses `#[cfg(feature = "std")]` attributes
58+
to conditionally enable extra functionality that requires `std`.
5659

5760
[`no_std`]: ../../reference/crates-and-source-files.html#preludes-and-no_std
58-
[`memchr`]: https://crates.io/crates/memchr
59-
[`std` feature]: https://github.com/BurntSushi/rust-memchr/blob/2.3.4/Cargo.toml#L21-L25
60-
[memchr-default]: https://github.com/BurntSushi/rust-memchr/blob/2.3.4/Cargo.toml#L19
61-
[memchr-nostd]: https://github.com/BurntSushi/rust-memchr/blob/2.3.4/src/lib.rs#L23
62-
[runtime CPU feature detection]: https://github.com/BurntSushi/rust-memchr/blob/2.3.4/src/x86/mod.rs#L62-L66
61+
[`wasm-bindgen`]: https://crates.io/crates/wasm-bindgen
62+
[`std` prelude]: ../../std/prelude/index.html
63+
[wasm-bindgen-std]: https://github.com/rustwasm/wasm-bindgen/blob/0.2.69/Cargo.toml#L25
64+
[wasm-bindgen-default]: https://github.com/rustwasm/wasm-bindgen/blob/0.2.69/Cargo.toml#L23
65+
[wasm-bindgen-no_std]: https://github.com/rustwasm/wasm-bindgen/blob/0.2.69/src/lib.rs#L8
66+
[wasm-bindgen-cfg1]: https://github.com/rustwasm/wasm-bindgen/blob/0.2.69/src/lib.rs#L270-L273
67+
[wasm-bindgen-cfg2]: https://github.com/rustwasm/wasm-bindgen/blob/0.2.69/src/lib.rs#L67-L75
6368

6469
### Re-exporting dependency features
6570

src/doc/src/reference/features.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,20 @@ not** use a `no_std` feature. Instead, use a `std` feature that *enables*
262262
`std`. For example:
263263

264264
```rust
265-
#![cfg_attr(not(feature = "std"), no_std)]
265+
#![no_std]
266+
267+
#[cfg(feature = "std")]
268+
extern crate std;
266269

267270
#[cfg(feature = "std")]
268271
pub fn function_that_requires_std() {
269272
// ...
270273
}
271274
```
272275

276+
[`no_std`]: ../../reference/crates-and-source-files.html#preludes-and-no_std
277+
[features section]: resolver.md#features
278+
273279
#### Mutually exclusive features
274280

275281
There are rare cases where features may be mutually incompatible with one
@@ -294,9 +300,7 @@ Instead of using mutually exclusive features, consider some other options:
294300
command-line argument, or environment variable to choose which behavior to
295301
enable.
296302

297-
[`no_std`]: ../../reference/crates-and-source-files.html#preludes-and-no_std
298303
[`cfg-if`]: https://crates.io/crates/cfg-if
299-
[features section]: resolver.md#features
300304
[feature-precedence]: features-examples.md#feature-precedence
301305

302306
#### Inspecting resolved features

0 commit comments

Comments
 (0)