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
}

0 commit comments

Comments
 (0)