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 #118213 - Urgau:check-cfg-diagnostics-rustc-cargo, r=petrochenkov
Add more suggestions to unexpected cfg names and values
This pull request adds more suggestion to unexpected cfg names and values diagnostics:
- it first adds a links to the [rustc unstable book](https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html) or the [Cargo reference](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg), depending if rustc is invoked by Cargo
- it secondly adds a suggestion on how to expect the cfg name or value:
*excluding well known names and values*
- for Cargo: it suggest using a feature or `cargo:rust-check-cfg` in build script
- for rustc: it suggest using `--check-cfg` (with the correct invocation)
Those diagnostics improvements are directed towards enabling users to fix the issue if the previous suggestions weren't good enough.
r? `@petrochenkov`
db.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`"));
774
+
}
775
+
db.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
776
+
}else{
777
+
db.help(format!("to expect this configuration use `--check-cfg={inst}`"));
778
+
db.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
db.help(format!("consider adding `{value}` as a feature in `Cargo.toml`"));
835
+
}
836
+
}else{
837
+
db.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`"));
838
+
}
839
+
db.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
840
+
}else{
841
+
db.help(format!("to expect this configuration use `--check-cfg={inst}`"));
842
+
db.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
| ^^^^ help: there is a config with a similar name: `unix`
6
6
|
7
+
= help: to expect this configuration use `--check-cfg=cfg(uniz)`
8
+
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
Copy file name to clipboardexpand all lines: tests/rustdoc-ui/doctest/check-cfg-test.stderr
+2
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ LL | #[cfg(feature = "invalid")]
5
5
| ^^^^^^^^^^^^^^^^^^^
6
6
|
7
7
= note: expected values for `feature` are: `test`
8
+
= help: to expect this configuration use `--check-cfg=cfg(feature, values("invalid"))`
9
+
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
= help: to expect this configuration use `--check-cfg=cfg(FALSE)`
9
+
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
= help: consider using a Cargo feature instead or adding `println!("cargo:rustc-check-cfg=cfg(CONFIG_NVME, values(\"m\"))");` to the top of a `build.rs`
28
+
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> 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 a `build.rs`
20
+
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
21
+
22
+
warning: unexpected `cfg` condition value: `m`
23
+
--> $DIR/cargo-feature.rs:22:7
24
+
|
25
+
LL | #[cfg(CONFIG_NVME = "m")]
26
+
| ^^^^^^^^^^^^^^---
27
+
| |
28
+
| help: there is a expected value with a similar name: `"y"`
29
+
|
30
+
= note: expected values for `CONFIG_NVME` are: `y`
31
+
= help: consider using a Cargo feature instead or adding `println!("cargo:rustc-check-cfg=cfg(CONFIG_NVME, values(\"m\"))");` to the top of a `build.rs`
32
+
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
= help: to expect this configuration use `--check-cfg=cfg(target_architecture, values("arm"))`
9
+
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
= note: expected values for `target_pointer_width` are: `16`, `32`, `64`
8
+
= help: to expect this configuration use `--check-cfg=cfg(target_pointer_width, values("X"))`
9
+
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
Copy file name to clipboardexpand all lines: tests/ui/check-cfg/concat-values.stderr
+4
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ LL | #[cfg(my_cfg)]
5
5
| ^^^^^^
6
6
|
7
7
= note: expected values for `my_cfg` are: `bar`, `foo`
8
+
= help: to expect this configuration use `--check-cfg=cfg(my_cfg)`
9
+
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
8
10
= note: `#[warn(unexpected_cfgs)]` on by default
9
11
10
12
warning: unexpected `cfg` condition value: `unk`
@@ -14,6 +16,8 @@ LL | #[cfg(my_cfg = "unk")]
14
16
| ^^^^^^^^^^^^^^
15
17
|
16
18
= note: expected values for `my_cfg` are: `bar`, `foo`
19
+
= help: to expect this configuration use `--check-cfg=cfg(my_cfg, values("unk"))`
20
+
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
= help: consider using a Cargo feature instead or adding `println!("cargo:rustc-check-cfg=cfg(no_value, values(\"foo\"))");` to the top of a `build.rs`
52
+
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
53
+
help: there is a config with a similar name and no value
54
+
|
55
+
LL | #[cfg(no_values)]
56
+
| ~~~~~~~~~
57
+
58
+
warning: unexpected `cfg` condition value: `bar`
59
+
--> $DIR/diagnotics.rs:30:7
60
+
|
61
+
LL | #[cfg(no_values = "bar")]
62
+
| ^^^^^^^^^--------
63
+
| |
64
+
| help: remove the value
65
+
|
66
+
= note: no expected value for `no_values`
67
+
= help: consider using a Cargo feature instead or adding `println!("cargo:rustc-check-cfg=cfg(no_values, values(\"bar\"))");` to the top of a `build.rs`
68
+
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
0 commit comments