Skip to content

Commit edbbd56

Browse files
committed
Remove span from hir::Item.
1 parent 066195c commit edbbd56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+414
-380
lines changed

src/librustc_ast_lowering/item.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
223223

224224
let kind = self.lower_item_kind(i.span, i.id, &mut ident, attrs, &mut vis, &i.kind);
225225

226-
Some(hir::Item {
227-
hir_id: self.lower_node_id(i.id, i.span),
228-
ident,
229-
attrs,
230-
kind,
231-
vis,
232-
span: i.span,
233-
})
226+
Some(hir::Item { hir_id: self.lower_node_id(i.id, i.span), ident, attrs, kind, vis })
234227
}
235228

236229
fn lower_item_kind(
@@ -511,14 +504,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
511504
let kind = hir::ItemKind::Use(path, hir::UseKind::Single);
512505
let vis = this.rebuild_vis(&vis);
513506

514-
this.insert_item(hir::Item {
515-
hir_id: new_id,
516-
ident,
517-
attrs,
518-
kind,
519-
vis,
520-
span,
521-
});
507+
this.insert_item(hir::Item { hir_id: new_id, ident, attrs, kind, vis });
522508
});
523509
}
524510

@@ -580,14 +566,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
580566
let kind =
581567
this.lower_use_tree(use_tree, &prefix, id, &mut vis, &mut ident, attrs);
582568

583-
this.insert_item(hir::Item {
584-
hir_id: new_hir_id,
585-
ident,
586-
attrs,
587-
kind,
588-
vis,
589-
span: use_tree.span,
590-
});
569+
this.insert_item(hir::Item { hir_id: new_hir_id, ident, attrs, kind, vis });
591570
});
592571
}
593572

@@ -683,7 +662,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
683662
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
684663
},
685664
vis: self.lower_visibility(&i.vis, None),
686-
span: i.span,
687665
}
688666
}
689667

@@ -790,7 +768,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
790768
attrs: self.lower_attrs(&i.attrs),
791769
generics,
792770
kind,
793-
span: i.span,
794771
}
795772
}
796773

@@ -876,7 +853,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
876853
vis: self.lower_visibility(&i.vis, None),
877854
defaultness,
878855
kind,
879-
span: i.span,
880856
}
881857
}
882858

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
575575
self.spans.push_owner(Idx::new(self.resolver.definitions().def_index_count() - 1));
576576

577577
hir::Crate {
578-
item: hir::CrateItem { module, attrs, span: c.span },
578+
item: hir::CrateItem { module, attrs },
579579
exported_macros: self.arena.alloc_from_iter(self.exported_macros),
580580
non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs),
581581
items: self.items,
@@ -1507,7 +1507,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15071507
attrs: Default::default(),
15081508
kind: opaque_ty_item_kind,
15091509
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
1510-
span: opaque_ty_span,
15111510
};
15121511

15131512
// Insert the item into the global item list. This usually happens

