Skip to content

Commit 042bf08

Browse files
committed
Remove span from hir::Item.
1 parent 85396f8 commit 042bf08

Some content is hidden

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

67 files changed

+428
-284
lines changed

compiler/rustc_ast_lowering/src/item.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
240240
let hir_id = self.lower_node_id(i.id, i.span);
241241
let attrs = self.lower_attrs(hir_id, &i.attrs);
242242
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind);
243-
Some(hir::Item { def_id: hir_id.expect_owner(), ident, kind, vis, span: i.span })
243+
Some(hir::Item { def_id: hir_id.expect_owner(), ident, kind, vis })
244244
}
245245

246246
fn lower_item_kind(
@@ -558,7 +558,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
558558
ident,
559559
kind,
560560
vis,
561-
span,
562561
});
563562
});
564563
}
@@ -632,7 +631,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
632631
ident,
633632
kind,
634633
vis,
635-
span: use_tree.span,
636634
});
637635
});
638636
}
@@ -849,7 +847,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
849847
};
850848

851849
self.lower_attrs(hir_id, &i.attrs);
852-
hir::TraitItem { def_id: trait_item_def_id, ident: i.ident, generics, kind, span: i.span }
850+
hir::TraitItem { def_id: trait_item_def_id, ident: i.ident, generics, kind }
853851
}
854852

855853
fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef {
@@ -936,7 +934,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
936934
vis: self.lower_visibility(&i.vis, None),
937935
defaultness,
938936
kind,
939-
span: i.span,
940937
}
941938
}
942939

compiler/rustc_ast_lowering/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16221622
ident: Ident::invalid(),
16231623
kind: opaque_ty_item_kind,
16241624
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
1625-
span: opaque_ty_span,
16261625
};
16271626

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

compiler/rustc_codegen_cranelift/src/driver/jit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
7171
crate::constant::codegen_static(&mut cx.constants_cx, def_id);
7272
}
7373
MonoItem::GlobalAsm(item_id) => {
74-
let item = cx.tcx.hir().item(item_id);
75-
tcx.sess.span_fatal(item.span, "Global asm is not supported in JIT mode");
74+
let item_span = cx.tcx.hir().span(item_id.hir_id());
75+
tcx.sess.span_fatal(item_span, "Global asm is not supported in JIT mode");
7676
}
7777
}
7878
}

compiler/rustc_codegen_ssa/src/mono_item.rs

+2-1
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 item_span = cx.tcx().def_span(item.def_id);
39+
span_bug!(item_span, "Mismatch between hir::Item type and MonoItem type")
3940
}
4041
}
4142
MonoItem::Fn(instance) => {

compiler/rustc_hir/src/hir.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,6 @@ pub struct TraitItem<'hir> {
20062006
pub def_id: LocalDefId,
20072007
pub generics: Generics<'hir>,
20082008
pub kind: TraitItemKind<'hir>,
2009-
pub span: Span,
20102009
}
20112010

20122011
impl TraitItem<'_> {
@@ -2068,7 +2067,6 @@ pub struct ImplItem<'hir> {
20682067
pub defaultness: Defaultness,
20692068
pub generics: Generics<'hir>,
20702069
pub kind: ImplItemKind<'hir>,
2071-
pub span: Span,
20722070
}
20732071

20742072
impl ImplItem<'_> {
@@ -2670,7 +2668,6 @@ pub struct Item<'hir> {
26702668
pub def_id: LocalDefId,
26712669
pub kind: ItemKind<'hir>,
26722670
pub vis: Visibility<'hir>,
2673-
pub span: Span,
26742671
}
26752672

26762673
impl Item<'_> {
@@ -3044,8 +3041,8 @@ mod size_asserts {
30443041
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
30453042
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
30463043

3047-
rustc_data_structures::static_assert_size!(super::Item<'static>, 184);
3048-
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);
3049-
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 152);
3044+
rustc_data_structures::static_assert_size!(super::Item<'static>, 176);
3045+
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 120);
3046+
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 144);
30503047
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 136);
30513048
}

compiler/rustc_hir/src/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
959959

960960
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
961961
// N.B., deliberately force a compilation error if/when new fields are added.
962-
let ImplItem { def_id: _, ident, ref vis, ref defaultness, ref generics, ref kind, span: _ } =
962+
let ImplItem { def_id: _, ident, ref vis, ref defaultness, ref generics, ref kind } =
963963
*impl_item;
964964

