You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #125219 - Urgau:check-cfg-cargo-config, r=fmease
Update `unexpected_cfgs` lint for Cargo new `check-cfg` config
This PR updates the diagnostics output of the `unexpected_cfgs` lint for Cargo new `check-cfg` config.
It's a simple and cost-less alternative to the build-script `cargo::rustc-check-cfg` instruction.
```toml
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] }
```
This PR also adds a Cargo specific section regarding check-cfg and Cargo inside rustc's book (motivation is described inside the file, but mainly check-cfg is a rustc feature not a Cargo one, Cargo only enabled the feature, it does not own it; T-cargo even considers the `check-cfg` lint config to be an implementation detail).
This PR also updates the links to refer to that sub-page when using Cargo from rustc.
As well as updating the lint doc to refer to the check-cfg docs.
~**Not to be merged before rust-lang/cargo#13913 reaches master!**~ (EDIT: merged in #125237)
`@rustbot` label +F-check-cfg
r? `@fmease` *(feel free to roll)*
Fixes#124800
cc `@epage` `@weihanglo`
let inst = |escape_quotes| to_check_cfg_arg(name, value.map(|(v, _s)| v), escape_quotes);
164
177
165
178
if is_from_cargo {
166
179
if !is_feature_cfg {
167
-
diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo::rustc-check-cfg={inst}\");` to the top of the `build.rs`"));
180
+
diag.help(format!("consider using a Cargo feature instead"));
181
+
diag.help(format!("or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{}'] }}", inst(EscapeQuotes::No)));
182
+
diag.help(format!("or consider adding `println!(\"cargo::rustc-check-cfg={}\");` to the top of the `build.rs`", inst(EscapeQuotes::Yes)));
168
183
}
169
-
diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration");
184
+
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration");
170
185
}else{
171
-
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
186
+
let inst = inst(EscapeQuotes::No);
187
+
diag.help(format!("to expect this configuration use `--check-cfg={inst}`",));
172
188
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
diag.help("consider defining some features in `Cargo.toml`");
267
278
}
268
279
}elseif !is_cfg_a_well_know_name {
269
-
diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo::rustc-check-cfg={inst}\");` to the top of the `build.rs`"));
280
+
diag.help(format!("consider using a Cargo feature instead"));
281
+
diag.help(format!("or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{}'] }}", inst(EscapeQuotes::No)));
282
+
diag.help(format!("or consider adding `println!(\"cargo::rustc-check-cfg={}\");` to the top of the `build.rs`", inst(EscapeQuotes::Yes)));
270
283
}
271
-
diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration");
284
+
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration");
272
285
}else{
273
286
if !is_cfg_a_well_know_name {
274
-
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
287
+
let inst = inst(EscapeQuotes::No);
288
+
diag.help(format!("to expect this configuration use `--check-cfg={inst}`",));
275
289
}
276
290
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
Copy file name to clipboardExpand all lines: tests/ui/check-cfg/cargo-feature.none.stderr
+14-6
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ LL | #[cfg(feature = "serde")]
6
6
|
7
7
= note: no expected values for `feature`
8
8
= help: consider adding `serde` as a feature in `Cargo.toml`
9
-
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
9
+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
10
10
= note: `#[warn(unexpected_cfgs)]` on by default
11
11
12
12
warning: unexpected `cfg` condition value: (none)
@@ -17,7 +17,7 @@ LL | #[cfg(feature)]
17
17
|
18
18
= note: no expected values for `feature`
19
19
= help: consider defining some features in `Cargo.toml`
20
-
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
20
+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
= help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(tokio_unstable)");` to the top of the `build.rs`
30
-
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
29
+
= help: consider using a Cargo feature instead
30
+
= help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
= help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(CONFIG_NVME, values(\"m\"))");` to the top of the `build.rs`
39
-
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
42
+
= help: consider using a Cargo feature instead
43
+
= help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
Copy file name to clipboardExpand all lines: tests/ui/check-cfg/cargo-feature.some.stderr
+14-6
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ LL | #[cfg(feature = "serde")]
6
6
|
7
7
= note: expected values for `feature` are: `bitcode`
8
8
= help: consider adding `serde` as a feature in `Cargo.toml`
9
-
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
9
+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
10
10
= note: `#[warn(unexpected_cfgs)]` on by default
11
11
12
12
warning: unexpected `cfg` condition value: (none)
@@ -17,7 +17,7 @@ LL | #[cfg(feature)]
17
17
|
18
18
= note: expected values for `feature` are: `bitcode`
19
19
= help: consider defining some features in `Cargo.toml`
20
-
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
20
+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
= help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(tokio_unstable)");` to the top of the `build.rs`
30
-
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
29
+
= help: consider using a Cargo feature instead
30
+
= help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
= help: or consider adding `println!("cargo::rustc-check-cfg=cfg(tokio_unstable)");` to the top of the `build.rs`
34
+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
31
35
32
36
warning: unexpected `cfg` condition value: `m`
33
37
--> $DIR/cargo-feature.rs:26:7
@@ -38,8 +42,12 @@ LL | #[cfg(CONFIG_NVME = "m")]
38
42
| help: there is a expected value with a similar name: `"y"`
39
43
|
40
44
= note: expected values for `CONFIG_NVME` are: `y`
41
-
= help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(CONFIG_NVME, values(\"m\"))");` to the top of the `build.rs`
42
-
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
45
+
= help: consider using a Cargo feature instead
46
+
= help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
0 commit comments