1
Fork 0

Stop using the whole match expr span for an arm's obligation span

This commit is contained in:
Michael Goulet 2024-10-27 22:35:17 +00:00
parent 5f5c243ca0
commit 2507e83d7b
5 changed files with 18 additions and 21 deletions

View file

@ -412,6 +412,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
source,
ref prior_non_diverging_arms,
scrut_span,
expr_span,
..
}) => match source {
hir::MatchSource::TryDesugar(scrut_hir_id) => {
@ -460,12 +461,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
format!("this and all prior arms are found to be of type `{t}`"),
);
}
let outer = if any_multiline_arm || !source_map.is_multiline(cause.span) {
let outer = if any_multiline_arm || !source_map.is_multiline(expr_span) {
// Cover just `match` and the scrutinee expression, not
// the entire match body, to reduce diagram noise.
cause.span.shrink_to_lo().to(scrut_span)
expr_span.shrink_to_lo().to(scrut_span)
} else {
cause.span
expr_span
};
let msg = "`match` arms have incompatible types";
err.span_label(outer, msg);