@@ -619,6 +619,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
619
619
scrut_hir_id,
620
620
opt_suggest_box_span,
621
621
arm_span,
622
+ scrut_span,
622
623
..
623
624
} ) => match source {
624
625
hir:: MatchSource :: IfLetDesugar { .. } => {
@@ -664,18 +665,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
664
665
Some ( ty:: error:: ExpectedFound { expected, .. } ) => expected,
665
666
_ => last_ty,
666
667
} ) ;
667
- let msg = "`match` arms have incompatible types" ;
668
- err . span_label ( cause . span , msg ) ;
668
+ let source_map = self . tcx . sess . source_map ( ) ;
669
+ let mut any_multiline_arm = source_map . is_multiline ( arm_span ) ;
669
670
if prior_arms. len ( ) <= 4 {
670
671
for sp in prior_arms {
672
+ any_multiline_arm |= source_map. is_multiline ( * sp) ;
671
673
err. span_label ( * sp, format ! ( "this is found to be of type `{}`" , t) ) ;
672
674
}
673
675
} else if let Some ( sp) = prior_arms. last ( ) {
676
+ any_multiline_arm |= source_map. is_multiline ( * sp) ;
674
677
err. span_label (
675
678
* sp,
676
679
format ! ( "this and all prior arms are found to be of type `{}`" , t) ,
677
680
) ;
678
681
}
682
+ let outer_error_span = if any_multiline_arm {
683
+ // Cover just `match` and the scrutinee expression, not
684
+ // the entire match body, to reduce diagram noise.
685
+ cause. span . shrink_to_lo ( ) . to ( scrut_span)
686
+ } else {
687
+ cause. span
688
+ } ;
689
+ let msg = "`match` arms have incompatible types" ;
690
+ err. span_label ( outer_error_span, msg) ;
679
691
if let Some ( sp) = semi_span {
680
692
err. span_suggestion_short (
681
693
sp,
0 commit comments