Skip to content

Commit

Permalink
Auto merge of rust-lang#10696 - Alexendoo:allow-enum-variant-names, r…
Browse files Browse the repository at this point in the history
…=flip1995

Fix `#[allow(clippy::enum_variant_names)]` directly on variants

changelog: [`enum_variant_names`]: Fix `#[allow]` attributes applied directly to the enum variant

Fixes rust-lang#10695
  • Loading branch information
bors committed Apr 23, 2023
2 parents 9283497 + 397f36a commit 9824234
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clippy_lints/src/enum_variants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! lint on enum variants that are prefixed or suffixed by the same characters

use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_hir};
use clippy_utils::source::is_present_in_source;
use clippy_utils::str_utils::{camel_case_split, count_match_end, count_match_start};
use rustc_hir::{EnumDef, Item, ItemKind, Variant};
Expand Down Expand Up @@ -135,9 +135,10 @@ fn check_enum_start(cx: &LateContext<'_>, item_name: &str, variant: &Variant<'_>
&& 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(
span_lint_hir(
cx,
ENUM_VARIANT_NAMES,
variant.hir_id,
variant.span,
"variant name starts with the enum's name",
);
Expand All @@ -149,9 +150,10 @@ fn check_enum_end(cx: &LateContext<'_>, item_name: &str, variant: &Variant<'_>)
let item_name_chars = item_name.chars().count();

if count_match_end(item_name, name).char_count == item_name_chars {
span_lint(
span_lint_hir(
cx,
ENUM_VARIANT_NAMES,
variant.hir_id,
variant.span,
"variant name ends with the enum's name",
);
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/enum_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,14 @@ mod issue9018 {
}
}

mod allow_attributes_on_variants {
enum Enum {
#[allow(clippy::enum_variant_names)]
EnumStartsWith,
#[allow(clippy::enum_variant_names)]
EndsWithEnum,
Foo,
}
}

fn main() {}

0 comments on commit 9824234

Please sign in to comment.