1
Fork 0

Use a more appropriate span for ; suggestion

Fix #83892.
This commit is contained in:
Esteban Küber 2021-04-06 19:23:22 -07:00
parent 16143d1067
commit 650877de45
6 changed files with 42 additions and 9 deletions

View file

@ -1440,9 +1440,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
// as prior return coercions would not be relevant (#57664).
let parent_id = fcx.tcx.hir().get_parent_node(id);
let fn_decl = if let Some((expr, blk_id)) = expression {
pointing_at_return_type = fcx.suggest_mismatched_types_on_tail(
&mut err, expr, expected, found, cause.span, blk_id,
);
pointing_at_return_type =
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
let parent = fcx.tcx.hir().get(parent_id);
if let (Some(cond_expr), true, false) = (
fcx.tcx.hir().get_if_cause(expr.hir_id),

View file

@ -603,7 +603,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&cause,
&mut |mut err| {
self.suggest_mismatched_types_on_tail(
&mut err, expr, ty, e_ty, cause.span, target_id,
&mut err, expr, ty, e_ty, target_id,
);
if let Some(val) = ty_kind_suggestion(ty) {
let label = destination

View file

@ -41,15 +41,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &'tcx hir::Expr<'tcx>,
expected: Ty<'tcx>,
found: Ty<'tcx>,
cause_span: Span,
blk_id: hir::HirId,
) -> bool {
let expr = expr.peel_drop_temps();
// If the expression is from an external macro, then do not suggest
// adding a semicolon, because there's nowhere to put it.
// See issue #81943.
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, cause_span) {
self.suggest_missing_semicolon(err, expr, expected, cause_span);
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, expr.span) {
self.suggest_missing_semicolon(err, expr, expected);
}
let mut pointing_at_return_type = false;
if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
@ -388,7 +387,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err: &mut DiagnosticBuilder<'_>,
expression: &'tcx hir::Expr<'tcx>,
expected: Ty<'tcx>,
cause_span: Span,
) {
if expected.is_unit() {
// `BlockTailExpression` only relevant if the tail expr would be
@ -403,7 +401,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if expression.can_have_side_effects() =>
{
err.span_suggestion(
cause_span.shrink_to_hi(),
expression.span.shrink_to_hi(),
"consider using a semicolon here",
";".to_string(),
Applicability::MachineApplicable,