From 5474f17011fe92c68e810b2080a7e539dc5687ea Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Nov 2020 09:55:10 +0100 Subject: [PATCH] Remove hir::ImplItem::attrs. --- compiler/rustc_ast_lowering/src/item.rs | 2 +- compiler/rustc_hir/src/hir.rs | 3 +-- compiler/rustc_hir/src/intravisit.rs | 12 ++---------- compiler/rustc_hir/src/stable_hash_impls.rs | 13 ++----------- compiler/rustc_hir_pretty/src/lib.rs | 2 +- compiler/rustc_save_analysis/src/dump_visitor.rs | 3 ++- compiler/rustc_save_analysis/src/lib.rs | 6 +++--- src/tools/clippy/clippy_lints/src/attrs.rs | 2 +- src/tools/clippy/clippy_lints/src/doc.rs | 3 ++- src/tools/clippy/clippy_lints/src/functions.rs | 5 +++-- src/tools/clippy/clippy_lints/src/missing_doc.rs | 3 ++- src/tools/clippy/clippy_lints/src/missing_inline.rs | 3 ++- .../clippy/clippy_lints/src/utils/inspector.rs | 2 +- 13 files changed, 23 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 50db57eedb2..48efc9b64eb 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -931,10 +931,10 @@ impl<'hir> LoweringContext<'_, 'hir> { let has_value = true; let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value); let hir_id = self.lower_node_id(i.id); + self.lower_attrs(hir_id, &i.attrs); hir::ImplItem { def_id: hir_id.expect_owner(), ident: i.ident, - attrs: self.lower_attrs(hir_id, &i.attrs), generics, vis: self.lower_visibility(&i.vis, None), defaultness, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index d72de243a00..6102c9d2acb 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2090,7 +2090,6 @@ pub struct ImplItem<'hir> { pub def_id: LocalDefId, pub vis: Visibility<'hir>, pub defaultness: Defaultness, - pub attrs: &'hir [Attribute], pub generics: Generics<'hir>, pub kind: ImplItemKind<'hir>, pub span: Span, @@ -3080,6 +3079,6 @@ mod size_asserts { rustc_data_structures::static_assert_size!(super::Item<'static>, 200); rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128); - rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 168); + rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 152); rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 136); } diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index c30b8efdfb2..61280c96436 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -988,16 +988,8 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) { // N.B., deliberately force a compilation error if/when new fields are added. - let ImplItem { - def_id: _, - ident, - ref vis, - ref defaultness, - attrs: _, - ref generics, - ref kind, - span: _, - } = *impl_item; + let ImplItem { def_id: _, ident, ref vis, ref defaultness, ref generics, ref kind, span: _ } = + *impl_item; visitor.visit_ident(ident); visitor.visit_vis(vis); diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index d47482b8828..5b88a69835d 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -152,22 +152,13 @@ impl HashStable for TraitItem<'_> { impl HashStable for ImplItem<'_> { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { - let ImplItem { - def_id: _, - ident, - ref vis, - defaultness, - ref attrs, - ref generics, - ref kind, - span, - } = *self; + let ImplItem { def_id: _, ident, ref vis, defaultness, ref generics, ref kind, span } = + *self; hcx.hash_hir_item_like(|hcx| { ident.name.hash_stable(hcx, hasher); vis.hash_stable(hcx, hasher); defaultness.hash_stable(hcx, hasher); - attrs.hash_stable(hcx, hasher); generics.hash_stable(hcx, hasher); kind.hash_stable(hcx, hasher); span.hash_stable(hcx, hasher); diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index fefade557b2..49c8107e07b 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -988,7 +988,7 @@ impl<'a> State<'a> { self.ann.pre(self, AnnNode::SubItem(ii.hir_id())); self.hardbreak_if_not_bol(); self.maybe_print_comment(ii.span.lo()); - self.print_outer_attributes(&ii.attrs); + self.print_outer_attributes(self.attrs(ii.hir_id())); self.print_defaultness(ii.defaultness); match ii.kind { diff --git a/compiler/rustc_save_analysis/src/dump_visitor.rs b/compiler/rustc_save_analysis/src/dump_visitor.rs index 494c2b246ba..2dd022b5ed7 100644 --- a/compiler/rustc_save_analysis/src/dump_visitor.rs +++ b/compiler/rustc_save_analysis/src/dump_visitor.rs @@ -1067,6 +1067,7 @@ impl<'tcx> DumpVisitor<'tcx> { match impl_item.kind { hir::ImplItemKind::Const(ref ty, body) => { let body = self.tcx.hir().body(body); + let attrs = self.tcx.hir().attrs(impl_item.hir_id()); self.process_assoc_const( impl_item.hir_id(), impl_item.ident, @@ -1074,7 +1075,7 @@ impl<'tcx> DumpVisitor<'tcx> { Some(&body.value), impl_id, &impl_item.vis, - &impl_item.attrs, + attrs, ); } hir::ImplItemKind::Fn(ref sig, body) => { diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index 8a188e8d05f..a6a1dba7bfa 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -426,9 +426,9 @@ impl<'tcx> SaveContext<'tcx> { let trait_id = self.tcx.trait_id_of_impl(impl_id); let mut docs = String::new(); let mut attrs = vec![]; - if let Some(Node::ImplItem(item)) = hir.find(hir_id) { - docs = self.docs_for_attrs(&item.attrs); - attrs = item.attrs.to_vec(); + if let Some(Node::ImplItem(_)) = hir.find(hir_id) { + attrs = self.tcx.hir().attrs(hir_id).to_vec(); + docs = self.docs_for_attrs(&attrs); } let mut decl_id = None; diff --git a/src/tools/clippy/clippy_lints/src/attrs.rs b/src/tools/clippy/clippy_lints/src/attrs.rs index 5ca67507a3d..362b11792a8 100644 --- a/src/tools/clippy/clippy_lints/src/attrs.rs +++ b/src/tools/clippy/clippy_lints/src/attrs.rs @@ -353,7 +353,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if is_relevant_impl(cx, item) { - check_attrs(cx, item.span, item.ident.name, &item.attrs) + check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id())) } } diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs index 5299b192f50..058f64780d6 100644 --- a/src/tools/clippy/clippy_lints/src/doc.rs +++ b/src/tools/clippy/clippy_lints/src/doc.rs @@ -260,7 +260,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { - let headers = check_attrs(cx, &self.valid_idents, &item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + let headers = check_attrs(cx, &self.valid_idents, attrs); if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) { return; } diff --git a/src/tools/clippy/clippy_lints/src/functions.rs b/src/tools/clippy/clippy_lints/src/functions.rs index 4a10f9abce4..b48b0b9f3e2 100644 --- a/src/tools/clippy/clippy_lints/src/functions.rs +++ b/src/tools/clippy/clippy_lints/src/functions.rs @@ -312,11 +312,12 @@ impl<'tcx> LateLintPass<'tcx> for Functions { if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() { check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); } - let attr = must_use_attr(&item.attrs); + let attrs = cx.tcx.hir().attrs(item.hir_id()); + let attr = must_use_attr(attrs); if let Some(attr) = attr { check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr); } else if is_public - && !is_proc_macro(cx.sess(), &item.attrs) + && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.hir_id()).is_none() { check_must_use_candidate( diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index 0a75b47e2c6..84852dd602b 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -183,7 +183,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); - self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, article, desc); + let attrs = cx.tcx.hir().attrs(impl_item.hir_id()); + self.check_missing_docs_attrs(cx, attrs, impl_item.span, article, desc); } fn check_struct_field(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::StructField<'_>) { diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index 74afc292f01..c915e329087 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -161,6 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { } } - check_missing_inline_attrs(cx, &impl_item.attrs, impl_item.span, desc); + let attrs = cx.tcx.hir().attrs(impl_item.hir_id()); + check_missing_inline_attrs(cx, attrs, impl_item.span, desc); } } diff --git a/src/tools/clippy/clippy_lints/src/utils/inspector.rs b/src/tools/clippy/clippy_lints/src/utils/inspector.rs index e1c58d88952..e95840e9db1 100644 --- a/src/tools/clippy/clippy_lints/src/utils/inspector.rs +++ b/src/tools/clippy/clippy_lints/src/utils/inspector.rs @@ -40,7 +40,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector { } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { - if !has_attr(cx.sess(), &item.attrs) { + if !has_attr(cx.sess(), cx.tcx.hir().attrs(item.hir_id())) { return; } println!("impl item `{}`", item.ident.name);