Tweak output

This commit is contained in:
Esteban Küber 2023-01-06 02:49:15 +00:00
parent 1fa6ada9dd
commit 031e085450
4 changed files with 44 additions and 66 deletions

View file

@ -224,14 +224,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut ret_span: MultiSpan = semi_span.into();
ret_span.push_span_label(
expr.span,
"this could be implicitly returned but it is a statement, not a \
tail expression",
"this could be implicitly returned but it is a statement, not a tail expression",
);
ret_span.push_span_label(ret, "the `match` arms can conform to this return type");
ret_span.push_span_label(
semi_span,
"the `match` is a statement because of this semicolon, consider \
removing it",
"the `match` is a statement because of this semicolon, consider removing it",
);
diag.span_note(ret_span, "you might have meant to return the `match` expression");
diag.tool_only_span_suggestion(

View file

@ -1699,20 +1699,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return;
}
let [.., stmt] = block.stmts else {
err.span_help(block.span, "this empty block is missing a tail expression");
err.span_label(block.span, "this empty block is missing a tail expression");
return;
};
let hir::StmtKind::Semi(tail_expr) = stmt.kind else { return; };
let Some(ty) = self.node_ty_opt(tail_expr.hir_id) else { return; };
if self.can_eq(self.param_env, expected_ty, ty).is_ok() {
err.span_suggestion_verbose(
err.span_suggestion_short(
stmt.span.with_lo(tail_expr.span.hi()),
"remove this semicolon",
"",
Applicability::MachineApplicable,
);
} else {
err.span_help(block.span, "this block is missing a tail expression");
err.span_label(block.span, "this block is missing a tail expression");
}
}
}

View file

@ -1077,12 +1077,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
return;
}
let [.., stmt] = block.stmts else {
err.span_help(block.span, "this empty block is missing a tail expression");
err.span_label(block.span, "this empty block is missing a tail expression");
return;
};
let hir::StmtKind::Semi(tail_expr) = stmt.kind else { return; };
let Some(ty) = typeck.expr_ty_opt(tail_expr) else {
err.span_help(block.span, "this block is missing a tail expression");
err.span_label(block.span, "this block is missing a tail expression");
return;
};
let ty = self.resolve_numeric_literals_with_default(self.resolve_vars_if_possible(ty));
@ -1091,14 +1091,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let new_obligation =
self.mk_trait_obligation_with_new_self_ty(obligation.param_env, trait_pred_and_self);
if self.predicate_must_hold_modulo_regions(&new_obligation) {
err.span_suggestion_verbose(
err.span_suggestion_short(
stmt.span.with_lo(tail_expr.span.hi()),
"remove this semicolon",
"",
Applicability::MachineApplicable,
);
} else {
err.span_help(block.span, "this block is missing a tail expression");
err.span_label(block.span, "this block is missing a tail expression");
}
}