No more ret_type_span

This commit is contained in:
Michael Goulet 2022-09-09 03:10:06 +00:00
parent 98e1f041b6
commit 0a605d33cd
3 changed files with 16 additions and 10 deletions

View File

@ -137,9 +137,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(&arm.body), Some(&arm.body),
arm_ty, arm_ty,
Some(&mut |err| { Some(&mut |err| {
let Some(ret) = self.ret_type_span else { let Some(ret) = self
return; .tcx
}; .hir()
.find_by_def_id(self.body_id.owner)
.and_then(|owner| owner.fn_decl())
.map(|decl| decl.output.span())
else { return; };
let Expectation::IsLast(stmt) = orig_expected else { let Expectation::IsLast(stmt) = orig_expected else {
return return
}; };
@ -517,9 +521,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
} }
// If all the obligations hold (or there are no obligations) the tail expression if suggest_box {
// we can suggest to return a boxed trait object instead of an opaque type. self.tcx
if suggest_box { self.ret_type_span } else { None } .hir()
.find_by_def_id(self.body_id.owner)
.and_then(|owner| owner.fn_decl())
.map(|decl| decl.output.span())
} else {
None
}
} }
_ => None, _ => None,
} }

View File

@ -106,7 +106,6 @@ pub(super) fn check_fn<'a, 'tcx>(
fcx.return_type_has_opaque = ret_ty != declared_ret_ty; fcx.return_type_has_opaque = ret_ty != declared_ret_ty;
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty))); fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
fcx.ret_type_span = Some(decl.output.span());
let span = body.value.span; let span = body.value.span;

View File

@ -68,8 +68,6 @@ pub struct FnCtxt<'a, 'tcx> {
/// any). /// any).
pub(super) ret_coercion: Option<RefCell<DynamicCoerceMany<'tcx>>>, pub(super) ret_coercion: Option<RefCell<DynamicCoerceMany<'tcx>>>,
pub(super) ret_type_span: Option<Span>,
/// Used exclusively to reduce cost of advanced evaluation used for /// Used exclusively to reduce cost of advanced evaluation used for
/// more helpful diagnostics. /// more helpful diagnostics.
pub(super) in_tail_expr: bool, pub(super) in_tail_expr: bool,
@ -142,7 +140,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
param_env, param_env,
err_count_on_creation: inh.tcx.sess.err_count(), err_count_on_creation: inh.tcx.sess.err_count(),
ret_coercion: None, ret_coercion: None,
ret_type_span: None,
in_tail_expr: false, in_tail_expr: false,
ret_coercion_span: Cell::new(None), ret_coercion_span: Cell::new(None),
resume_yield_tys: None, resume_yield_tys: None,