Skip to content

Commit c701872

Browse files
committed
Remove hir::Item::attrs.
1 parent 5474f17 commit c701872

File tree

32 files changed

+104
-76
lines changed

32 files changed

+104
-76
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
242242
let hir_id = self.lower_node_id(i.id);
243243
let attrs = self.lower_attrs(hir_id, &i.attrs);
244244
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind);
245-
Some(hir::Item { def_id: hir_id.expect_owner(), ident, attrs, kind, vis, span: i.span })
245+
Some(hir::Item { def_id: hir_id.expect_owner(), ident, kind, vis, span: i.span })
246246
}
247247

248248
fn lower_item_kind(
@@ -556,7 +556,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
556556
this.insert_item(hir::Item {
557557
def_id: new_id.expect_owner(),
558558
ident,
559-
attrs,
560559
kind,
561560
vis,
562561
span,
@@ -629,7 +628,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
629628
this.insert_item(hir::Item {
630629
def_id: new_hir_id.expect_owner(),
631630
ident,
632-
attrs,
633631
kind,
634632
vis,
635633
span: use_tree.span,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15791579
let opaque_ty_item = hir::Item {
15801580
def_id: opaque_ty_id,
15811581
ident: Ident::invalid(),
1582-
attrs: Default::default(),
15831582
kind: opaque_ty_item_kind,
15841583
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
15851584
span: opaque_ty_span,

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,6 @@ impl ItemId {
26972697
pub struct Item<'hir> {
26982698
pub ident: Ident,
26992699
pub def_id: LocalDefId,
2700-
pub attrs: &'hir [Attribute],
27012700
pub kind: ItemKind<'hir>,
27022701
pub vis: Visibility<'hir>,
27032702
pub span: Span,
@@ -3077,7 +3076,7 @@ mod size_asserts {
30773076
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
30783077
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
30793078

3080-
rustc_data_structures::static_assert_size!(super::Item<'static>, 200);
3079+
rustc_data_structures::static_assert_size!(super::Item<'static>, 184);
30813080
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);
30823081
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 152);
30833082
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 136);

compiler/rustc_hir/src/stable_hash_impls.rs

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

182182
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
183183
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
184-
let Item { ident, ref attrs, def_id: _, ref kind, ref vis, span } = *self;
184+
let Item { ident, def_id: _, ref kind, ref vis, span } = *self;
185185

186186
hcx.hash_hir_item_like(|hcx| {
187187
ident.name.hash_stable(hcx, hasher);
188-
attrs.hash_stable(hcx, hasher);
189188
kind.hash_stable(hcx, hasher);
190189
vis.hash_stable(hcx, hasher);
191190
span.hash_stable(hcx, hasher);

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ impl<'a> State<'a> {
561561
pub fn print_item(&mut self, item: &hir::Item<'_>) {
562562
self.hardbreak_if_not_bol();
563563
self.maybe_print_comment(item.span.lo());
564-
self.print_outer_attributes(&item.attrs);
564+
let attrs = self.attrs(item.hir_id());
565+
self.print_outer_attributes(attrs);
565566
self.ann.pre(self, AnnNode::Item(item));
566567
match item.kind {
567568
hir::ItemKind::ExternCrate(orig_name) => {
@@ -646,14 +647,14 @@ impl<'a> State<'a> {
646647
self.print_ident(item.ident);
647648
self.nbsp();
648649
self.bopen();
649-
self.print_mod(_mod, &item.attrs);
650+
self.print_mod(_mod, attrs);
650651
self.bclose(item.span);
651652
}
652653
hir::ItemKind::ForeignMod { abi, items } => {
653654
self.head("extern");
654655
self.word_nbsp(abi.to_string());
655656
self.bopen();
656-
self.print_inner_attributes(item.attrs);
657+
self.print_inner_attributes(self.attrs(item.hir_id()));
657658
for item in items {
658659
self.ann.nested(self, Nested::ForeignItem(item.id));
659660
}
@@ -737,7 +738,7 @@ impl<'a> State<'a> {
737738

738739
self.s.space();
739740
self.bopen();
740-
self.print_inner_attributes(&item.attrs);
741+
self.print_inner_attributes(attrs);
741742
for impl_item in items {
742743
self.ann.nested(self, Nested::ImplItem(impl_item.id));
743744
}

compiler/rustc_interface/src/proc_macro_decls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ struct Finder<'tcx> {
2525

2626
impl<'v> ItemLikeVisitor<'v> for Finder<'_> {
2727
fn visit_item(&mut self, item: &hir::Item<'_>) {
28-
if self.tcx.sess.contains_name(&item.attrs, sym::rustc_proc_macro_decls) {
28+
let attrs = self.tcx.hir().attrs(item.hir_id());
29+
if self.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
2930
self.decls = Some(item.hir_id());
3031
}
3132
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,10 @@ declare_lint_pass!(InvalidNoMangleItems => [NO_MANGLE_CONST_ITEMS, NO_MANGLE_GEN
10921092

10931093
impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
10941094
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
1095+
let attrs = cx.tcx.hir().attrs(it.hir_id());
10951096
match it.kind {
10961097
hir::ItemKind::Fn(.., ref generics, _) => {
1097-
if let Some(no_mangle_attr) = cx.sess().find_by_name(&it.attrs, sym::no_mangle) {
1098+
if let Some(no_mangle_attr) = cx.sess().find_by_name(attrs, sym::no_mangle) {
10981099
for param in generics.params {
10991100
match param.kind {
11001101
GenericParamKind::Lifetime { .. } => {}
@@ -1120,7 +1121,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
11201121
}
11211122
}
11221123
hir::ItemKind::Const(..) => {
1123-
if cx.sess().contains_name(&it.attrs, sym::no_mangle) {
1124+
if cx.sess().contains_name(attrs, sym::no_mangle) {
11241125
// Const items do not refer to a particular location in memory, and therefore
11251126
// don't have anything to attach a symbol to
11261127
cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it.span, |lint| {
@@ -1800,7 +1801,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnameableTestItems {
18001801
return;
18011802
}
18021803

1803-
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::rustc_test_marker) {
1804+
let attrs = cx.tcx.hir().attrs(it.hir_id());
1805+
if let Some(attr) = cx.sess().find_by_name(attrs, sym::rustc_test_marker) {
18041806
cx.struct_span_lint(UNNAMEABLE_TEST_ITEMS, attr.span, |lint| {
18051807
lint.build("cannot test inner items").emit()
18061808
});

compiler/rustc_lint/src/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn is_doc_keyword(s: Symbol) -> bool {
283283

284284
impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
285285
fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
286-
for attr in item.attrs {
286+
for attr in cx.tcx.hir().attrs(item.hir_id()) {
287287
if !attr.has_name(sym::doc) {
288288
continue;
289289
}

compiler/rustc_lint/src/nonstandard_style.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,9 @@ impl NonUpperCaseGlobals {
505505

506506
impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
507507
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
508+
let attrs = cx.tcx.hir().attrs(it.hir_id());
508509
match it.kind {
509-
hir::ItemKind::Static(..) if !cx.sess().contains_name(&it.attrs, sym::no_mangle) => {
510+
hir::ItemKind::Static(..) if !cx.sess().contains_name(attrs, sym::no_mangle) => {
510511
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &it.ident);
511512
}
512513
hir::ItemKind::Const(..) => {

compiler/rustc_metadata/src/link_args.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
3636

3737
// First, add all of the custom #[link_args] attributes
3838
let sess = &self.tcx.sess;
39-
for m in it.attrs.iter().filter(|a| sess.check_name(a, sym::link_args)) {
39+
for m in
40+
self.tcx.hir().attrs(it.hir_id()).iter().filter(|a| sess.check_name(a, sym::link_args))
41+
{
4042
if let Some(linkarg) = m.value_str() {
4143
self.add_link_args(linkarg);
4244
}

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
4444

4545
// Process all of the #[link(..)]-style arguments
4646
let sess = &self.tcx.sess;
47-
for m in it.attrs.iter().filter(|a| sess.check_name(a, sym::link)) {
47+
for m in self.tcx.hir().attrs(it.hir_id()).iter().filter(|a| sess.check_name(a, sym::link))
48+
{
4849
let items = match m.meta_item_list() {
4950
Some(item) => item,
5051
None => continue,

compiler/rustc_passes/src/entry.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(LocalDefId, EntryFnType)
8080

8181
// Beware, this is duplicated in `librustc_builtin_macros/test_harness.rs`
8282
// (with `ast::Item`), so make sure to keep them in sync.
83-
fn entry_point_type(sess: &Session, item: &Item<'_>, at_root: bool) -> EntryPointType {
84-
if sess.contains_name(&item.attrs, sym::start) {
83+
fn entry_point_type(ctxt: &EntryContext<'_, '_>, item: &Item<'_>, at_root: bool) -> EntryPointType {
84+
let attrs = ctxt.map.attrs(item.hir_id());
85+
if ctxt.session.contains_name(attrs, sym::start) {
8586
EntryPointType::Start
86-
} else if sess.contains_name(&item.attrs, sym::main) {
87+
} else if ctxt.session.contains_name(attrs, sym::main) {
8788
EntryPointType::MainAttr
8889
} else if item.ident.name == sym::main {
8990
if at_root {
@@ -103,13 +104,14 @@ fn throw_attr_err(sess: &Session, span: Span, attr: &str) {
103104
}
104105

105106
fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
106-
match entry_point_type(&ctxt.session, item, at_root) {
107+
match entry_point_type(ctxt, item, at_root) {
107108
EntryPointType::None => (),
108109
_ if !matches!(item.kind, ItemKind::Fn(..)) => {
109-
if let Some(attr) = ctxt.session.find_by_name(item.attrs, sym::start) {
110+
let attrs = ctxt.map.attrs(item.hir_id());
111+
if let Some(attr) = ctxt.session.find_by_name(attrs, sym::start) {
110112
throw_attr_err(&ctxt.session, attr.span, "start");
111113
}
112-
if let Some(attr) = ctxt.session.find_by_name(item.attrs, sym::main) {
114+
if let Some(attr) = ctxt.session.find_by_name(attrs, sym::main) {
113115
throw_attr_err(&ctxt.session, attr.span, "main");
114116
}
115117
}

compiler/rustc_passes/src/stability.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,9 @@ impl Visitor<'tcx> for Checker<'tcx> {
751751
// error if all involved types and traits are stable, because
752752
// it will have no effect.
753753
// See: https://github.com/rust-lang/rust/issues/55436
754+
let attrs = self.tcx.hir().attrs(item.hir_id());
754755
if let (Some((Stability { level: attr::Unstable { .. }, .. }, span)), _) =
755-
attr::find_stability(&self.tcx.sess, &item.attrs, item.span)
756+
attr::find_stability(&self.tcx.sess, attrs, item.span)
756757
{
757758
let mut c = CheckTraitImplStable { tcx: self.tcx, fully_stable: true };
758759
c.visit_ty(self_ty);

compiler/rustc_plugin_impl/src/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ struct RegistrarFinder<'tcx> {
1616
impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> {
1717
fn visit_item(&mut self, item: &hir::Item<'_>) {
1818
if let hir::ItemKind::Fn(..) = item.kind {
19-
if self.tcx.sess.contains_name(&item.attrs, sym::plugin_registrar) {
19+
let attrs = self.tcx.hir().attrs(item.hir_id());
20+
if self.tcx.sess.contains_name(attrs, sym::plugin_registrar) {
2021
self.registrars.push((item.def_id, item.span));
2122
}
2223
}

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,8 @@ fn compute_object_lifetime_defaults(tcx: TyCtxt<'_>) -> HirIdMap<Vec<ObjectLifet
12391239
let result = object_lifetime_defaults_for_item(tcx, generics);
12401240

12411241
// Debugging aid.
1242-
if tcx.sess.contains_name(&item.attrs, sym::rustc_object_lifetime_default) {
1242+
let attrs = tcx.hir().attrs(item.hir_id());
1243+
if tcx.sess.contains_name(attrs, sym::rustc_object_lifetime_default) {
12431244
let object_lifetime_default_reprs: String = result
12441245
.iter()
12451246
.map(|set| match *set {

compiler/rustc_save_analysis/src/dump_visitor.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ impl<'tcx> DumpVisitor<'tcx> {
496496

497497
if !self.span.filter_generated(item.ident.span) {
498498
let span = self.span_from_span(item.ident.span);
499+
let attrs = self.tcx.hir().attrs(item.hir_id());
499500
self.dumper.dump_def(
500501
&access_from!(self.save_ctxt, item, item.hir_id()),
501502
Def {
@@ -508,9 +509,9 @@ impl<'tcx> DumpVisitor<'tcx> {
508509
parent: None,
509510
children: fields,
510511
decl_id: None,
511-
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
512+
docs: self.save_ctxt.docs_for_attrs(attrs),
512513
sig: sig::item_signature(item, &self.save_ctxt),
513-
attributes: lower_attributes(item.attrs.to_vec(), &self.save_ctxt),
514+
attributes: lower_attributes(attrs.to_vec(), &self.save_ctxt),
514515
},
515516
);
516517
}
@@ -671,6 +672,7 @@ impl<'tcx> DumpVisitor<'tcx> {
671672
let span = self.span_from_span(item.ident.span);
672673
let children =
673674
methods.iter().map(|i| id_from_def_id(i.id.def_id.to_def_id())).collect();
675+
let attrs = self.tcx.hir().attrs(item.hir_id());
674676
self.dumper.dump_def(
675677
&access_from!(self.save_ctxt, item, item.hir_id()),
676678
Def {
@@ -683,9 +685,9 @@ impl<'tcx> DumpVisitor<'tcx> {
683685
parent: None,
684686
children,
685687
decl_id: None,
686-
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
688+
docs: self.save_ctxt.docs_for_attrs(attrs),
687689
sig: sig::item_signature(item, &self.save_ctxt),
688-
attributes: lower_attributes(item.attrs.to_vec(), &self.save_ctxt),
690+
attributes: lower_attributes(attrs.to_vec(), &self.save_ctxt),
689691
},
690692
);
691693
}
@@ -1260,6 +1262,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
12601262
if !self.span.filter_generated(item.ident.span) {
12611263
let span = self.span_from_span(item.ident.span);
12621264
let id = id_from_def_id(item.def_id.to_def_id());
1265+
let attrs = self.tcx.hir().attrs(item.hir_id());
12631266

12641267
self.dumper.dump_def(
12651268
&access_from!(self.save_ctxt, item, item.hir_id()),
@@ -1273,9 +1276,9 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
12731276
parent: None,
12741277
children: vec![],
12751278
decl_id: None,
1276-
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
1279+
docs: self.save_ctxt.docs_for_attrs(attrs),
12771280
sig: sig::item_signature(item, &self.save_ctxt),
1278-
attributes: lower_attributes(item.attrs.to_vec(), &self.save_ctxt),
1281+
attributes: lower_attributes(attrs.to_vec(), &self.save_ctxt),
12791282
},
12801283
);
12811284
}

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ impl<'tcx> SaveContext<'tcx> {
203203

204204
pub fn get_item_data(&self, item: &hir::Item<'_>) -> Option<Data> {
205205
let def_id = item.def_id.to_def_id();
206+
let attrs = self.tcx.hir().attrs(item.hir_id());
206207
match item.kind {
207208
hir::ItemKind::Fn(ref sig, ref generics, _) => {
208209
let qualname = format!("::{}", self.tcx.def_path_str(def_id));
@@ -225,9 +226,9 @@ impl<'tcx> SaveContext<'tcx> {
225226
parent: None,
226227
children: vec![],
227228
decl_id: None,
228-
docs: self.docs_for_attrs(&item.attrs),
229+
docs: self.docs_for_attrs(attrs),
229230
sig: sig::item_signature(item, self),
230-
attributes: lower_attributes(item.attrs.to_vec(), self),
231+
attributes: lower_attributes(attrs.to_vec(), self),
231232
}))
232233
}
233234
hir::ItemKind::Static(ref typ, ..) => {
@@ -248,9 +249,9 @@ impl<'tcx> SaveContext<'tcx> {
248249
parent: None,
249250
children: vec![],
250251
decl_id: None,
251-
docs: self.docs_for_attrs(&item.attrs),
252+
docs: self.docs_for_attrs(attrs),
252253
sig: sig::item_signature(item, self),
253-
attributes: lower_attributes(item.attrs.to_vec(), self),
254+
attributes: lower_attributes(attrs.to_vec(), self),
254255
}))
255256
}
256257
hir::ItemKind::Const(ref typ, _) => {
@@ -270,9 +271,9 @@ impl<'tcx> SaveContext<'tcx> {
270271
parent: None,
271272
children: vec![],
272273
decl_id: None,
273-
docs: self.docs_for_attrs(&item.attrs),
274+
docs: self.docs_for_attrs(attrs),
274275
sig: sig::item_signature(item, self),
275-
attributes: lower_attributes(item.attrs.to_vec(), self),
276+
attributes: lower_attributes(attrs.to_vec(), self),
276277
}))
277278
}
278279
hir::ItemKind::Mod(ref m) => {
@@ -297,9 +298,9 @@ impl<'tcx> SaveContext<'tcx> {
297298
.map(|i| id_from_def_id(i.def_id.to_def_id()))
298299
.collect(),
299300
decl_id: None,
300-
docs: self.docs_for_attrs(&item.attrs),
301+
docs: self.docs_for_attrs(attrs),
301302
sig: sig::item_signature(item, self),
302-
attributes: lower_attributes(item.attrs.to_vec(), self),
303+
attributes: lower_attributes(attrs.to_vec(), self),
303304
}))
304305
}
305306
hir::ItemKind::Enum(ref def, ref generics) => {
@@ -318,9 +319,9 @@ impl<'tcx> SaveContext<'tcx> {
318319
parent: None,
319320
children: def.variants.iter().map(|v| id_from_hir_id(v.id, self)).collect(),
320321
decl_id: None,
321-
docs: self.docs_for_attrs(&item.attrs),
322+
docs: self.docs_for_attrs(attrs),
322323
sig: sig::item_signature(item, self),
323-
attributes: lower_attributes(item.attrs.to_vec(), self),
324+
attributes: lower_attributes(attrs.to_vec(), self),
324325
}))
325326
}
326327
hir::ItemKind::Impl(hir::Impl { ref of_trait, ref self_ty, ref items, .. }) => {

compiler/rustc_typeck/src/check/method/suggest.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,11 +1466,12 @@ impl intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
14661466
if self.span.map_or(true, |span| item.span < span) {
14671467
if !item.span.from_expansion() {
14681468
// Don't insert between attributes and an item.
1469-
if item.attrs.is_empty() {
1469+
let attrs = self.tcx.hir().attrs(item.hir_id());
1470+
if attrs.is_empty() {
14701471
self.span = Some(item.span.shrink_to_lo());
14711472
} else {
14721473
// Find the first attribute on the item.
1473-
for attr in item.attrs {
1474+
for attr in attrs {
14741475
if self.span.map_or(true, |span| attr.span < span) {
14751476
self.span = Some(attr.span.shrink_to_lo());
14761477
}

0 commit comments

Comments
 (0)