@@ -1107,22 +1107,29 @@ pub(crate) struct Rust2024IncompatiblePat<'m> {
11071107}
11081108
11091109pub ( crate ) struct Rust2024IncompatiblePatSugg < ' m > {
1110- /// If true, our suggestion is to elide explicit binding modifiers.
1111- /// If false, our suggestion is to make the pattern fully explicit.
1112- pub ( crate ) suggest_eliding_modes : bool ,
11131110 pub ( crate ) suggestion : Vec < ( Span , String ) > ,
1111+ /// If `Some(..)`, we provide a suggestion about either adding or removing syntax.
1112+ /// If `None`, we suggest both additions and removals; use a generic wording for simplicity.
1113+ pub ( crate ) kind : Option < Rust2024IncompatiblePatSuggKind > ,
11141114 pub ( crate ) ref_pattern_count : usize ,
11151115 pub ( crate ) binding_mode_count : usize ,
11161116 /// Labels for where incompatibility-causing by-ref default binding modes were introduced.
11171117 pub ( crate ) default_mode_labels : & ' m FxIndexMap < Span , ty:: Mutability > ,
11181118}
11191119
1120+ pub ( crate ) enum Rust2024IncompatiblePatSuggKind {
1121+ Subtractive ,
1122+ Additive ,
1123+ }
1124+
11201125impl < ' m > Subdiagnostic for Rust2024IncompatiblePatSugg < ' m > {
11211126 fn add_to_diag_with < G : EmissionGuarantee , F : SubdiagMessageOp < G > > (
11221127 self ,
11231128 diag : & mut Diag < ' _ , G > ,
11241129 _f : & F ,
11251130 ) {
1131+ use Rust2024IncompatiblePatSuggKind :: * ;
1132+
11261133 // Format and emit explanatory notes about default binding modes. Reversing the spans' order
11271134 // means if we have nested spans, the innermost ones will be visited first.
11281135 for ( & span, & def_br_mutbl) in self . default_mode_labels . iter ( ) . rev ( ) {
@@ -1144,17 +1151,33 @@ impl<'m> Subdiagnostic for Rust2024IncompatiblePatSugg<'m> {
11441151 } else {
11451152 Applicability :: MaybeIncorrect
11461153 } ;
1147- let msg = if self . suggest_eliding_modes {
1148- let plural_modes = pluralize ! ( self . binding_mode_count) ;
1149- format ! ( "remove the unnecessary binding modifier{plural_modes}" )
1150- } else {
1151- let plural_derefs = pluralize ! ( self . ref_pattern_count) ;
1152- let and_modes = if self . binding_mode_count > 0 {
1153- format ! ( " and variable binding mode{}" , pluralize!( self . binding_mode_count) )
1154+ let msg = if let Some ( kind) = self . kind {
1155+ let derefs = if self . ref_pattern_count > 0 {
1156+ format ! ( "reference pattern{}" , pluralize!( self . ref_pattern_count) )
11541157 } else {
11551158 String :: new ( )
11561159 } ;
1157- format ! ( "make the implied reference pattern{plural_derefs}{and_modes} explicit" )
1160+ let modes = if self . binding_mode_count > 0 {
1161+ match kind {
1162+ Subtractive => {
1163+ format ! ( "binding modifier{}" , pluralize!( self . binding_mode_count) )
1164+ }
1165+ Additive => {
1166+ format ! ( "variable binding mode{}" , pluralize!( self . binding_mode_count) )
1167+ }
1168+ }
1169+ } else {
1170+ String :: new ( )
1171+ } ;
1172+ let and = if !derefs. is_empty ( ) && !modes. is_empty ( ) { " and " } else { "" } ;
1173+ match kind {
1174+ Subtractive => format ! ( "remove the unnecessary {derefs}{and}{modes}" ) ,
1175+ Additive => {
1176+ format ! ( "make the implied {derefs}{and}{modes} explicit" )
1177+ }
1178+ }
1179+ } else {
1180+ "rewrite the pattern" . to_owned ( )
11581181 } ;
11591182 // FIXME(dianne): for peace of mind, don't risk emitting a 0-part suggestion (that panics!)
11601183 if !self . suggestion . is_empty ( ) {
0 commit comments