Skip to content

Commit dc9560c

Browse files
committed
Remove hir::Item::attrs.
1 parent 49835d8 commit dc9560c

11 files changed

+25
-16
lines changed

clippy_lints/src/attrs.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,15 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
276276
}
277277

278278
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
279+
let attrs = cx.tcx.hir().attrs(item.hir_id());
279280
if is_relevant_item(cx, item) {
280-
check_attrs(cx, item.span, item.ident.name, &item.attrs)
281+
check_attrs(cx, item.span, item.ident.name, attrs)
281282
}
282283
match item.kind {
283284
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
284-
let skip_unused_imports = item.attrs.iter().any(|attr| attr.has_name(sym::macro_use));
285+
let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use));
285286

286-
for attr in item.attrs {
287+
for attr in attrs {
287288
if in_external_macro(cx.sess(), attr.span) {
288289
return;
289290
}

clippy_lints/src/derive.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
170170
}) = item.kind
171171
{
172172
let ty = cx.tcx.type_of(item.def_id);
173-
let is_automatically_derived = is_automatically_derived(&*item.attrs);
173+
let attrs = cx.tcx.hir().attrs(item.hir_id());
174+
let is_automatically_derived = is_automatically_derived(attrs);
174175

175176
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
176177
check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived);

clippy_lints/src/doc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
214214
}
215215

216216
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
217-
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
217+
let attrs = cx.tcx.hir().attrs(item.hir_id());
218+
let headers = check_attrs(cx, &self.valid_idents, attrs);
218219
match item.kind {
219220
hir::ItemKind::Fn(ref sig, _, body_id) => {
220221
if !(is_entrypoint_fn(cx, item.def_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) {

clippy_lints/src/exhaustive_items.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ impl LateLintPass<'_> for ExhaustiveItems {
7373
if_chain! {
7474
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
7575
if cx.access_levels.is_exported(item.hir_id());
76-
if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
76+
let attrs = cx.tcx.hir().attrs(item.hir_id());
77+
if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
7778
then {
7879
let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind {
7980
if v.fields().iter().any(|f| !f.vis.node.is_pub()) {

clippy_lints/src/functions.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
280280
}
281281

282282
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
283-
let attr = must_use_attr(&item.attrs);
283+
let attrs = cx.tcx.hir().attrs(item.hir_id());
284+
let attr = must_use_attr(attrs);
284285
if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind {
285286
let is_public = cx.access_levels.is_exported(item.hir_id());
286287
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
@@ -291,7 +292,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
291292
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
292293
return;
293294
}
294-
if is_public && !is_proc_macro(cx.sess(), &item.attrs) && attr_by_name(&item.attrs, "no_mangle").is_none() {
295+
if is_public && !is_proc_macro(cx.sess(), attrs) && attr_by_name(attrs, "no_mangle").is_none() {
295296
check_must_use_candidate(
296297
cx,
297298
&sig.decl,

clippy_lints/src/macro_use.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
107107
if_chain! {
108108
if cx.sess().opts.edition >= Edition::Edition2018;
109109
if let hir::ItemKind::Use(path, _kind) = &item.kind;
110-
if let Some(mac_attr) = item
111-
.attrs
110+
let attrs = cx.tcx.hir().attrs(item.hir_id());
111+
if let Some(mac_attr) = attrs
112112
.iter()
113113
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
114114
if let Res::Def(DefKind::Mod, id) = path.res;

clippy_lints/src/missing_doc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
161161

162162
let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id());
163163

164-
self.check_missing_docs_attrs(cx, &it.attrs, it.span, article, desc);
164+
let attrs = cx.tcx.hir().attrs(it.hir_id());
165+
self.check_missing_docs_attrs(cx, attrs, it.span, article, desc);
165166
}
166167

167168
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) {

clippy_lints/src/missing_inline.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
9393
match it.kind {
9494
hir::ItemKind::Fn(..) => {
9595
let desc = "a function";
96-
check_missing_inline_attrs(cx, &it.attrs, it.span, desc);
96+
let attrs = cx.tcx.hir().attrs(it.hir_id());
97+
check_missing_inline_attrs(cx, attrs, it.span, desc);
9798
},
9899
hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics, ref _bounds, trait_items) => {
99100
// note: we need to check if the trait is exported so we can't use

clippy_lints/src/needless_borrow.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
115115
}
116116
}
117117

118-
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
119-
if is_automatically_derived(item.attrs) {
118+
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
119+
let attrs = cx.tcx.hir().attrs(item.hir_id());
120+
if is_automatically_derived(attrs) {
120121
debug_assert!(self.derived_item.is_none());
121122
self.derived_item = Some(item.def_id);
122123
}

clippy_lints/src/partialeq_ne_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
3535
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
3636
if_chain! {
3737
if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind;
38-
if !is_automatically_derived(&*item.attrs);
38+
let attrs = cx.tcx.hir().attrs(item.hir_id());
39+
if !is_automatically_derived(attrs);
3940
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
4041
if trait_ref.path.res.def_id() == eq_trait;
4142
then {

clippy_lints/src/utils/inspector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ declare_lint_pass!(DeepCodeInspector => [DEEP_CODE_INSPECTION]);
3333

3434
impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
3535
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
36-
if !has_attr(cx.sess(), &item.attrs) {
36+
if !has_attr(cx.sess(), cx.tcx.hir().attrs(item.hir_id())) {
3737
return;
3838
}
3939
print_item(cx, item);

0 commit comments

Comments
 (0)