Skip to content

Commit 41140e3

Browse files
committed
Auto merge of rust-lang#11840 - GuillaumeGomez:improve-maybe_misused_cfg, r=blyxyas
Improve maybe misused cfg Follow-up of the improvements that were suggested to me in rust-lang/rust-clippy#11821: * I unified the output to use the same terms. * I updated the code to prevent creating a new symbol. r? `@blyxyas` changelog: [`maybe_misued_cfg`]: Output and code improvements
2 parents 9c3a365 + dfbca7f commit 41140e3

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

clippy_lints/src/attrs.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -929,15 +929,16 @@ fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
929929
fn check_nested_misused_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
930930
for item in items {
931931
if let NestedMetaItem::MetaItem(meta) = item {
932-
if meta.has_name(sym!(features))
932+
if let Some(ident) = meta.ident()
933+
&& ident.name.as_str() == "features"
933934
&& let Some(val) = meta.value_str()
934935
{
935936
span_lint_and_sugg(
936937
cx,
937938
MAYBE_MISUSED_CFG,
938939
meta.span,
939-
"feature may misspelled as features",
940-
"use",
940+
"'feature' may be misspelled as 'features'",
941+
"did you mean",
941942
format!("feature = \"{val}\""),
942943
Applicability::MaybeIncorrect,
943944
);
@@ -953,7 +954,7 @@ fn check_nested_misused_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
953954
MAYBE_MISUSED_CFG,
954955
meta.span,
955956
&format!("'test' may be misspelled as '{}'", ident.name.as_str()),
956-
"do you mean",
957+
"did you mean",
957958
"test".to_string(),
958959
Applicability::MaybeIncorrect,
959960
);

tests/ui/cfg_features.fixed

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
fn main() {
44
#[cfg(feature = "not-really-a-feature")]
5-
//~^ ERROR: feature may misspelled as features
5+
//~^ ERROR: 'feature' may be misspelled as 'features'
66
//~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
77
let _ = 1 + 2;
88

99
#[cfg(all(feature = "right", feature = "wrong"))]
10-
//~^ ERROR: feature may misspelled as features
10+
//~^ ERROR: 'feature' may be misspelled as 'features'
1111
let _ = 1 + 2;
1212

1313
#[cfg(all(feature = "wrong1", any(feature = "right", feature = "wrong2", feature, features)))]
14-
//~^ ERROR: feature may misspelled as features
15-
//~| ERROR: feature may misspelled as features
14+
//~^ ERROR: 'feature' may be misspelled as 'features'
15+
//~| ERROR: 'feature' may be misspelled as 'features'
1616
let _ = 1 + 2;
1717

1818
#[cfg(test)]

tests/ui/cfg_features.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
fn main() {
44
#[cfg(features = "not-really-a-feature")]
5-
//~^ ERROR: feature may misspelled as features
5+
//~^ ERROR: 'feature' may be misspelled as 'features'
66
//~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
77
let _ = 1 + 2;
88

99
#[cfg(all(feature = "right", features = "wrong"))]
10-
//~^ ERROR: feature may misspelled as features
10+
//~^ ERROR: 'feature' may be misspelled as 'features'
1111
let _ = 1 + 2;
1212

1313
#[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
14-
//~^ ERROR: feature may misspelled as features
15-
//~| ERROR: feature may misspelled as features
14+
//~^ ERROR: 'feature' may be misspelled as 'features'
15+
//~| ERROR: 'feature' may be misspelled as 'features'
1616
let _ = 1 + 2;
1717

1818
#[cfg(tests)]

tests/ui/cfg_features.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
error: feature may misspelled as features
1+
error: 'feature' may be misspelled as 'features'
22
--> $DIR/cfg_features.rs:4:11
33
|
44
LL | #[cfg(features = "not-really-a-feature")]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `feature = "not-really-a-feature"`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `feature = "not-really-a-feature"`
66
|
77
= note: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::maybe_misused_cfg)]`
99

10-
error: feature may misspelled as features
10+
error: 'feature' may be misspelled as 'features'
1111
--> $DIR/cfg_features.rs:9:34
1212
|
1313
LL | #[cfg(all(feature = "right", features = "wrong"))]
14-
| ^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong"`
14+
| ^^^^^^^^^^^^^^^^^^ help: did you mean: `feature = "wrong"`
1515

16-
error: feature may misspelled as features
16+
error: 'feature' may be misspelled as 'features'
1717
--> $DIR/cfg_features.rs:13:15
1818
|
1919
LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
20-
| ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong1"`
20+
| ^^^^^^^^^^^^^^^^^^^ help: did you mean: `feature = "wrong1"`
2121

22-
error: feature may misspelled as features
22+
error: 'feature' may be misspelled as 'features'
2323
--> $DIR/cfg_features.rs:13:59
2424
|
2525
LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
26-
| ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong2"`
26+
| ^^^^^^^^^^^^^^^^^^^ help: did you mean: `feature = "wrong2"`
2727

2828
error: 'test' may be misspelled as 'tests'
2929
--> $DIR/cfg_features.rs:18:11
3030
|
3131
LL | #[cfg(tests)]
32-
| ^^^^^ help: do you mean: `test`
32+
| ^^^^^ help: did you mean: `test`
3333

3434
error: 'test' may be misspelled as 'Test'
3535
--> $DIR/cfg_features.rs:21:11
3636
|
3737
LL | #[cfg(Test)]
38-
| ^^^^ help: do you mean: `test`
38+
| ^^^^ help: did you mean: `test`
3939

4040
error: 'test' may be misspelled as 'tests'
4141
--> $DIR/cfg_features.rs:25:15
4242
|
4343
LL | #[cfg(all(tests, Test))]
44-
| ^^^^^ help: do you mean: `test`
44+
| ^^^^^ help: did you mean: `test`
4545

4646
error: 'test' may be misspelled as 'Test'
4747
--> $DIR/cfg_features.rs:25:22
4848
|
4949
LL | #[cfg(all(tests, Test))]
50-
| ^^^^ help: do you mean: `test`
50+
| ^^^^ help: did you mean: `test`
5151

5252
error: aborting due to 8 previous errors
5353

0 commit comments

Comments
 (0)