Skip to content

Commit b4021ee

Browse files
committed
Auto merge of #12375 - GuillaumeGomez:improve-code, r=flip1995
Improve `is_lint_level` code Since rust-lang/rust#121230 was merged, we can now rely on `Level` directly instead of keeping the list of symbols to check in clippy. changelog: Improve `is_lint_level` code
2 parents 4c1d05c + 41a3516 commit b4021ee

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: clippy_lints/src/attrs.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt
1010
use rustc_ast::token::{Token, TokenKind};
1111
use rustc_ast::tokenstream::TokenTree;
1212
use rustc_ast::{
13-
AttrArgs, AttrArgsEq, AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem,
13+
AttrArgs, AttrArgsEq, AttrId, AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem,
1414
};
1515
use rustc_errors::Applicability;
1616
use rustc_hir::{
@@ -518,7 +518,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
518518
fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) {
519519
if let Some(items) = &attr.meta_item_list() {
520520
if let Some(ident) = attr.ident() {
521-
if is_lint_level(ident.name) {
521+
if is_lint_level(ident.name, attr.id) {
522522
check_clippy_lint_names(cx, ident.name, items);
523523
}
524524
if matches!(ident.name, sym::allow | sym::expect) {
@@ -556,7 +556,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
556556
return;
557557
}
558558
if let Some(lint_list) = &attr.meta_item_list() {
559-
if attr.ident().map_or(false, |ident| is_lint_level(ident.name)) {
559+
if attr.ident().map_or(false, |ident| is_lint_level(ident.name, attr.id)) {
560560
for lint in lint_list {
561561
match item.kind {
562562
ItemKind::Use(..) => {
@@ -1205,6 +1205,6 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
12051205
}
12061206
}
12071207

1208-
fn is_lint_level(symbol: Symbol) -> bool {
1209-
matches!(symbol, sym::allow | sym::expect | sym::warn | sym::deny | sym::forbid)
1208+
fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool {
1209+
Level::from_symbol(symbol, Some(attr_id)).is_some()
12101210
}

0 commit comments

Comments
 (0)