diff options
| author | bors <bors@rust-lang.org> | 2019-08-07 10:22:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-08-07 10:22:06 +0000 |
| commit | 286d528a453e0a5abb28d1ff26e91e92b139afef (patch) | |
| tree | e7df5def3d79399731b1f0795ea6a8792dbe2a2c | |
| parent | 8fed08dfb1c05c89c54879c052620316548afa6c (diff) | |
| parent | 0a988c663080f5c59ccd5a1d1f4e7903495871fd (diff) | |
| download | rust-286d528a453e0a5abb28d1ff26e91e92b139afef.tar.gz rust-286d528a453e0a5abb28d1ff26e91e92b139afef.zip | |
Auto merge of #4345 - phansch:enum_variants_fix, r=flip1995
Don't emit enum_variant_names if remainder starts with a numeric changelog: Fix false positive in `pub_enum_variant_names` and `enum_variant_names` As [per the reference](https://doc.rust-lang.org/reference/identifiers.html), identifiers must start with a letter. So we don't suggest a better variant naming in case the remainder would start with a numeric. Fixes #739
| -rw-r--r-- | clippy_lints/src/enum_variants.rs | 4 | ||||
| -rw-r--r-- | tests/ui/enum_variants.rs | 15 |
2 files changed, 18 insertions, 1 deletions
diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 782d80a7b64..1cc3bda3ba3 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -160,6 +160,7 @@ fn check_variant( let name = var2str(var); if partial_match(item_name, &name) == item_name_chars && name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase()) + && name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric()) { span_lint(cx, lint, var.span, "Variant name starts with the enum's name"); } @@ -178,6 +179,9 @@ fn check_variant( let pre_camel = camel_case::until(pre); pre = &pre[..pre_camel]; while let Some((next, last)) = name[pre.len()..].chars().zip(pre.chars().rev()).next() { + if next.is_numeric() { + return; + } if next.is_lowercase() { let last = pre.len() - last.len_utf8(); let last_camel = camel_case::until(&pre[..last]); diff --git a/tests/ui/enum_variants.rs b/tests/ui/enum_variants.rs index f3bbd3d9626..01774a2a984 100644 --- a/tests/ui/enum_variants.rs +++ b/tests/ui/enum_variants.rs @@ -1,5 +1,5 @@ #![feature(non_ascii_idents)] -#![warn(clippy::all, clippy::pub_enum_variant_names)] +#![warn(clippy::enum_variant_names, clippy::pub_enum_variant_names)] #![allow(non_camel_case_types)] enum FakeCallType { @@ -120,4 +120,17 @@ enum N { Float, } +// should not lint +enum Peek { + Peek1, + Peek2, + Peek3, +} + +// should not lint +pub enum NetworkLayer { + Layer2, + Layer3, +} + fn main() {} |
