Skip to content

Commit 0d9d1e0

Browse files
committed
Remove Span from hir::Ty.
1 parent d632f42 commit 0d9d1e0

Some content is hidden

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

81 files changed

+419
-279
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
655655

656656
// Resume argument type. We let the compiler infer this to simplify the lowering. It is
657657
// fully constrained by `future::from_generator`.
658-
let input_ty = hir::Ty { hir_id: self.next_id(span), kind: hir::TyKind::Infer, span };
658+
let input_ty = hir::Ty { hir_id: self.next_id(span), kind: hir::TyKind::Infer };
659659

660660
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
661661
let decl = self.arena.alloc(hir::FnDecl {

compiler/rustc_ast_lowering/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13461346
}
13471347

13481348
fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
1349-
hir::Ty { hir_id: self.next_id(span), kind, span }
1349+
hir::Ty { hir_id: self.next_id(span), kind }
13501350
}
13511351

13521352
fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
@@ -1543,7 +1543,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15431543
}
15441544
};
15451545

1546-
hir::Ty { kind, span: t.span, hir_id: self.lower_node_id(t.id, t.span) }
1546+
hir::Ty { kind, hir_id: self.lower_node_id(t.id, t.span) }
15471547
}
15481548

15491549
fn lower_opaque_impl_trait(
@@ -2706,7 +2706,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
27062706
_ => hir::TyKind::Path(qpath),
27072707
};
27082708

2709-
hir::Ty { hir_id, kind, span }
2709+
hir::Ty { hir_id, kind }
27102710
}
27112711

27122712
/// Invoked to create the lifetime argument for a type `&T`

compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
409409
FnRetTy::Default(_) => this.arena.alloc(this.ty_tup(*span, &[])),
410410
};
411411
let args = smallvec![GenericArg::Type(this.ty_tup(*inputs_span, inputs))];
412-
let binding = this.output_ty_binding(output_ty.span, output_ty);
412+
let binding = this.output_ty_binding(this.spans[output_ty.hir_id], output_ty);
413413
(
414414
GenericArgsCtor { args, bindings: arena_vec![this; binding], parenthesized: true },
415415
false,

compiler/rustc_hir/src/hir.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1793,10 +1793,10 @@ impl<'hir> QPath<'hir> {
17931793

17941794
/// Returns the span of the qself of this `QPath`. For example, `()` in
17951795
/// `<() as Trait>::method`.
1796-
pub fn qself_span(&self) -> Span {
1796+
pub fn qself_span(&self, get_span: impl Fn(HirId) -> Span) -> Span {
17971797
match *self {
17981798
QPath::Resolved(_, path) => path.span,
1799-
QPath::TypeRelative(qself, _) => qself.span,
1799+
QPath::TypeRelative(qself, _) => get_span(qself.hir_id),
18001800
QPath::LangItem(_, span) => span,
18011801
}
18021802
}
@@ -2151,7 +2151,6 @@ impl TypeBinding<'_> {
21512151
pub struct Ty<'hir> {
21522152
pub hir_id: HirId,
21532153
pub kind: TyKind<'hir>,
2154-
pub span: Span,
21552154
}
21562155

21572156
/// Not represented directly in the AST; referred to by name through a `ty_path`.
@@ -2476,10 +2475,10 @@ pub enum FnRetTy<'hir> {
24762475
}
24772476

24782477
impl FnRetTy<'_> {
2479-
pub fn span(&self) -> Span {
2478+
pub fn span(&self, get_span: impl Fn(HirId) -> Span) -> Span {
24802479
match *self {
24812480
Self::DefaultReturn(span) => span,
2482-
Self::Return(ref ty) => ty.span,
2481+
Self::Return(ref ty) => get_span(ty.hir_id),
24832482
}
24842483
}
24852484
}
@@ -3038,7 +3037,7 @@ mod size_asserts {
30383037
rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
30393038
rustc_data_structures::static_assert_size!(super::Pat<'static>, 80);
30403039
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
3041-
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
3040+
rustc_data_structures::static_assert_size!(super::Ty<'static>, 64);
30423041

30433042
rustc_data_structures::static_assert_size!(super::Item<'static>, 176);
30443043
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 120);

compiler/rustc_hir_pretty/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl<'a> State<'a> {
381381
}
382382

383383
pub fn print_type(&mut self, ty: &hir::Ty<'_>) {
384-
self.maybe_print_comment(ty.span.lo());
384+
self.maybe_print_comment(self.span(ty.hir_id).lo());
385385
self.ibox(0);
386386
match ty.kind {
387387
hir::TyKind::Slice(ref ty) => {
@@ -2205,7 +2205,7 @@ impl<'a> State<'a> {
22052205
match decl.output {
22062206
hir::FnRetTy::Return(ref ty) => {
22072207
self.print_type(&ty);
2208-
self.maybe_print_comment(ty.span.lo())
2208+
self.maybe_print_comment(self.span(ty.hir_id).lo())
22092209
}
22102210
hir::FnRetTy::DefaultReturn(..) => unreachable!(),
22112211
}
@@ -2397,7 +2397,7 @@ impl<'a> State<'a> {
23972397
self.end();
23982398

23992399
if let hir::FnRetTy::Return(ref output) = decl.output {
2400-
self.maybe_print_comment(output.span.lo())
2400+
self.maybe_print_comment(self.span(output.hir_id).lo())
24012401
}
24022402
}
24032403

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn msg_span_from_early_bound_and_free_regions(
181181
ty::ReFree(ref fr) => match fr.bound_region {
182182
ty::BrAnon(idx) => {
183183
if let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region) {
184-
("the anonymous lifetime defined on".to_string(), ty.span)
184+
("the anonymous lifetime defined on".to_string(), tcx.hir().span(ty.hir_id))
185185
} else {
186186
(
187187
format!("the anonymous lifetime #{} defined on", idx + 1),

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl UseDiagnostic<'_> {
214214

215215
/// Suggest giving an appropriate return type to a closure expression.
216216
fn closure_return_type_suggestion(
217+
tcx: TyCtxt<'_>,
217218
err: &mut DiagnosticBuilder<'_>,
218219
output: &FnRetTy<'_>,
219220
body: &Body<'_>,
@@ -224,9 +225,11 @@ fn closure_return_type_suggestion(
224225
_ => ("", ""),
225226
};
226227
let suggestion = match body.value.kind {
227-
ExprKind::Block(..) => vec![(output.span(), format!("{}{}{}", arrow, ret, post))],
228+
ExprKind::Block(..) => {
229+
vec![(output.span(|id| tcx.hir().span(id)), format!("{}{}{}", arrow, ret, post))]
230+
}
228231
_ => vec![
229-
(output.span(), format!("{}{}{}{{ ", arrow, ret, post)),
232+
(output.span(|id| tcx.hir().span(id)), format!("{}{}{}{{ ", arrow, ret, post)),
230233
(body.value.span.shrink_to_hi(), " }".to_string()),
231234
],
232235
};
@@ -554,6 +557,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
554557

555558
if let Some((decl, body_id)) = closure_decl_and_body_id {
556559
closure_return_type_suggestion(
560+
self.tcx,
557561
&mut err,
558562
&decl.output,
559563
self.tcx.hir().body(body_id),

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
103103
None => String::new(),
104104
};
105105

106+
let ty_sub_span = self.tcx().hir().span(ty_sub.hir_id);
107+
let ty_sup_span = self.tcx().hir().span(ty_sup.hir_id);
106108
let (span_1, span_2, main_label, span_label, future_return_type) =
107109
match (sup_is_ret_type, sub_is_ret_type) {
108110
(None, None) => {
@@ -117,7 +119,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
117119
format!("...but data{} flows{} here", span_label_var1, span_label_var2),
118120
)
119121
};
120-
(ty_sup.span, ty_sub.span, main_label_1, span_label_1, None)
122+
(ty_sup_span, ty_sub_span, main_label_1, span_label_1, None)
121123
}
122124

123125
(Some(ret_span), _) => {
@@ -129,7 +131,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
129131
};
130132

131133
(
132-
ty_sub.span,
134+
ty_sub_span,
133135
ret_span,
134136
format!(
135137
"this parameter and the {} are declared with different lifetimes...",
@@ -148,7 +150,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
148150
};
149151

150152
(
151-
ty_sup.span,
153+
ty_sup_span,
152154
ret_span,
153155
format!(
154156
"this parameter and the {} are declared with different lifetimes...",
@@ -167,11 +169,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
167169
e.span_label(span, span_label);
168170

169171
if let Some(t) = future_return_type {
172+
let t_span = self.tcx().hir().span(t.hir_id);
170173
let snip = self
171174
.tcx()
172175
.sess
173176
.source_map()
174-
.span_to_snippet(t.span)
177+
.span_to_snippet(t_span)
175178
.ok()
176179
.and_then(|s| match (&t.kind, s.as_str()) {
177180
(rustc_hir::TyKind::Tup(&[]), "") => Some("()".to_string()),
@@ -181,7 +184,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
181184
.unwrap_or("{unnamed_type}".to_string());
182185

183186
e.span_label(
184-
t.span,
187+
t_span,
185188
&format!("this `async fn` implicitly returns an `impl Future<Output = {}>`", snip),
186189
);
187190
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
8686

8787
debug!("try_report_named_anon_conflict: ret ty {:?}", ty);
8888
if sub == &ty::ReStatic
89-
&& v.0.into_iter().any(|t| t.span.desugaring_kind().is_none())
89+
&& v.0
90+
.into_iter()
91+
.any(|t| self.tcx().hir().span(t.hir_id).desugaring_kind().is_none())
9092
{
9193
// If the failure is due to a `'static` requirement coming from a `dyn` or
9294
// `impl` Trait that *isn't* caused by `async fn` desugaring, handle this case

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
225225
let add_static_bound = "alternatively, add an explicit `'static` bound to this reference";
226226
let plus_lt = format!(" + {}", lifetime_name);
227227
for fn_return in fn_returns {
228-
if fn_return.span.desugaring_kind().is_some() {
228+
let fn_return_span = self.tcx().hir().span(fn_return.hir_id);
229+
if fn_return_span.desugaring_kind().is_some() {
229230
// Skip `async` desugaring `impl Future`.
230231
continue;
231232
}
@@ -280,7 +281,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
280281
{
281282
} else {
282283
err.span_suggestion_verbose(
283-
fn_return.span.shrink_to_hi(),
284+
fn_return_span.shrink_to_hi(),
284285
&format!(
285286
"{declare} `impl Trait` {captures}, {explicit}",
286287
declare = declare,
@@ -295,7 +296,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
295296
TyKind::TraitObject(_, lt) => match lt.name {
296297
LifetimeName::ImplicitObjectLifetimeDefault => {
297298
err.span_suggestion_verbose(
298-
fn_return.span.shrink_to_hi(),
299+
fn_return_span.shrink_to_hi(),
299300
&format!(
300301
"{declare} trait object {captures}, {explicit}",
301302
declare = declare,

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
154154
let late_bound_regions =
155155
self.tcx().collect_referenced_late_bound_regions(&sig.output());
156156
if late_bound_regions.iter().any(|r| *r == br) {
157-
return Some(decl.output.span());
157+
return Some(decl.output.span(|id| self.tcx().hir().span(id)));
158158
}
159159
}
160160
None

compiler/rustc_lint/src/internal.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
119119
.emit();
120120
})
121121
} else {
122-
if ty.span.from_expansion() {
122+
let ty_span = cx.tcx.hir().span(ty.hir_id);
123+
if ty_span.from_expansion() {
123124
return;
124125
}
125126
if let Some(t) = is_ty_or_ty_ctxt(cx, ty) {
@@ -148,10 +149,11 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
148149
}
149150
}
150151
if let Some(t) = is_ty_or_ty_ctxt(cx, &inner_ty) {
151-
cx.struct_span_lint(TY_PASS_BY_REFERENCE, ty.span, |lint| {
152+
let ty_span = cx.tcx.hir().span(ty.hir_id);
153+
cx.struct_span_lint(TY_PASS_BY_REFERENCE, ty_span, |lint| {
152154
lint.build(&format!("passing `{}` by reference", t))
153155
.span_suggestion(
154-
ty.span,
156+
ty_span,
155157
"try passing by value",
156158
t,
157159
// Changing type of function argument

compiler/rustc_lint/src/types.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1258,12 +1258,14 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
12581258
let sig = self.cx.tcx.erase_late_bound_regions(sig);
12591259

12601260
for (input_ty, input_hir) in sig.inputs().iter().zip(decl.inputs) {
1261-
self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty, false, false);
1261+
let input_span = self.cx.tcx.hir().span(input_hir.hir_id);
1262+
self.check_type_for_ffi_and_report_errors(input_span, input_ty, false, false);
12621263
}
12631264

12641265
if let hir::FnRetTy::Return(ref ret_hir) = decl.output {
12651266
let ret_ty = sig.output();
1266-
self.check_type_for_ffi_and_report_errors(ret_hir.span, ret_ty, false, true);
1267+
let ret_span = self.cx.tcx.hir().span(ret_hir.hir_id);
1268+
self.check_type_for_ffi_and_report_errors(ret_span, ret_ty, false, true);
12671269
}
12681270
}
12691271

@@ -1292,7 +1294,8 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDeclarations {
12921294
vis.check_foreign_fn(it.hir_id(), decl);
12931295
}
12941296
hir::ForeignItemKind::Static(ref ty, _) => {
1295-
vis.check_foreign_static(it.hir_id(), ty.span);
1297+
let ty_span = cx.tcx.hir().span(ty.hir_id);
1298+
vis.check_foreign_static(it.hir_id(), ty_span);
12961299
}
12971300
hir::ForeignItemKind::Type => (),
12981301
}

compiler/rustc_middle/src/ich/impls_hir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
7575

7676
fn hash_hir_ty(&mut self, ty: &hir::Ty<'_>, hasher: &mut StableHasher) {
7777
self.while_hashing_hir_bodies(true, |hcx| {
78-
let hir::Ty { hir_id: _, ref kind, ref span } = *ty;
78+
let hir::Ty { hir_id: _, ref kind } = *ty;
7979

8080
kind.hash_stable(hcx, hasher);
81-
span.hash_stable(hcx, hasher);
8281
})
8382
}
8483

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ impl<'tcx> TyCtxt<'tcx> {
15001500
let output = self.erase_late_bound_regions(sig.output());
15011501
if output.is_impl_trait() {
15021502
let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap();
1503-
Some((output, fn_decl.output.span()))
1503+
Some((output, fn_decl.output.span(|id| self.hir().span(id))))
15041504
} else {
15051505
None
15061506
}

compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ impl<'tcx> ty::TyS<'tcx> {
876876
.map(|id| tcx.hir().local_def_id_to_hir_id(id))
877877
.and_then(|id| tcx.hir().find(id))
878878
{
879-
Some(hir::Node::Field(field)) => field.ty.span,
879+
Some(hir::Node::Field(field)) => tcx.hir().span(field.ty.hir_id),
880880
_ => sp,
881881
};
882882
match is_type_structurally_recursive(

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20242024
// We use a mix of the HIR and the Ty types to get information
20252025
// as the HIR doesn't have full types for closure arguments.
20262026
let return_ty = sig.output().skip_binder();
2027-
let mut return_span = fn_decl.output.span();
2027+
let mut return_span = fn_decl.output.span(|id| self.infcx.tcx.hir().span(id));
20282028
if let hir::FnRetTy::Return(ty) = &fn_decl.output {
20292029
if let hir::TyKind::Rptr(lifetime, _) = ty.kind {
20302030
return_span = lifetime.span;
@@ -2041,7 +2041,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20412041
// This is case 2 from above but only for closures, return type is anonymous
20422042
// reference so we select
20432043
// the first argument.
2044-
let argument_span = fn_decl.inputs.first()?.span;
2044+
let argument_span = self.infcx.tcx.hir().span(fn_decl.inputs.first()?.hir_id);
20452045
let argument_ty = sig.inputs().skip_binder().first()?;
20462046

20472047
// Closure arguments are wrapped in a tuple, so we need to get the first
@@ -2061,10 +2061,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20612061
ty::Ref(_, _, _) => {
20622062
// This is also case 2 from above but for functions, return type is still an
20632063
// anonymous reference so we select the first argument.
2064-
let argument_span = fn_decl.inputs.first()?.span;
2064+
let argument_span = self.infcx.tcx.hir().span(fn_decl.inputs.first()?.hir_id);
20652065
let argument_ty = sig.inputs().skip_binder().first()?;
20662066

2067-
let return_span = fn_decl.output.span();
2067+
let return_span = fn_decl.output.span(|id| self.infcx.tcx.hir().span(id));
20682068
let return_ty = sig.output().skip_binder();
20692069

20702070
// We expect the first argument to be a reference.

0 commit comments

Comments
 (0)