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