@@ -1106,22 +1106,29 @@ pub(crate) struct Rust2024IncompatiblePat<'m> {
1106
1106
}
1107
1107
1108
1108
pub ( 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 ,
1112
1109
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 > ,
1113
1113
pub ( crate ) ref_pattern_count : usize ,
1114
1114
pub ( crate ) binding_mode_count : usize ,
1115
1115
/// Labels for where incompatibility-causing by-ref default binding modes were introduced.
1116
1116
pub ( crate ) default_mode_labels : & ' m FxIndexMap < Span , ty:: Mutability > ,
1117
1117
}
1118
1118
1119
+ pub ( crate ) enum Rust2024IncompatiblePatSuggKind {
1120
+ Subtractive ,
1121
+ Additive ,
1122
+ }
1123
+
1119
1124
impl < ' m > Subdiagnostic for Rust2024IncompatiblePatSugg < ' m > {
1120
1125
fn add_to_diag_with < G : EmissionGuarantee , F : SubdiagMessageOp < G > > (
1121
1126
self ,
1122
1127
diag : & mut Diag < ' _ , G > ,
1123
1128
_f : & F ,
1124
1129
) {
1130
+ use Rust2024IncompatiblePatSuggKind :: * ;
1131
+
1125
1132
// Format and emit explanatory notes about default binding modes. Reversing the spans' order
1126
1133
// means if we have nested spans, the innermost ones will be visited first.
1127
1134
for ( & span, & def_br_mutbl) in self . default_mode_labels . iter ( ) . rev ( ) {
@@ -1143,17 +1150,33 @@ impl<'m> Subdiagnostic for Rust2024IncompatiblePatSugg<'m> {
1143
1150
} else {
1144
1151
Applicability :: MaybeIncorrect
1145
1152
} ;
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) )
1153
1156
} else {
1154
1157
String :: new ( )
1155
1158
} ;
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 ( )
1157
1180
} ;
1158
1181
// FIXME(dianne): for peace of mind, don't risk emitting a 0-part suggestion (that panics!)
1159
1182
if !self . suggestion . is_empty ( ) {
0 commit comments