Skip to content

Commit

Permalink
Auto merge of rust-lang#11498 - jonboh:issue11494_enumvariants_order_…
Browse files Browse the repository at this point in the history
…affects_lint, r=Centri3

fix enum_variant_names depending lint depending on order

changelog: [`enum_variant_names`]: fix single word variants preventing lint of later variant pre/postfixed with the enum name

fixes rust-lang#11494

Single word variants prevented checking the `check_enum_start` and `check_enum_end` for being run on later variants
  • Loading branch information
bors committed Oct 31, 2023
2 parents cdc4d56 + c51e2a0 commit 3da80dc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 5 additions & 2 deletions clippy_lints/src/item_name_repetitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
return;
}

for var in def.variants {
check_enum_start(cx, item_name, var);
check_enum_end(cx, item_name, var);
}

let first = match def.variants.first() {
Some(variant) => variant.ident.name.as_str(),
None => return,
Expand All @@ -328,8 +333,6 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
let mut post = pre.clone();
post.reverse();
for var in def.variants {
check_enum_start(cx, item_name, var);
check_enum_end(cx, item_name, var);
let name = var.ident.name.as_str();

let variant_split = camel_case_split(name);
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/enum_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,21 @@ mod allow_attributes_on_variants {
}
}

mod issue11494 {
// variant order should not affect lint
enum Data {
Valid,
Invalid,
DataDependent,
//~^ ERROR: variant name starts with the enum's name
}

enum Datas {
DatasDependent,
//~^ ERROR: variant name starts with the enum's name
Valid,
Invalid,
}
}

fn main() {}
14 changes: 13 additions & 1 deletion tests/ui/enum_variants.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,17 @@ LL | | }
|
= help: remove the postfixes and use full paths to the variants instead of glob imports

error: aborting due to 14 previous errors
error: variant name starts with the enum's name
--> $DIR/enum_variants.rs:212:9
|
LL | DataDependent,
| ^^^^^^^^^^^^^

error: variant name starts with the enum's name
--> $DIR/enum_variants.rs:217:9
|
LL | DatasDependent,
| ^^^^^^^^^^^^^^

error: aborting due to 16 previous errors

0 comments on commit 3da80dc

Please sign in to comment.