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