mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Improve check-cfg diagnostics (part 1)
This commit is contained in:
parent
d327d5b168
commit
a5f8dba4cd
@ -591,7 +591,7 @@ pub fn cfg_matches(
|
||||
"unexpected `cfg` condition value",
|
||||
BuiltinLintDiagnostics::UnexpectedCfg(
|
||||
(cfg.name, cfg.name_span),
|
||||
cfg.value_span.map(|vs| (cfg.value.unwrap(), vs)),
|
||||
cfg.value.map(|v| (v, cfg.value_span.unwrap())),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ pub trait LintContext: Sized {
|
||||
|
||||
// Suggest the most probable if we found one
|
||||
if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) {
|
||||
db.span_suggestion(name_span, "did you mean", best_match, Applicability::MaybeIncorrect);
|
||||
db.span_suggestion(name_span, "there is an config with a similar name", best_match, Applicability::MaybeIncorrect);
|
||||
}
|
||||
},
|
||||
BuiltinLintDiagnostics::UnexpectedCfg((name, name_span), Some((value, value_span))) => {
|
||||
@ -794,20 +794,20 @@ pub trait LintContext: Sized {
|
||||
let mut possibilities = possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
|
||||
possibilities.sort();
|
||||
|
||||
let possibilities = possibilities.join(", ");
|
||||
db.note(format!("expected values for `{name}` are: {possibilities}"));
|
||||
let possibilities = possibilities.join("`, `");
|
||||
let none = if have_none_possibility { "(none), " } else { "" };
|
||||
|
||||
db.note(format!("expected values for `{name}` are: {none}`{possibilities}`"));
|
||||
}
|
||||
|
||||
// Suggest the most probable if we found one
|
||||
if let Some(best_match) = find_best_match_for_name(&possibilities, value, None) {
|
||||
db.span_suggestion(value_span, "did you mean", format!("\"{best_match}\""), Applicability::MaybeIncorrect);
|
||||
db.span_suggestion(value_span, "there is an expected value with a similar name", format!("\"{best_match}\""), Applicability::MaybeIncorrect);
|
||||
}
|
||||
} else {
|
||||
} else if have_none_possibility {
|
||||
db.note(format!("no expected value for `{name}`"));
|
||||
if name != sym::feature {
|
||||
db.span_suggestion(name_span.shrink_to_hi().to(value_span), "remove the value", "", Applicability::MaybeIncorrect);
|
||||
}
|
||||
}
|
||||
},
|
||||
BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(new_span, suggestion) => {
|
||||
db.multipart_suggestion(
|
||||
|
@ -2,7 +2,7 @@ warning: unexpected `cfg` condition name
|
||||
--> $DIR/check-cfg.rs:5:7
|
||||
|
|
||||
LL | #[cfg(uniz)]
|
||||
| ^^^^ help: did you mean: `unix`
|
||||
| ^^^^ help: there is a config with a similar name: `unix`
|
||||
|
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
|
@ -4,7 +4,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | #[cfg(feature = "invalid")]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: test
|
||||
= note: expected values for `feature` are: `test`
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
@ -4,7 +4,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | #[cfg(target(os = "linux", arch = "X"))]
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `target_arch` are: aarch64, arm, avr, bpf, hexagon, loongarch64, m68k, mips, mips64, msp430, nvptx64, powerpc, powerpc64, riscv32, riscv64, s390x, sparc, sparc64, wasm32, wasm64, x86, x86_64
|
||||
= note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips64`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64`
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
@ -2,7 +2,7 @@ warning: unexpected `cfg` condition name
|
||||
--> $DIR/invalid-cfg-name.rs:7:7
|
||||
|
|
||||
LL | #[cfg(widnows)]
|
||||
| ^^^^^^^ help: did you mean: `windows`
|
||||
| ^^^^^^^ help: there is an config with a similar name: `windows`
|
||||
|
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
|
@ -4,9 +4,9 @@ warning: unexpected `cfg` condition value
|
||||
LL | #[cfg(feature = "sedre")]
|
||||
| ^^^^^^^^^^-------
|
||||
| |
|
||||
| help: did you mean: `"serde"`
|
||||
| help: there is an expected value with a similar name: `"serde"`
|
||||
|
|
||||
= note: expected values for `feature` are: full, serde
|
||||
= note: expected values for `feature` are: `full`, `serde`
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
warning: unexpected `cfg` condition value
|
||||
@ -15,7 +15,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | #[cfg(feature = "rand")]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: full, serde
|
||||
= note: expected values for `feature` are: `full`, `serde`
|
||||
|
||||
warning: unexpected condition value `rand` for condition name `feature`
|
||||
|
|
||||
|
@ -2,7 +2,7 @@ warning: unexpected `cfg` condition name
|
||||
--> $DIR/mix.rs:11:7
|
||||
|
|
||||
LL | #[cfg(widnows)]
|
||||
| ^^^^^^^ help: did you mean: `windows`
|
||||
| ^^^^^^^ help: there is an config with a similar name: `windows`
|
||||
|
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
@ -12,7 +12,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | #[cfg(feature = "bar")]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: unexpected `cfg` condition value
|
||||
--> $DIR/mix.rs:22:7
|
||||
@ -20,7 +20,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | #[cfg(feature = "zebra")]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: unexpected `cfg` condition name
|
||||
--> $DIR/mix.rs:26:12
|
||||
@ -40,7 +40,7 @@ warning: unexpected `cfg` condition name
|
||||
--> $DIR/mix.rs:35:10
|
||||
|
|
||||
LL | cfg!(widnows);
|
||||
| ^^^^^^^ help: did you mean: `windows`
|
||||
| ^^^^^^^ help: there is an config with a similar name: `windows`
|
||||
|
||||
warning: unexpected `cfg` condition value
|
||||
--> $DIR/mix.rs:38:10
|
||||
@ -48,7 +48,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | cfg!(feature = "bar");
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: unexpected `cfg` condition value
|
||||
--> $DIR/mix.rs:40:10
|
||||
@ -56,7 +56,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | cfg!(feature = "zebra");
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: unexpected `cfg` condition name
|
||||
--> $DIR/mix.rs:42:10
|
||||
@ -82,7 +82,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | cfg!(any(feature = "bad", windows));
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: unexpected `cfg` condition name
|
||||
--> $DIR/mix.rs:50:23
|
||||
@ -126,7 +126,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | cfg!(any(unix, feature = "zebra"));
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: unexpected `cfg` condition name
|
||||
--> $DIR/mix.rs:62:14
|
||||
@ -140,7 +140,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | cfg!(any(xxx, feature = "zebra"));
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: unexpected `cfg` condition name
|
||||
--> $DIR/mix.rs:65:14
|
||||
@ -160,7 +160,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: unexpected `cfg` condition value
|
||||
--> $DIR/mix.rs:68:33
|
||||
@ -168,7 +168,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: unexpected `cfg` condition value
|
||||
--> $DIR/mix.rs:68:52
|
||||
@ -176,7 +176,7 @@ warning: unexpected `cfg` condition value
|
||||
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: expected values for `feature` are: foo
|
||||
= note: expected values for `feature` are: `foo`
|
||||
|
||||
warning: 27 warnings emitted
|
||||
|
||||
|
@ -2,7 +2,9 @@ warning: unexpected `cfg` condition value
|
||||
--> $DIR/no-values.rs:6:7
|
||||
|
|
||||
LL | #[cfg(feature = "foo")]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^--------
|
||||
| |
|
||||
| help: remove the value
|
||||
|
|
||||
= note: no expected value for `feature`
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
@ -4,9 +4,9 @@ warning: unexpected `cfg` condition value
|
||||
LL | #[cfg(target_os = "linuz")]
|
||||
| ^^^^^^^^^^^^-------
|
||||
| |
|
||||
| help: did you mean: `"linux"`
|
||||
| help: there is an expected value with a similar name: `"linux"`
|
||||
|
|
||||
= note: expected values for `target_os` are: aix, android, cuda, dragonfly, emscripten, ericos, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, nto, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vita, vxworks, wasi, watchos, windows, xous
|
||||
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `ericos`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
@ -4,7 +4,7 @@ warning: unexpected `cfg` condition name
|
||||
LL | #[cfg(target_oz = "linux")]
|
||||
| ---------^^^^^^^^^^
|
||||
| |
|
||||
| help: did you mean: `target_os`
|
||||
| help: there is an config with a similar name: `target_os`
|
||||
|
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
@ -14,13 +14,13 @@ warning: unexpected `cfg` condition name
|
||||
LL | #[cfg(features = "foo")]
|
||||
| --------^^^^^^^^
|
||||
| |
|
||||
| help: did you mean: `feature`
|
||||
| help: there is an config with a similar name: `feature`
|
||||
|
||||
warning: unexpected `cfg` condition name
|
||||
--> $DIR/well-known-names.rs:20:7
|
||||
|
|
||||
LL | #[cfg(uniw)]
|
||||
| ^^^^ help: did you mean: `unix`
|
||||
| ^^^^ help: there is an config with a similar name: `unix`
|
||||
|
||||
warning: 3 warnings emitted
|
||||
|
||||
|
@ -4,9 +4,9 @@ warning: unexpected `cfg` condition value
|
||||
LL | #[cfg(target_os = "linuz")]
|
||||
| ^^^^^^^^^^^^-------
|
||||
| |
|
||||
| help: did you mean: `"linux"`
|
||||
| help: there is an expected value with a similar name: `"linux"`
|
||||
|
|
||||
= note: expected values for `target_os` are: aix, android, cuda, dragonfly, emscripten, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, nto, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vita, vxworks, wasi, watchos, windows, xous
|
||||
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
|
||||
= note: `#[warn(unexpected_cfgs)]` on by default
|
||||
|
||||
warning: unexpected `cfg` condition value
|
||||
@ -15,9 +15,9 @@ warning: unexpected `cfg` condition value
|
||||
LL | #[cfg(target_has_atomic = "0")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^---
|
||||
| |
|
||||
| help: did you mean: `"8"`
|
||||
| help: there is an expected value with a similar name: `"8"`
|
||||
|
|
||||
= note: expected values for `target_has_atomic` are: 128, 16, 32, 64, 8, ptr
|
||||
= note: expected values for `target_has_atomic` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
|
||||
|
||||
warning: unexpected `cfg` condition value
|
||||
--> $DIR/well-known-values.rs:21:7
|
||||
|
Loading…
Reference in New Issue
Block a user