965965
visitor.visit_ident(ident);

compiler/rustc_hir/src/stable_hash_impls.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,26 @@ 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 generics, ref kind, span } = *self;
142+
let TraitItem { def_id: _, ident, ref generics, ref kind } = *self;
143143

144144
hcx.hash_hir_item_like(|hcx| {
145145
ident.name.hash_stable(hcx, hasher);
146146
generics.hash_stable(hcx, hasher);
147147
kind.hash_stable(hcx, hasher);
148-
span.hash_stable(hcx, hasher);
149148
});
150149
}
151150
}
152151

153152
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
154153
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
155-
let ImplItem { def_id: _, ident, ref vis, defaultness, ref generics, ref kind, span } =
156-
*self;
154+
let ImplItem { def_id: _, ident, ref vis, defaultness, ref generics, ref kind } = *self;
157155

158156
hcx.hash_hir_item_like(|hcx| {
159157
ident.name.hash_stable(hcx, hasher);
160158
vis.hash_stable(hcx, hasher);
161159
defaultness.hash_stable(hcx, hasher);
162160
generics.hash_stable(hcx, hasher);
163161
kind.hash_stable(hcx, hasher);
164-
span.hash_stable(hcx, hasher);
165162
});
166163
}
167164
}
@@ -181,13 +178,12 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItem<'_> {
181178

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

186183
hcx.hash_hir_item_like(|hcx| {
187184
ident.name.hash_stable(hcx, hasher);
188185
kind.hash_stable(hcx, hasher);
189186
vis.hash_stable(hcx, hasher);
190-
span.hash_stable(hcx, hasher);
191187
});
192188
}
193189
}

compiler/rustc_hir_pretty/src/lib.rs

