@@ -619,6 +619,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
619619 scrut_hir_id,
620620 opt_suggest_box_span,
621621 arm_span,
622+ scrut_span,
622623 ..
623624 } ) => match source {
624625 hir:: MatchSource :: IfLetDesugar { .. } => {
@@ -664,18 +665,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
664665 Some ( ty:: error:: ExpectedFound { expected, .. } ) => expected,
665666 _ => last_ty,
666667 } ) ;
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 ) ;
669670 if prior_arms. len ( ) <= 4 {
670671 for sp in prior_arms {
672+ any_multiline_arm |= source_map. is_multiline ( * sp) ;
671673 err. span_label ( * sp, format ! ( "this is found to be of type `{}`" , t) ) ;
672674 }
673675 } else if let Some ( sp) = prior_arms. last ( ) {
676+ any_multiline_arm |= source_map. is_multiline ( * sp) ;
674677 err. span_label (
675678 * sp,
676679 format ! ( "this and all prior arms are found to be of type `{}`" , t) ,
677680 ) ;
678681 }
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) ;
679691 if let Some ( sp) = semi_span {
680692 err. span_suggestion_short (
681693 sp,
0 commit comments