Skip to content

Commit 0a605d3

Browse files
No more ret_type_span
1 parent 98e1f04 commit 0a605d3

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

compiler/rustc_typeck/src/check/_match.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
137137
Some(&arm.body),
138138
arm_ty,
139139
Some(&mut |err| {
140-
let Some(ret) = self.ret_type_span else {
141-
return;
142-
};
140+
let Some(ret) = self
141+
.tcx
142+
.hir()
143+
.find_by_def_id(self.body_id.owner)
144+
.and_then(|owner| owner.fn_decl())
145+
.map(|decl| decl.output.span())
146+
else { return; };
143147
let Expectation::IsLast(stmt) = orig_expected else {
144148
return
145149
};
@@ -517,9 +521,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
517521
}
518522
}
519523
}
520-
// If all the obligations hold (or there are no obligations) the tail expression
521-
// we can suggest to return a boxed trait object instead of an opaque type.
522-
if suggest_box { self.ret_type_span } else { None }
524+
if suggest_box {
525+
self.tcx
526+
.hir()
527+
.find_by_def_id(self.body_id.owner)
528+
.and_then(|owner| owner.fn_decl())
529+
.map(|decl| decl.output.span())
530+
} else {
531+
None
532+
}
523533
}
524534
_ => None,
525535
}

compiler/rustc_typeck/src/check/check.rs

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ pub(super) fn check_fn<'a, 'tcx>(
106106
fcx.return_type_has_opaque = ret_ty != declared_ret_ty;
107107

108108
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
109-
fcx.ret_type_span = Some(decl.output.span());
110109

111110
let span = body.value.span;
112111

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ pub struct FnCtxt<'a, 'tcx> {
6868
/// any).
6969
pub(super) ret_coercion: Option<RefCell<DynamicCoerceMany<'tcx>>>,
7070

71-
pub(super) ret_type_span: Option<Span>,
72-
7371
/// Used exclusively to reduce cost of advanced evaluation used for
7472
/// more helpful diagnostics.
7573
pub(super) in_tail_expr: bool,
@@ -142,7 +140,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
142140
param_env,
143141
err_count_on_creation: inh.tcx.sess.err_count(),
144142
ret_coercion: None,
145-
ret_type_span: None,
146143
in_tail_expr: false,
147144
ret_coercion_span: Cell::new(None),
148145
resume_yield_tys: None,

0 commit comments

Comments
 (0)