+29-11
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl<'a> State<'a> {
464464

465465
pub fn print_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
466466
self.hardbreak_if_not_bol();
467-
self.maybe_print_comment(item.span.lo());
467+
self.maybe_print_comment(self.span(item.hir_id()).lo());
468468
self.print_outer_attributes(self.attrs(item.hir_id()));
469469
match item.kind {
470470
hir::ForeignItemKind::Fn(ref decl, ref arg_names, ref generics) => {
@@ -572,7 +572,7 @@ impl<'a> State<'a> {
572572
/// Pretty-print an item
573573
pub fn print_item(&mut self, item: &hir::Item<'_>) {
574574
self.hardbreak_if_not_bol();
575-
self.maybe_print_comment(item.span.lo());
575+
self.maybe_print_comment(self.span(item.hir_id()).lo());
576576
let attrs = self.attrs(item.hir_id());
577577
self.print_outer_attributes(attrs);
578578
self.ann.pre(self, AnnNode::Item(item));
@@ -660,7 +660,7 @@ impl<'a> State<'a> {
660660
self.nbsp();
661661
self.bopen();
662662
self.print_mod(_mod, attrs);
663-
self.bclose(item.span);
663+
self.bclose(self.span(item.hir_id()));
664664
}
665665
hir::ItemKind::ForeignMod { abi, items } => {
666666
self.head("extern");
@@ -670,7 +670,7 @@ impl<'a> State<'a> {
670670
for item in items {
671671
self.ann.nested(self, Nested::ForeignItem(item.id));
672672
}
673-
self.bclose(item.span);
673+
self.bclose(self.span(item.hir_id()));
674674
}
675675
hir::ItemKind::GlobalAsm(ref ga) => {
676676
self.head(visibility_qualified(&item.vis, "global asm"));
@@ -699,15 +699,33 @@ impl<'a> State<'a> {
699699
});
700700
}
701701
hir::ItemKind::Enum(ref enum_definition, ref params) => {
702-
self.print_enum_def(enum_definition, params, item.ident.name, item.span, &item.vis);
702+
self.print_enum_def(
703+
enum_definition,
704+
params,
705+
item.ident.name,
706+
self.span(item.hir_id()),
707+
&item.vis,
708+
);
703709
}
704710
hir::ItemKind::Struct(ref struct_def, ref generics) => {
705711
self.head(visibility_qualified(&item.vis, "struct"));
706-
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
712+
self.print_struct(
713+
struct_def,
714+
generics,
715+
item.ident.name,
716+
self.span(item.hir_id()),
717+
true,
718+
);
707719
}
708720
hir::ItemKind::Union(ref struct_def, ref generics) => {
709721
self.head(visibility_qualified(&item.vis, "union"));
710-
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
722+
self.print_struct(
723+
struct_def,
724+
generics,
725+
item.ident.name,
726+
self.span(item.hir_id()),
727+
true,
728+
);
711729
}
712730
hir::ItemKind::Impl(hir::Impl {
713731
unsafety,
@@ -754,7 +772,7 @@ impl<'a> State<'a> {
754772
for impl_item in items {
755773
self.ann.nested(self, Nested::ImplItem(impl_item.id));
756774
}
757-
self.bclose(item.span);
775+
self.bclose(self.span(item.hir_id()));
758776
}
759777
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, trait_items) => {
760778
self.head("");
@@ -781,7 +799,7 @@ impl<'a> State<'a> {
781799
for trait_item in trait_items {
782800
self.ann.nested(self, Nested::TraitItem(trait_item.id));
783801
}
784-
self.bclose(item.span);
802+
self.bclose(self.span(item.hir_id()));
785803
}
786804
hir::ItemKind::TraitAlias(ref generics, ref bounds) => {
787805
self.head("");
@@ -964,7 +982,7 @@ impl<'a> State<'a> {
964982
pub fn print_trait_item(&mut self, ti: &hir::TraitItem<'_>) {
965983
self.ann.pre(self, AnnNode::SubItem(ti.hir_id()));
966984
self.hardbreak_if_not_bol();
967-
self.maybe_print_comment(ti.span.lo());
985+
self.maybe_print_comment(self.span(ti.hir_id()).lo());
968986
self.print_outer_attributes(self.attrs(ti.hir_id()));
969987
match ti.kind {
970988
hir::TraitItemKind::Const(ref ty, default) => {
@@ -1003,7 +1021,7 @@ impl<'a> State<'a> {
10031021
pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) {
10041022
self.ann.pre(self, AnnNode::SubItem(ii.hir_id()));
10051023
self.hardbreak_if_not_bol();
1006-
self.maybe_print_comment(ii.span.lo());
1024+
self.maybe_print_comment(self.span(ii.hir_id()).lo());
10071025
self.print_outer_attributes(self.attrs(ii.hir_id()));
10081026
self.print_defaultness(ii.defaultness);
10091027

compiler/rustc_lint/src/builtin.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
734734
return;
735735
}
736736
let param_env = ty::ParamEnv::empty();
737-
if ty.is_copy_modulo_regions(cx.tcx.at(item.span), param_env) {
737+
let item_span = cx.tcx.hir().span_with_body(item.hir_id());
738+
if ty.is_copy_modulo_regions(cx.tcx.at(item_span), param_env) {
738739
return;
739740
}
740741
if can_type_implement_copy(cx.tcx, param_env, ty).is_ok() {
741-
cx.struct_span_lint(MISSING_COPY_IMPLEMENTATIONS, item.span, |lint| {
742+
cx.struct_span_lint(MISSING_COPY_IMPLEMENTATIONS, item_span, |lint| {
742743
lint.build(
743744
"type could implement `Copy`; consider adding `impl \
744745
Copy`",
@@ -819,7 +820,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
819820
}
820821

821822
if !self.impling_types.as_ref().unwrap().contains(&item.def_id) {
822-
cx.struct_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, |lint| {
823+
let item_span = cx.tcx.hir().span_with_body(item.hir_id());
824+
cx.struct_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item_span, |lint| {
823825
lint.build(&format!(
824826
"type does not implement `{}`; consider adding `#[derive(Debug)]` \
825827
or a manual implementation",
@@ -1103,7 +1105,8 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
11031105
match param.kind {
11041106
GenericParamKind::Lifetime { .. } => {}
11051107
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
1106-
cx.struct_span_lint(NO_MANGLE_GENERIC_ITEMS, it.span, |lint| {
1108+
let it_span = cx.tcx.hir().span_with_body(it.hir_id());
1109+
cx.struct_span_lint(NO_MANGLE_GENERIC_ITEMS, it_span, |lint| {
11071110
lint.build(
11081111
"functions generic over types or consts must be mangled",
11091112
)
@@ -1127,7 +1130,8 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
11271130
if cx.sess().contains_name(attrs, sym::no_mangle) {
11281131
// Const items do not refer to a particular location in memory, and therefore
11291132
// don't have anything to attach a symbol to
1130-
cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it.span, |lint| {
1133+
let it_span = cx.tcx.hir().span_with_body(it.hir_id());
1134+
cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it_span, |lint| {
11311135
let msg = "const items should never be `#[no_mangle]`";
11321136
let mut err = lint.build(msg);
11331137

@@ -1136,11 +1140,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
11361140
.tcx
11371141
.sess
11381142
.source_map()
1139-
.span_to_snippet(it.span)
1143+
.span_to_snippet(it_span)
11401144
.map(|snippet| snippet.find("const").unwrap_or(0))
11411145
.unwrap_or(0) as u32;
11421146
// `const` is 5 chars
1143-
let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5));
1147+
let const_span = it_span.with_hi(BytePos(it_span.lo().0 + start + 5));
11441148
err.span_suggestion(
11451149
const_span,
11461150
"try a static value",

compiler/rustc_metadata/src/rmeta/encoder.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1058,11 +1058,14 @@ impl EncodeContext<'a, 'tcx> {
10581058
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
10591059
let ast_item = tcx.hir().expect_trait_item(hir_id);
10601060
let trait_item = tcx.associated_item(def_id);
1061+
let ast_item_span = tcx.hir().span_with_body(hir_id);
10611062

10621063
let container = match trait_item.defaultness {
10631064
hir::Defaultness::Default { has_value: true } => AssocContainer::TraitWithDefault,
10641065
hir::Defaultness::Default { has_value: false } => AssocContainer::TraitRequired,
1065-
hir::Defaultness::Final => span_bug!(ast_item.span, "traits cannot have final items"),
1066+
hir::Defaultness::Final => {
1067+
span_bug!(ast_item_span, "traits cannot have final items")
1068+
}
10661069
};
10671070

10681071
match trait_item.kind {
@@ -1131,19 +1134,20 @@ impl EncodeContext<'a, 'tcx> {
11311134
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
11321135
let ast_item = self.tcx.hir().expect_impl_item(hir_id);
11331136
let impl_item = self.tcx.associated_item(def_id);
1137+
let ast_item_span = tcx.hir().span_with_body(hir_id);
11341138

11351139
let container = match impl_item.defaultness {
11361140
hir::Defaultness::Default { has_value: true } => AssocContainer::ImplDefault,
11371141
hir::Defaultness::Final => AssocContainer::ImplFinal,
11381142
hir::Defaultness::Default { has_value: false } => {
1139-
span_bug!(ast_item.span, "impl items always have values (currently)")
1143+
span_bug!(ast_item_span, "impl items always have values (currently)")
11401144
}
11411145
};
11421146

11431147
match impl_item.kind {
11441148
ty::AssocKind::Const => {
11451149
if let hir::ImplItemKind::Const(_, body_id) = ast_item.kind {
1146-
let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id);
1150+
let qualifs = self.tcx.at(ast_item_span).mir_const_qualif(def_id);
11471151

11481152
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
11491153
container,
@@ -1301,7 +1305,8 @@ impl EncodeContext<'a, 'tcx> {
13011305
hir::ItemKind::Static(_, hir::Mutability::Mut, _) => EntryKind::MutStatic,
13021306
hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic,
13031307
hir::ItemKind::Const(_, body_id) => {
1304-
let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
1308+
let item_span = tcx.hir().span_with_body(item.hir_id());
1309+
let qualifs = self.tcx.at(item_span).mir_const_qualif(def_id);
13051310
EntryKind::Const(qualifs, self.encode_rendered_const_for_body(body_id))
13061311
}
13071312
hir::ItemKind::Fn(ref sig, .., body) => {
@@ -1378,7 +1383,8 @@ impl EncodeContext<'a, 'tcx> {
13781383
// "unsized info", else just store None
13791384
let coerce_unsized_info = trait_ref.and_then(|t| {
13801385
if Some(t.def_id) == self.tcx.lang_items().coerce_unsized_trait() {
1381-
Some(self.tcx.at(item.span).coerce_unsized_info(def_id))
1386+
let item_span = tcx.hir().span_with_body(item.hir_id());
1387+
Some(self.tcx.at(item_span).coerce_unsized_info(def_id))
13821388
} else {
13831389
None
13841390
}

0 commit comments

Comments
 (0)