@@ -1104,7 +1104,7 @@ pub(crate) struct Rust2024IncompatiblePat {
11041104
11051105pub ( crate ) struct Rust2024IncompatiblePatSugg {
11061106 pub ( crate ) suggestion : Vec < ( Span , String ) > ,
1107- pub ( crate ) kind : Rust2024IncompatiblePatSuggKind ,
1107+ pub ( crate ) kind : Option < Rust2024IncompatiblePatSuggKind > ,
11081108 pub ( crate ) ref_pattern_count : usize ,
11091109 pub ( crate ) binding_mode_count : usize ,
11101110}
@@ -1120,31 +1120,33 @@ impl Subdiagnostic for Rust2024IncompatiblePatSugg {
11201120 diag : & mut Diag < ' _ , G > ,
11211121 _f : & F ,
11221122 ) {
1123+ use Rust2024IncompatiblePatSuggKind :: * ;
11231124 let applicability =
11241125 if self . suggestion . iter ( ) . all ( |( span, _) | span. can_be_used_for_suggestions ( ) ) {
11251126 Applicability :: MachineApplicable
11261127 } else {
11271128 Applicability :: MaybeIncorrect
11281129 } ;
1129- let derefs = if self . ref_pattern_count > 0 {
1130- format ! ( "reference pattern{}" , pluralize!( self . ref_pattern_count) )
1131- } else {
1132- String :: new ( )
1133- } ;
1134- let modes = if self . binding_mode_count > 0 {
1135- format ! ( "variable binding mode{}" , pluralize!( self . binding_mode_count) )
1130+ let msg = if let Some ( kind) = self . kind {
1131+ let derefs = if self . ref_pattern_count > 0 {
1132+ format ! ( "reference pattern{}" , pluralize!( self . ref_pattern_count) )
1133+ } else {
1134+ String :: new ( )
1135+ } ;
1136+ let modes = if self . binding_mode_count > 0 {
1137+ format ! ( "variable binding mode{}" , pluralize!( self . binding_mode_count) )
1138+ } else {
1139+ String :: new ( )
1140+ } ;
1141+ let and = if !derefs. is_empty ( ) && !modes. is_empty ( ) { " and " } else { "" } ;
1142+ let ( old_visibility, new_visibility) = match kind {
1143+ Subtractive => ( "" , "implicit" ) ,
1144+ Additive => ( "implied " , "explicit" ) ,
1145+ } ;
1146+ format ! ( "make the {old_visibility}{derefs}{and}{modes} {new_visibility}" )
11361147 } else {
1137- String :: new ( )
1148+ "rewrite the pattern" . to_owned ( )
11381149 } ;
1139- let and = if !derefs. is_empty ( ) && !modes. is_empty ( ) { " and " } else { "" } ;
1140- let ( old_visibility, new_visibility) = match self . kind {
1141- Rust2024IncompatiblePatSuggKind :: Subtractive => ( "" , "implicit" ) ,
1142- Rust2024IncompatiblePatSuggKind :: Additive => ( "implied " , "explicit" ) ,
1143- } ;
1144- diag. multipart_suggestion_verbose (
1145- format ! ( "make the {old_visibility}{derefs}{and}{modes} {new_visibility}" ) ,
1146- self . suggestion ,
1147- applicability,
1148- ) ;
1150+ diag. multipart_suggestion_verbose ( msg, self . suggestion , applicability) ;
11491151 }
11501152}
0 commit comments