1
Fork 0

check-cfg: adjust expected names and values when useful

This commit is contained in:
Urgau 2023-10-12 16:46:27 +02:00
parent 19149d1ea9
commit 72815dc08f
7 changed files with 42 additions and 2 deletions

View file

@ -727,11 +727,14 @@ pub trait LintContext: Sized {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
possibilities.sort(); possibilities.sort();
let mut should_print_possibilities = true;
if let Some((value, value_span)) = value { if let Some((value, value_span)) = value {
if best_match_values.contains(&Some(value)) { if best_match_values.contains(&Some(value)) {
db.span_suggestion(name_span, "there is a config with a similar name and value", best_match, Applicability::MaybeIncorrect); db.span_suggestion(name_span, "there is a config with a similar name and value", best_match, Applicability::MaybeIncorrect);
should_print_possibilities = false;
} else if best_match_values.contains(&None) { } else if best_match_values.contains(&None) {
db.span_suggestion(name_span.to(value_span), "there is a config with a similar name and no value", best_match, Applicability::MaybeIncorrect); db.span_suggestion(name_span.to(value_span), "there is a config with a similar name and no value", best_match, Applicability::MaybeIncorrect);
should_print_possibilities = false;
} else if let Some(first_value) = possibilities.first() { } else if let Some(first_value) = possibilities.first() {
db.span_suggestion(name_span.to(value_span), "there is a config with a similar name and different values", format!("{best_match} = \"{first_value}\""), Applicability::MaybeIncorrect); db.span_suggestion(name_span.to(value_span), "there is a config with a similar name and different values", format!("{best_match} = \"{first_value}\""), Applicability::MaybeIncorrect);
} else { } else {
@ -741,13 +744,21 @@ pub trait LintContext: Sized {
db.span_suggestion(name_span, "there is a config with a similar name", best_match, Applicability::MaybeIncorrect); db.span_suggestion(name_span, "there is a config with a similar name", best_match, Applicability::MaybeIncorrect);
} }
if !possibilities.is_empty() { if !possibilities.is_empty() && should_print_possibilities {
let possibilities = possibilities.join("`, `"); let possibilities = possibilities.join("`, `");
db.help(format!("expected values for `{best_match}` are: `{possibilities}`")); db.help(format!("expected values for `{best_match}` are: `{possibilities}`"));
} }
} else { } else {
db.span_suggestion(name_span, "there is a config with a similar name", best_match, Applicability::MaybeIncorrect); db.span_suggestion(name_span, "there is a config with a similar name", best_match, Applicability::MaybeIncorrect);
} }
} else if !possibilities.is_empty() {
let mut possibilities = possibilities.iter()
.map(Symbol::as_str)
.collect::<Vec<_>>();
possibilities.sort();
let possibilities = possibilities.join("`, `");
db.help(format!("expected names are: `{possibilities}`"));
} }
}, },
BuiltinLintDiagnostics::UnexpectedCfgValue((name, name_span), value) => { BuiltinLintDiagnostics::UnexpectedCfgValue((name, name_span), value) => {

View file

@ -4,6 +4,7 @@ warning: unexpected `cfg` condition name
LL | #[cfg(FALSE)] LL | #[cfg(FALSE)]
| ^^^^^ | ^^^^^
| |
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
= note: `#[warn(unexpected_cfgs)]` on by default = note: `#[warn(unexpected_cfgs)]` on by default
warning: 1 warning emitted warning: 1 warning emitted

View file

@ -4,6 +4,7 @@ warning: unexpected `cfg` condition name
LL | #[cfg(target(os = "linux", architecture = "arm"))] LL | #[cfg(target(os = "linux", architecture = "arm"))]
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
| |
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
= note: `#[warn(unexpected_cfgs)]` on by default = note: `#[warn(unexpected_cfgs)]` on by default
warning: 1 warning emitted warning: 1 warning emitted

View file

@ -13,7 +13,6 @@ warning: unexpected `cfg` condition name
LL | #[cfg(featur = "foo")] LL | #[cfg(featur = "foo")]
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
| |
= help: expected values for `feature` are: `foo`
help: there is a config with a similar name and value help: there is a config with a similar name and value
| |
LL | #[cfg(feature = "foo")] LL | #[cfg(feature = "foo")]

View file

@ -4,6 +4,7 @@ warning: unexpected `cfg` condition name
LL | #[cfg(unknown_key = "value")] LL | #[cfg(unknown_key = "value")]
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^
| |
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
= note: `#[warn(unexpected_cfgs)]` on by default = note: `#[warn(unexpected_cfgs)]` on by default
warning: 1 warning emitted warning: 1 warning emitted

View file

@ -35,6 +35,8 @@ warning: unexpected `cfg` condition name
| |
LL | #[cfg_attr(uu, test)] LL | #[cfg_attr(uu, test)]
| ^^ | ^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected condition value `bar` for condition name `feature` warning: unexpected condition value `bar` for condition name `feature`
| |
@ -71,18 +73,24 @@ warning: unexpected `cfg` condition name
| |
LL | cfg!(xxx = "foo"); LL | cfg!(xxx = "foo");
| ^^^^^^^^^^^ | ^^^^^^^^^^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition name warning: unexpected `cfg` condition name
--> $DIR/mix.rs:48:10 --> $DIR/mix.rs:48:10
| |
LL | cfg!(xxx); LL | cfg!(xxx);
| ^^^ | ^^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition name warning: unexpected `cfg` condition name
--> $DIR/mix.rs:50:14 --> $DIR/mix.rs:50:14
| |
LL | cfg!(any(xxx, windows)); LL | cfg!(any(xxx, windows));
| ^^^ | ^^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition value warning: unexpected `cfg` condition value
--> $DIR/mix.rs:52:14 --> $DIR/mix.rs:52:14
@ -97,36 +105,48 @@ warning: unexpected `cfg` condition name
| |
LL | cfg!(any(windows, xxx)); LL | cfg!(any(windows, xxx));
| ^^^ | ^^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition name warning: unexpected `cfg` condition name
--> $DIR/mix.rs:56:20 --> $DIR/mix.rs:56:20
| |
LL | cfg!(all(unix, xxx)); LL | cfg!(all(unix, xxx));
| ^^^ | ^^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition name warning: unexpected `cfg` condition name
--> $DIR/mix.rs:58:14 --> $DIR/mix.rs:58:14
| |
LL | cfg!(all(aa, bb)); LL | cfg!(all(aa, bb));
| ^^ | ^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition name warning: unexpected `cfg` condition name
--> $DIR/mix.rs:58:18 --> $DIR/mix.rs:58:18
| |
LL | cfg!(all(aa, bb)); LL | cfg!(all(aa, bb));
| ^^ | ^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition name warning: unexpected `cfg` condition name
--> $DIR/mix.rs:61:14 --> $DIR/mix.rs:61:14
| |
LL | cfg!(any(aa, bb)); LL | cfg!(any(aa, bb));
| ^^ | ^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition name warning: unexpected `cfg` condition name
--> $DIR/mix.rs:61:18 --> $DIR/mix.rs:61:18
| |
LL | cfg!(any(aa, bb)); LL | cfg!(any(aa, bb));
| ^^ | ^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition value warning: unexpected `cfg` condition value
--> $DIR/mix.rs:64:20 --> $DIR/mix.rs:64:20
@ -141,6 +161,8 @@ warning: unexpected `cfg` condition name
| |
LL | cfg!(any(xxx, feature = "zebra")); LL | cfg!(any(xxx, feature = "zebra"));
| ^^^ | ^^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition value warning: unexpected `cfg` condition value
--> $DIR/mix.rs:66:19 --> $DIR/mix.rs:66:19
@ -155,12 +177,16 @@ warning: unexpected `cfg` condition name
| |
LL | cfg!(any(xxx, unix, xxx)); LL | cfg!(any(xxx, unix, xxx));
| ^^^ | ^^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition name warning: unexpected `cfg` condition name
--> $DIR/mix.rs:69:25 --> $DIR/mix.rs:69:25
| |
LL | cfg!(any(xxx, unix, xxx)); LL | cfg!(any(xxx, unix, xxx));
| ^^^ | ^^^
|
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
warning: unexpected `cfg` condition value warning: unexpected `cfg` condition value
--> $DIR/mix.rs:72:14 --> $DIR/mix.rs:72:14

View file

@ -4,6 +4,7 @@ warning: unexpected `cfg` condition name
LL | #[cfg(crossbeam_loom)] LL | #[cfg(crossbeam_loom)]
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
| |
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
= note: `#[warn(unexpected_cfgs)]` on by default = note: `#[warn(unexpected_cfgs)]` on by default
warning: 1 warning emitted warning: 1 warning emitted