@@ -688,12 +688,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
688
688
let msg = "`match` arms have incompatible types" ;
689
689
err. span_label ( outer_error_span, msg) ;
690
690
if let Some ( ( sp, boxed) ) = semi_span {
691
- if matches ! ( boxed, StatementAsExpression :: NeedsBoxing ) {
692
- err. span_suggestion_verbose (
691
+ if let ( StatementAsExpression :: NeedsBoxing , [ .., prior_arm] ) =
692
+ ( boxed, & prior_arms[ ..] )
693
+ {
694
+ err. multipart_suggestion (
695
+ "consider removing this semicolon and boxing the expressions" ,
696
+ vec ! [
697
+ ( prior_arm. shrink_to_lo( ) , "Box::new(" . to_string( ) ) ,
698
+ ( prior_arm. shrink_to_hi( ) , ")" . to_string( ) ) ,
699
+ ( arm_span. shrink_to_lo( ) , "Box::new(" . to_string( ) ) ,
700
+ ( arm_span. shrink_to_hi( ) , ")" . to_string( ) ) ,
701
+ ( sp, String :: new( ) ) ,
702
+ ] ,
703
+ Applicability :: HasPlaceholders ,
704
+ ) ;
705
+ } else if matches ! ( boxed, StatementAsExpression :: NeedsBoxing ) {
706
+ err. span_suggestion_short (
693
707
sp,
694
- "consider removing this semicolon and boxing the expression " ,
708
+ "consider removing this semicolon and boxing the expressions " ,
695
709
String :: new ( ) ,
696
- Applicability :: HasPlaceholders ,
710
+ Applicability :: MachineApplicable ,
697
711
) ;
698
712
} else {
699
713
err. span_suggestion_short (
@@ -727,11 +741,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
727
741
}
728
742
if let Some ( ( sp, boxed) ) = semicolon {
729
743
if matches ! ( boxed, StatementAsExpression :: NeedsBoxing ) {
730
- err. span_suggestion_verbose (
731
- sp,
744
+ err. multipart_suggestion (
732
745
"consider removing this semicolon and boxing the expression" ,
733
- String :: new ( ) ,
734
- Applicability :: HasPlaceholders ,
746
+ vec ! [
747
+ ( then. shrink_to_lo( ) , "Box::new(" . to_string( ) ) ,
748
+ ( then. shrink_to_hi( ) , ")" . to_string( ) ) ,
749
+ ( else_sp. shrink_to_lo( ) , "Box::new(" . to_string( ) ) ,
750
+ ( else_sp. shrink_to_hi( ) , ")" . to_string( ) ) ,
751
+ ( sp, String :: new( ) ) ,
752
+ ] ,
753
+ Applicability :: MachineApplicable ,
735
754
) ;
736
755
} else {
737
756
err. span_suggestion_short (
0 commit comments