Skip to content

Commit 202d6bd

Browse files
committed
Rework the flow of the check-cfg blog post with latest updates
1 parent 25793d6 commit 202d6bd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

posts/2024-05-06-check-cfg.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,25 @@ fn win() {}
5252

5353
![cargo-check](../../../../images/2024-05-06-check-cfg/cargo-check.svg)
5454

55-
## Expecting static cfgs
55+
## Expecting custom cfgs
5656

5757
*UPDATE: This section was added with the release of nightly-2024-05-19.*
5858

59-
Some crates might use cfgs, like `loom`, `fuzzing` which are always statically known at compile time. For those cases, Cargo provides via the `[lints]` table a way to statically declare those cfgs as expected.
59+
> In Cargo point-of-view: a custom cfg is one that is neither defined by `rustc` nor by a Cargo feature. Think of `tokio_unstable`, `has_foo`, ... but not `feature = "lasers"`, `unix` or `debug_assertions`
60+
61+
Some crates might use custom cfgs, like `loom`, `fuzzing` or `tokio_unstable` that they expected from the environment (`RUSTFLAGS` or other means) and which are always statically known at compile time. For those cases, Cargo provides via the `[lints]` table a way to statically declare those cfgs as expected.
6062

61-
It is done through the special `check-cfg` config under `[lints.rust.unexpected_cfgs]`:
63+
Defining those custom cfgs as expected is done through the special `check-cfg` config under `[lints.rust.unexpected_cfgs]`:
6264

6365
*`Cargo.toml`*
6466
```toml
6567
[lints.rust]
6668
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)', 'cfg(fuzzing)'] }
6769
```
6870

69-
## Custom cfgs and build scripts
70-
71-
> In Cargo point-of-view: a custom cfg is one that is neither defined by `rustc` nor by a Cargo feature. Think of `tokio_unstable`, `has_foo`, ... but not `feature = "lasers"`, `unix` or `debug_assertions`
71+
## Custom cfgs in build scripts
7272

73-
Some crates use custom cfgs that they either expected from the environment (`RUSTFLAGS`or other means) or is enabled by some logic in the crate `build.rs`. For those crates Cargo provides a new instruction: [`cargo::rustc-check-cfg`](https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg)[^2] (or `cargo:rustc-check-cfg` for older Cargo version).
73+
On the other hand some crates use custom cfgs that are enabled by some logic in the crate `build.rs`. For those crates Cargo provides a new instruction: [`cargo::rustc-check-cfg`](https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg)[^2] (or `cargo:rustc-check-cfg` for older Cargo version).
7474

7575
[^2]: `cargo::rustc-check-cfg` will start working in Rust 1.80 (or nightly-2024-05-05). From Rust 1.77 to Rust 1.79 *(inclusive)* it is silently ignored. In Rust 1.76 and below a warning is emitted when used without the unstable Cargo flag `-Zcheck-cfg`.
7676

0 commit comments

Comments
 (0)