diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-02-28 15:14:22 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-02-28 15:14:22 +0100 |
| commit | 41a351665fdcd6171f9ad4759546e366ec866c1f (patch) | |
| tree | 24548e7515a714d487070c05c36cd4693f191eba | |
| parent | 4c1d05cfa193012eb197119b4614dd979d7f6004 (diff) | |
| download | rust-41a351665fdcd6171f9ad4759546e366ec866c1f.tar.gz rust-41a351665fdcd6171f9ad4759546e366ec866c1f.zip | |
Improve `is_lint_level` code
| -rw-r--r-- | clippy_lints/src/attrs.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index f2937d51340..f131bb40043 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -10,7 +10,7 @@ use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt use rustc_ast::token::{Token, TokenKind}; use rustc_ast::tokenstream::TokenTree; use rustc_ast::{ - AttrArgs, AttrArgsEq, AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem, + AttrArgs, AttrArgsEq, AttrId, AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem, }; use rustc_errors::Applicability; use rustc_hir::{ @@ -518,7 +518,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) { if let Some(items) = &attr.meta_item_list() { if let Some(ident) = attr.ident() { - if is_lint_level(ident.name) { + if is_lint_level(ident.name, attr.id) { check_clippy_lint_names(cx, ident.name, items); } if matches!(ident.name, sym::allow | sym::expect) { @@ -556,7 +556,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { return; } if let Some(lint_list) = &attr.meta_item_list() { - if attr.ident().map_or(false, |ident| is_lint_level(ident.name)) { + if attr.ident().map_or(false, |ident| is_lint_level(ident.name, attr.id)) { for lint in lint_list { match item.kind { ItemKind::Use(..) => { @@ -1205,6 +1205,6 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) { } } -fn is_lint_level(symbol: Symbol) -> bool { - matches!(symbol, sym::allow | sym::expect | sym::warn | sym::deny | sym::forbid) +fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool { + Level::from_symbol(symbol, Some(attr_id)).is_some() } |
