Skip to content

Commit c49359a

Browse files
committed
Remove hir::TraitItem::attrs.
1 parent 4bab93a commit c49359a

File tree

12 files changed

+25
-29
lines changed

12 files changed

+25
-29
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -851,14 +851,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
851851
AssocItemKind::MacCall(..) => panic!("macro item shouldn't exist at this point"),
852852
};
853853

854-
hir::TraitItem {
855-
def_id: trait_item_def_id,
856-
ident: i.ident,
857-
attrs: self.lower_attrs(hir_id, &i.attrs),
858-
generics,
859-
kind,
860-
span: i.span,
861-
}
854+
self.lower_attrs(hir_id, &i.attrs);
855+
hir::TraitItem { def_id: trait_item_def_id, ident: i.ident, generics, kind, span: i.span }
862856
}
863857

864858
fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef {

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,6 @@ impl TraitItemId {
20282028
pub struct TraitItem<'hir> {
20292029
pub ident: Ident,
20302030
pub def_id: LocalDefId,
2031-
pub attrs: &'hir [Attribute],
20322031
pub generics: Generics<'hir>,
20332032
pub kind: TraitItemKind<'hir>,
20342033
pub span: Span,
@@ -3080,7 +3079,7 @@ mod size_asserts {
30803079
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
30813080

30823081
rustc_data_structures::static_assert_size!(super::Item<'static>, 200);
3083-
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 144);
3082+
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);
30843083
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 168);
30853084
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 136);
30863085
}

compiler/rustc_hir/src/stable_hash_impls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,10 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_>
139139

140140
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
141141
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
142-
let TraitItem { def_id: _, ident, ref attrs, ref generics, ref kind, span } = *self;
142+
let TraitItem { def_id: _, ident, ref generics, ref kind, span } = *self;
143143