src/librustc_codegen_llvm/consts.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,13 @@ impl CodegenCx<'ll, 'tcx> {
214214
let llty = self.layout_of(ty).llvm_type(self);
215215
// FIXME: refactor this to work without accessing the HIR
216216
let (g, attrs) = match self.tcx.hir().get(id) {
217-
Node::Item(&hir::Item { attrs, span, kind: hir::ItemKind::Static(..), .. }) => {
217+
Node::Item(&hir::Item {
218+
attrs, hir_id, kind: hir::ItemKind::Static(..), ..
219+
}) => {
218220
let sym_str = sym.as_str();
219221
if let Some(g) = self.get_declared_value(&sym_str) {
220222
if self.val_ty(g) != self.type_ptr_to(llty) {
223+
let span = self.tcx.hir().span(hir_id);
221224
span_bug!(span, "Conflicting types for static");
222225
}
223226
}
@@ -235,11 +238,12 @@ impl CodegenCx<'ll, 'tcx> {
235238

236239
Node::ForeignItem(&hir::ForeignItem {
237240
ref attrs,
238-
span,
241+
hir_id,
239242
kind: hir::ForeignItemKind::Static(..),
240243
..
241244
}) => {
242245
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
246+
let span = self.tcx.hir().span(hir_id);
243247
(check_and_apply_linkage(&self, &fn_attrs, ty, sym, span), &**attrs)
244248
}
245249

src/librustc_codegen_ssa/mono_item.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
3535
if let hir::ItemKind::GlobalAsm(ref ga) = item.kind {
3636
cx.codegen_global_asm(ga);
3737
} else {
38-
span_bug!(item.span, "Mismatch between hir::Item type and MonoItem type")
38+
let span = cx.tcx().hir().span(hir_id);
39+
span_bug!(span, "Mismatch between hir::Item type and MonoItem type")
3940
}
4041
}
4142
MonoItem::Fn(instance) => {

src/librustc_hir/hir.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ pub struct ModuleItems {
581581
pub struct CrateItem<'hir> {
582582
pub module: Mod<'hir>,
583583
pub attrs: &'hir [Attribute],
584-
pub span: Span,
585584
}
586585

587586
/// The top-level data structure that stores the entire contents of
@@ -1846,7 +1845,6 @@ pub struct TraitItem<'hir> {
18461845
pub attrs: &'hir [Attribute],
18471846
pub generics: Generics<'hir>,
18481847
pub kind: TraitItemKind<'hir>,
1849-
pub span: Span,
18501848
}
18511849

18521850
/// Represents a trait method's body (or just argument names).
@@ -1889,7 +1887,6 @@ pub struct ImplItem<'hir> {
18891887
pub attrs: &'hir [Attribute],
18901888
pub generics: Generics<'hir>,
18911889
pub kind: ImplItemKind<'hir>,
1892-
pub span: Span,
18931890
}
18941891

18951892
/// Represents various kinds of content within an `impl`.
@@ -2424,7 +2421,6 @@ pub struct Item<'hir> {
24242421
pub attrs: &'hir [Attribute],
24252422
pub kind: ItemKind<'hir>,
24262423
pub vis: Visibility<'hir>,
2427-
pub span: Span,
24282424
}
24292425

24302426
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
@@ -2597,7 +2593,6 @@ pub struct ForeignItem<'hir> {
25972593
pub attrs: &'hir [Attribute],
25982594
pub kind: ForeignItemKind<'hir>,
25992595
pub hir_id: HirId,
2600-
pub span: Span,
26012596
pub vis: Visibility<'hir>,
26022597
}
26032598

src/librustc_hir/intravisit.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -941,16 +941,8 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
941941

942942
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
943943
// N.B., deliberately force a compilation error if/when new fields are added.
944-
let ImplItem {
945-
hir_id: _,
946-
ident,
947-
ref vis,
948-
ref defaultness,
949-
attrs,
950-
ref generics,
951-
ref kind,
952-
span: _,
953-
} = *impl_item;
944+
let ImplItem { hir_id: _, ident, ref vis, ref defaultness, attrs, ref generics, ref kind } =
945+
*impl_item;
954946

955947
visitor.visit_ident(ident);
956948
visitor.visit_vis(vis);

src/librustc_hir/stable_hash_impls.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,21 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_>
115115

116116
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
117117
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
118-
let TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind, span } = *self;
118+
let TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind } = *self;
119119

120120
hcx.hash_hir_item_like(|hcx| {
121121
ident.name.hash_stable(hcx, hasher);
122122
attrs.hash_stable(hcx, hasher);
123123
generics.hash_stable(hcx, hasher);
124124
kind.hash_stable(hcx, hasher);
125-
span.hash_stable(hcx, hasher);
126125
});
127126
}
128127
}
129128

130129
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
131130
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
132-
let ImplItem {
133-
hir_id: _,
134-
ident,
135-
ref vis,
136-
defaultness,
137-
ref attrs,
138-
ref generics,
139-
ref kind,
140-
span,
141-
} = *self;
131+
let ImplItem { hir_id: _, ident, ref vis, defaultness, ref attrs, ref generics, ref kind } =
132+
*self;
142133

143134
hcx.hash_hir_item_like(|hcx| {
144135
ident.name.hash_stable(hcx, hasher);
@@ -147,21 +138,19 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
147138
attrs.hash_stable(hcx, hasher);
148139
generics.hash_stable(hcx, hasher);
149140
kind.hash_stable(hcx, hasher);
150-
span.hash_stable(hcx, hasher);
151141
});
152142
}
153143
}
154144

155145
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Item<'_> {
156146
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
157-
let Item { ident, ref attrs, hir_id: _, ref kind, ref vis, span } = *self;
147+
let Item { ident, ref attrs, hir_id: _, ref kind, ref vis } = *self;
158148

159149
hcx.hash_hir_item_like(|hcx| {
160150
ident.name.hash_stable(hcx, hasher);
161151
attrs.hash_stable(hcx, hasher);
162152
kind.hash_stable(hcx, hasher);
163153
vis.hash_stable(hcx, hasher);
164-
span.hash_stable(hcx, hasher);
165154
});
166155
}
167156
}

src/librustc_hir_pretty/lib.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,9 @@ impl<'a> State<'a> {
466466
}
467467

