Skip to content

Commit 0d9d1e0

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

File tree

81 files changed

+419
-279
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 8 additions & 5 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 4 additions & 3 deletions
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,

0 commit comments

Comments
 (0)