144144
hcx.hash_hir_item_like(|hcx| {
145145
ident.name.hash_stable(hcx, hasher);
146-
attrs.hash_stable(hcx, hasher);
147146
generics.hash_stable(hcx, hasher);
148147
kind.hash_stable(hcx, hasher);
149148
span.hash_stable(hcx, hasher);

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ impl<'a> State<'a> {
949949
self.ann.pre(self, AnnNode::SubItem(ti.hir_id()));
950950
self.hardbreak_if_not_bol();
951951
self.maybe_print_comment(ti.span.lo());
952-
self.print_outer_attributes(&ti.attrs);
952+
self.print_outer_attributes(self.attrs(ti.hir_id()));
953953
match ti.kind {
954954
hir::TraitItemKind::Const(ref ty, default) => {
955955
let vis =

compiler/rustc_save_analysis/src/dump_visitor.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -994,14 +994,15 @@ impl<'tcx> DumpVisitor<'tcx> {
994994
hir::TraitItemKind::Const(ref ty, body) => {
995995
let body = body.map(|b| &self.tcx.hir().body(b).value);
996996
let respan = respan(vis_span, hir::VisibilityKind::Public);
997+
let attrs = self.tcx.hir().attrs(trait_item.hir_id());
997998
self.process_assoc_const(
998999
trait_item.hir_id(),
9991000
trait_item.ident,
10001001
&ty,
10011002
body,
10021003
trait_id,
10031004
&respan,
1004-
&trait_item.attrs,
1005+
attrs,
10051006
);
10061007
}
10071008
hir::TraitItemKind::Fn(ref sig, ref trait_fn) => {
@@ -1027,6 +1028,7 @@ impl<'tcx> DumpVisitor<'tcx> {
10271028
if !self.span.filter_generated(trait_item.ident.span) {
10281029
let span = self.span_from_span(trait_item.ident.span);
10291030
let id = id_from_def_id(trait_item.def_id.to_def_id());
1031+
let attrs = self.tcx.hir().attrs(trait_item.hir_id());
10301032

10311033
self.dumper.dump_def(
10321034
&Access { public: true, reachable: true },
@@ -1040,18 +1042,15 @@ impl<'tcx> DumpVisitor<'tcx> {
10401042
parent: Some(id_from_def_id(trait_id)),
10411043
children: vec![],
10421044
decl_id: None,
1043-
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
1045+
docs: self.save_ctxt.docs_for_attrs(attrs),
10441046
sig: sig::assoc_type_signature(
10451047
trait_item.hir_id(),
10461048
trait_item.ident,
10471049
Some(bounds),
10481050
default_ty.as_ref().map(|ty| &**ty),
10491051
&self.save_ctxt,
10501052
),
1051-
attributes: lower_attributes(
1052-
trait_item.attrs.to_vec(),
1053-
&self.save_ctxt,
1054-
),
1053+
attributes: lower_attributes(attrs.to_vec(), &self.save_ctxt),
10551054
},
10561055
);
10571056
}

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ impl<'tcx> SaveContext<'tcx> {
472472
let mut docs = String::new();
473473
let mut attrs = vec![];
474474

475-
if let Some(Node::TraitItem(item)) = self.tcx.hir().find(hir_id) {
476-
docs = self.docs_for_attrs(&item.attrs);
477-
attrs = item.attrs.to_vec();
475+
if let Some(Node::TraitItem(_)) = self.tcx.hir().find(hir_id) {
476+
attrs = self.tcx.hir().attrs(hir_id).to_vec();
477+
docs = self.docs_for_attrs(&attrs);
478478
}
479479

480480
(

src/tools/clippy/clippy_lints/src/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
359359

360360
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
361361
if is_relevant_trait(cx, item) {
362-
check_attrs(cx, item.span, item.ident.name, &item.attrs)
362+
check_attrs(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()))
363363
}
364364
}
365365
}

src/tools/clippy/clippy_lints/src/doc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
250250
}
251251

252252
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
253-
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
253+
let attrs = cx.tcx.hir().attrs(item.hir_id());
254+
let headers = check_attrs(cx, &self.valid_idents, attrs);
254255
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
255256
if !in_external_macro(cx.tcx.sess, item.span) {
256257
lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None);

src/tools/clippy/clippy_lints/src/functions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,16 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
344344
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
345345
}
346346

347-
let attr = must_use_attr(&item.attrs);
347+
let attrs = cx.tcx.hir().attrs(item.hir_id());
348+
let attr = must_use_attr(attrs);
348349
if let Some(attr) = attr {
349350
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
350351
}
351352
if let hir::TraitFn::Provided(eid) = *eid {
352353
let body = cx.tcx.hir().body(eid);
353354
Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id());
354355

355-
if attr.is_none() && is_public && !is_proc_macro(cx.sess(), &item.attrs) {
356+
if attr.is_none() && is_public && !is_proc_macro(cx.sess(), attrs) {
356357
check_must_use_candidate(
357358
cx,
358359
&sig.decl,

src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]);
3434
impl<'tcx> LateLintPass<'tcx> for InlineFnWithoutBody {
3535
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
3636
if let TraitItemKind::Fn(_, TraitFn::Required(_)) = item.kind {
37-
check_attrs(cx, item.ident.name, &item.attrs);
37+
let attrs = cx.tcx.hir().attrs(item.hir_id());
38+
check_attrs(cx, item.ident.name, attrs);
3839
}
3940
}
4041
}

src/tools/clippy/clippy_lints/src/missing_doc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
167167
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) {
168168
let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id());
169169

170-
self.check_missing_docs_attrs(cx, &trait_item.attrs, trait_item.span, article, desc);
170+
let attrs = cx.tcx.hir().attrs(trait_item.hir_id());
171+
self.check_missing_docs_attrs(cx, attrs, trait_item.span, article, desc);
171172
}
172173

173174
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {

src/tools/clippy/clippy_lints/src/missing_inline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
108108
// an impl is not provided
109109
let desc = "a default trait method";
110110
let item = cx.tcx.hir().trait_item(tit.id);
111-
check_missing_inline_attrs(cx, &item.attrs, item.span, desc);
111+
let attrs = cx.tcx.hir().attrs(item.hir_id());
112+
check_missing_inline_attrs(cx, attrs, item.span, desc);
112113
}
113114
},
114115
}

0 commit comments

Comments
 (0)