468468
pub fn print_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
469+
let item_span = self.span(item.hir_id);
469470
self.hardbreak_if_not_bol();
470-
self.maybe_print_comment(item.span.lo());
471+
self.maybe_print_comment(item_span.lo());
471472
self.print_outer_attributes(&item.attrs);
472473
match item.kind {
473474
hir::ForeignItemKind::Fn(ref decl, ref arg_names, ref generics) => {
@@ -574,8 +575,9 @@ impl<'a> State<'a> {
574575

575576
/// Pretty-print an item
576577
pub fn print_item(&mut self, item: &hir::Item<'_>) {
578+
let span = self.span(item.hir_id);
577579
self.hardbreak_if_not_bol();
578-
self.maybe_print_comment(item.span.lo());
580+
self.maybe_print_comment(span.lo());
579581
self.print_outer_attributes(&item.attrs);
580582
self.ann.pre(self, AnnNode::Item(item));
581583
match item.kind {
@@ -662,14 +664,14 @@ impl<'a> State<'a> {
662664
self.nbsp();
663665
self.bopen();
664666
self.print_mod(_mod, &item.attrs);
665-
self.bclose(item.span);
667+
self.bclose(span);
666668
}
667669
hir::ItemKind::ForeignMod(ref nmod) => {
668670
self.head("extern");
669671
self.word_nbsp(nmod.abi.to_string());
670672
self.bopen();
671673
self.print_foreign_mod(nmod, &item.attrs);
672-
self.bclose(item.span);
674+
self.bclose(span);
673675
}
674676
hir::ItemKind::GlobalAsm(ref ga) => {
675677
self.head(visibility_qualified(&item.vis, "global asm"));
@@ -698,15 +700,15 @@ impl<'a> State<'a> {
698700
});
699701
}
700702
hir::ItemKind::Enum(ref enum_definition, ref params) => {
701-
self.print_enum_def(enum_definition, params, item.ident.name, item.span, &item.vis);
703+
self.print_enum_def(enum_definition, params, item.ident.name, span, &item.vis);
702704
}
703705
hir::ItemKind::Struct(ref struct_def, ref generics) => {
704706
self.head(visibility_qualified(&item.vis, "struct"));
705-
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
707+
self.print_struct(struct_def, generics, item.ident.name, span, true);
706708
}
707709
hir::ItemKind::Union(ref struct_def, ref generics) => {
708710
self.head(visibility_qualified(&item.vis, "union"));
709-
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
711+
self.print_struct(struct_def, generics, item.ident.name, span, true);
710712
}
711713
hir::ItemKind::Impl {
712714
unsafety,
@@ -753,7 +755,7 @@ impl<'a> State<'a> {
753755
for impl_item in items {
754756
self.ann.nested(self, Nested::ImplItem(impl_item.id));
755757
}
756-
self.bclose(item.span);
758+
self.bclose(span);
757759
}
758760
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, trait_items) => {
759761
self.head("");
@@ -780,7 +782,7 @@ impl<'a> State<'a> {
780782
for trait_item in trait_items {
781783
self.ann.nested(self, Nested::TraitItem(trait_item.id));
782784
}
783-
self.bclose(item.span);
785+
self.bclose(span);
784786
}
785787
hir::ItemKind::TraitAlias(ref generics, ref bounds) => {
786788
self.head("");
@@ -961,9 +963,10 @@ impl<'a> State<'a> {
961963
}
962964

963965
pub fn print_trait_item(&mut self, ti: &hir::TraitItem<'_>) {
966+
let span = self.span(ti.hir_id);
964967
self.ann.pre(self, AnnNode::SubItem(ti.hir_id));
965968
self.hardbreak_if_not_bol();
966-
self.maybe_print_comment(ti.span.lo());
969+
self.maybe_print_comment(span.lo());
967970
self.print_outer_attributes(&ti.attrs);
968971
match ti.kind {
969972
hir::TraitItemKind::Const(ref ty, default) => {
@@ -1000,9 +1003,10 @@ impl<'a> State<'a> {
10001003
}
10011004

10021005
pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) {
1006+
let span = self.span(ii.hir_id);
10031007
self.ann.pre(self, AnnNode::SubItem(ii.hir_id));
10041008
self.hardbreak_if_not_bol();
1005-
self.maybe_print_comment(ii.span.lo());
1009+
self.maybe_print_comment(span.lo());
10061010
self.print_outer_attributes(&ii.attrs);
10071011
self.print_defaultness(ii.defaultness);
10081012

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,9 @@ impl DirtyCleanVisitor<'tcx> {
431431
}
432432
}
433433

434-
fn check_item(&mut self, item_id: hir::HirId, item_span: Span) {
434+
fn check_item(&mut self, item_id: hir::HirId) {
435435
let def_id = self.tcx.hir().local_def_id(item_id);
436+
let item_span = self.tcx.hir().span(item_id);
436437
for attr in self.tcx.get_attrs(def_id.to_def_id()).iter() {
437438
let assertion = match self.assertion_maybe(item_id, attr) {
438439
Some(a) => a,
@@ -451,15 +452,15 @@ impl DirtyCleanVisitor<'tcx> {
451452

452453
impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
453454
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
454-
self.check_item(item.hir_id, item.span);
455+
self.check_item(item.hir_id);
455456
}
456457

457458
fn visit_trait_item(&mut self, item: &hir::TraitItem<'_>) {
458-
self.check_item(item.hir_id, item.span);
459+
self.check_item(item.hir_id);
459460
}
460461

461462
fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) {
462-
self.check_item(item.hir_id, item.span);
463+
self.check_item(item.hir_id);
463464
}
464465
}
465466

0 commit comments

Comments
 (0)