Skip to content

Commit d632f42

Browse files
committed
Remove span from hir::ForeignItem.
1 parent 042bf08 commit d632f42

File tree

9 files changed

+36
-21
lines changed

9 files changed

+36
-21
lines changed

compiler/rustc_ast_lowering/src/item.rs

-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
728728
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
729729
},
730730
vis: self.lower_visibility(&i.vis, None),
731-
span: i.span,
732731
}
733732
}
734733

compiler/rustc_hir/src/hir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2880,7 +2880,6 @@ pub struct ForeignItem<'hir> {
28802880
pub ident: Ident,
28812881
pub kind: ForeignItemKind<'hir>,
28822882
pub def_id: LocalDefId,
2883-
pub span: Span,
28842883
pub vis: Visibility<'hir>,
28852884
}
28862885

@@ -3044,5 +3043,5 @@ mod size_asserts {
30443043
rustc_data_structures::static_assert_size!(super::Item<'static>, 176);
30453044
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 120);
30463045
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 144);
3047-
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 136);
3046+
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 128);
30483047
}

compiler/rustc_hir/src/stable_hash_impls.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,11 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
165165

166166
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItem<'_> {
167167
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
168-
let ForeignItem { def_id: _, ident, ref kind, span, ref vis } = *self;
168+
let ForeignItem { def_id: _, ident, ref kind, ref vis } = *self;
169169

170170
hcx.hash_hir_item_like(|hcx| {
171171
ident.name.hash_stable(hcx, hasher);
172172
kind.hash_stable(hcx, hasher);
173-
span.hash_stable(hcx, hasher);
174173
vis.hash_stable(hcx, hasher);
175174
});
176175
}

compiler/rustc_lint/src/builtin.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -2927,11 +2927,13 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
29272927

29282928
// We want to ensure that we use spans for both decls that include where the
29292929
// name was defined, whether that was from the link_name attribute or not.
2930-
let get_relevant_span =
2931-
|fi: &hir::ForeignItem<'_>| match Self::name_of_extern_decl(tcx, fi) {
2932-
SymbolName::Normal(_) => fi.span,
2933-
SymbolName::Link(_, annot_span) => fi.span.to(annot_span),
2934-
};
2930+
let get_relevant_span = |fi: &hir::ForeignItem<'_>| {
2931+
let fi_span = tcx.hir().span(fi.hir_id());
2932+
match Self::name_of_extern_decl(tcx, fi) {
2933+
SymbolName::Normal(_) => fi_span,
2934+
SymbolName::Link(_, annot_span) => fi_span.to(annot_span),
2935+
}
2936+
};
29352937
// Finally, emit the diagnostic.
29362938
tcx.struct_span_lint_hir(
29372939
CLASHING_EXTERN_DECLARATIONS,

compiler/rustc_passes/src/dead.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,12 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
646646

647647
fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem<'tcx>) {
648648
if self.should_warn_about_foreign_item(fi) {
649-
self.warn_dead_code(fi.hir_id(), fi.span, fi.ident.name, "used");
649+
self.warn_dead_code(
650+
fi.hir_id(),
651+
self.tcx.hir().span(fi.hir_id()),
652+
fi.ident.name,
653+
"used",
654+
);
650655
}
651656
intravisit::walk_foreign_item(self, fi);
652657
}

compiler/rustc_passes/src/weak_lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
9999
let check_name = |attr, sym| self.tcx.sess.check_name(attr, sym);
100100
let attrs = self.tcx.hir().attrs(i.hir_id());
101101
if let Some((lang_item, _)) = lang_items::extract(check_name, attrs) {
102-
self.register(lang_item, i.span);
102+
self.register(lang_item, self.tcx.hir().span(i.hir_id()));
103103
}
104104
intravisit::walk_foreign_item(self, i)
105105
}

compiler/rustc_typeck/src/check/check.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,12 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
835835
let item = tcx.hir().foreign_item(item.id);
836836
match item.kind {
837837
hir::ForeignItemKind::Fn(ref fn_decl, _, _) => {
838-
require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span);
838+
require_c_abi_if_c_variadic(
839+
tcx,
840+
fn_decl,
841+
abi,
842+
tcx.hir().span(item.hir_id()),
843+
);
839844
}
840845
hir::ForeignItemKind::Static(..) => {
841846
check_static_inhabited(tcx, item.def_id);

compiler/rustc_typeck/src/check/intrinsic.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ fn equate_intrinsic_type<'tcx>(
2323
n_tps: usize,
2424
sig: ty::PolyFnSig<'tcx>,
2525
) {
26+
let it_span = tcx.hir().span(it.hir_id());
2627
match it.kind {
2728
hir::ForeignItemKind::Fn(..) => {}
2829
_ => {
29-
struct_span_err!(tcx.sess, it.span, E0622, "intrinsic must be a function")
30-
.span_label(it.span, "expected a function")
30+
struct_span_err!(tcx.sess, it_span, E0622, "intrinsic must be a function")
31+
.span_label(it_span, "expected a function")
3132
.emit();
3233
return;
3334
}
@@ -49,7 +50,7 @@ fn equate_intrinsic_type<'tcx>(
4950
}
5051

5152
let fty = tcx.mk_fn_ptr(sig);
52-
let cause = ObligationCause::new(it.span, it.hir_id(), ObligationCauseCode::IntrinsicType);
53+
let cause = ObligationCause::new(it_span, it.hir_id(), ObligationCauseCode::IntrinsicType);
5354
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.def_id)), fty);
5455
}
5556

@@ -130,7 +131,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
130131
| "umin" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], param(0)),
131132
"fence" | "singlethreadfence" => (0, Vec::new(), tcx.mk_unit()),
132133
op => {
133-
tcx.sess.emit_err(UnrecognizedAtomicOperation { span: it.span, op });
134+
let it_span = tcx.hir().span(it.hir_id());
135+
tcx.sess.emit_err(UnrecognizedAtomicOperation { span: it_span, op });
134136
return;
135137
}
136138
};
@@ -359,7 +361,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
359361
sym::nontemporal_store => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()),
360362

361363
other => {
362-
tcx.sess.emit_err(UnrecognizedIntrinsicFunction { span: it.span, name: other });
364+
let it_span = tcx.hir().span(it.hir_id());
365+
tcx.sess.emit_err(UnrecognizedIntrinsicFunction { span: it_span, name: other });
363366
return;
364367
}
365368
};
@@ -440,14 +443,16 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
440443
(2, params, param(1))
441444
}
442445
Err(_) => {
443-
tcx.sess.emit_err(SimdShuffleMissingLength { span: it.span, name });
446+
let it_span = tcx.hir().span(it.hir_id());
447+
tcx.sess.emit_err(SimdShuffleMissingLength { span: it_span, name });
444448
return;
445449
}
446450
}
447451
}
448452
_ => {
449453
let msg = format!("unrecognized platform-specific intrinsic function: `{}`", name);
450-
tcx.sess.struct_span_err(it.span, &msg).emit();
454+
let it_span = tcx.hir().span(it.hir_id());
455+
tcx.sess.struct_span_err(it_span, &msg).emit();
451456
return;
452457
}
453458
};

src/librustdoc/doctest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,8 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
10751075
}
10761076

10771077
fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem<'_>) {
1078-
self.visit_testable(item.ident.to_string(), item.hir_id(), item.span, |this| {
1078+
let item_span = self.tcx.hir().span(item.hir_id());
1079+
self.visit_testable(item.ident.to_string(), item.hir_id(), item_span, |this| {
10791080
intravisit::walk_foreign_item(this, item);
10801081
});
10811082
}

0 commit comments

Comments
 (0)