Skip to content

Commit 566bfff

Browse files
committed
useless_attribute: Update docs for allowed attributes
1 parent db0cbba commit 566bfff

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

clippy_lints/src/attrs/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,21 @@ declare_clippy_lint! {
6161
///
6262
/// This lint permits lint attributes for lints emitted on the items themself.
6363
/// For `use` items these lints are:
64+
/// * ambiguous_glob_reexports
65+
/// * dead_code
6466
/// * deprecated
67+
/// * hidden_glob_reexports
6568
/// * unreachable_pub
66-
/// * unused_imports
69+
/// * unused
70+
/// * unused_braces
71+
/// * unused_import_braces
72+
/// * clippy::disallowed_types
6773
/// * clippy::enum_glob_use
6874
/// * clippy::macro_use_imports
75+
/// * clippy::module_name_repetitions
76+
/// * clippy::redundant_pub_crate
77+
/// * clippy::single_component_path_imports
78+
/// * clippy::unsafe_removed_from_name
6979
/// * clippy::wildcard_imports
7080
///
7181
/// For `extern crate` items these lints are:

clippy_lints/src/attrs/useless_attribute.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::utils::{extract_clippy_lint, is_lint_level, is_word};
22
use super::{Attribute, USELESS_ATTRIBUTE};
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::source::{first_line_of_span, snippet_opt};
5+
use rustc_ast::NestedMetaItem;
56
use rustc_errors::Applicability;
67
use rustc_hir::{Item, ItemKind};
78
use rustc_lint::{LateContext, LintContext};
@@ -20,31 +21,40 @@ pub(super) fn check(cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute])
2021
for lint in lint_list {
2122
match item.kind {
2223
ItemKind::Use(..) => {
23-
if is_word(lint, sym::unused_imports)
24-
|| is_word(lint, sym::deprecated)
25-
|| is_word(lint, sym!(unreachable_pub))
26-
|| is_word(lint, sym!(unused))
27-
|| is_word(lint, sym!(unused_import_braces))
28-
|| is_word(lint, sym!(unused_braces))
29-
|| is_word(lint, sym::dead_code)
30-
|| is_word(lint, sym!(hidden_glob_reexports))
31-
|| is_word(lint, sym!(ambiguous_glob_reexports))
32-
|| extract_clippy_lint(lint).map_or(false, |s| {
33-
matches!(
34-
s.as_str(),
35-
"wildcard_imports"
36-
| "enum_glob_use"
37-
| "redundant_pub_crate"
38-
| "macro_use_imports"
39-
| "unsafe_removed_from_name"
40-
| "module_name_repetitions"
41-
| "single_component_path_imports"
42-
| "disallowed_types"
43-
)
44-
})
24+
if let NestedMetaItem::MetaItem(meta_item) = lint
25+
&& meta_item.is_word()
26+
&& let Some(ident) = meta_item.ident()
27+
&& matches!(
28+
ident.name.as_str(),
29+
"ambiguous_glob_reexports"
30+
| "dead_code"
31+
| "deprecated"
32+
| "hidden_glob_reexports"
33+
| "unreachable_pub"
34+
| "unused"
35+
| "unused_braces"
36+
| "unused_import_braces"
37+
| "unused_imports"
38+
)
4539
{
4640
return;
4741
}
42+
43+
if extract_clippy_lint(lint).is_some_and(|symbol| {
44+
matches!(
45+
symbol.as_str(),
46+
"wildcard_imports"
47+
| "enum_glob_use"
48+
| "redundant_pub_crate"
49+
| "macro_use_imports"
50+
| "unsafe_removed_from_name"
51+
| "module_name_repetitions"
52+
| "single_component_path_imports"
53+
| "disallowed_types"
54+
)
55+
}) {
56+
return;
57+
}
4858
},
4959
ItemKind::ExternCrate(..) => {
5060
if is_word(lint, sym::unused_imports) && skip_unused_imports {

0 commit comments

Comments
 (0)