@@ -159,8 +159,6 @@ enum IsStandalone {
159
159
Standalone ,
160
160
/// It's a subexpression, i.e., *not* standalone.
161
161
Subexpr ,
162
- /// It's maybe standalone; we're not sure.
163
- Maybe ,
164
162
}
165
163
166
164
#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
@@ -213,14 +211,8 @@ impl MultiSugg {
213
211
err. multipart_suggestion ( & self . msg , self . patches , self . applicability ) ;
214
212
}
215
213
216
- /// Overrides individual messages and applicabilities.
217
- fn emit_many (
218
- err : & mut Diagnostic ,
219
- msg : & str ,
220
- applicability : Applicability ,
221
- suggestions : impl Iterator < Item = Self > ,
222
- ) {
223
- err. multipart_suggestions ( msg, suggestions. map ( |s| s. patches ) , applicability) ;
214
+ fn emit_verbose ( self , err : & mut Diagnostic ) {
215
+ err. multipart_suggestion_verbose ( & self . msg , self . patches , self . applicability ) ;
224
216
}
225
217
}
226
218
@@ -1267,26 +1259,24 @@ impl<'a> Parser<'a> {
1267
1259
& mut self ,
1268
1260
operand_expr : P < Expr > ,
1269
1261
op_span : Span ,
1270
- prev_is_semi : bool ,
1262
+ start_stmt : bool ,
1271
1263
) -> PResult < ' a , P < Expr > > {
1272
- let standalone =
1273
- if prev_is_semi { IsStandalone :: Standalone } else { IsStandalone :: Subexpr } ;
1264
+ let standalone = if start_stmt { IsStandalone :: Standalone } else { IsStandalone :: Subexpr } ;
1274
1265
let kind = IncDecRecovery { standalone, op : IncOrDec :: Inc , fixity : UnaryFixity :: Pre } ;
1275
-
1276
1266
self . recover_from_inc_dec ( operand_expr, kind, op_span)
1277
1267
}
1278
1268
1279
1269
pub ( super ) fn recover_from_postfix_increment (
1280
1270
& mut self ,
1281
1271
operand_expr : P < Expr > ,
1282
1272
op_span : Span ,
1273
+ start_stmt : bool ,
1283
1274
) -> PResult < ' a , P < Expr > > {
1284
1275
let kind = IncDecRecovery {
1285
- standalone : IsStandalone :: Maybe ,
1276
+ standalone : if start_stmt { IsStandalone :: Standalone } else { IsStandalone :: Subexpr } ,
1286
1277
op : IncOrDec :: Inc ,
1287
1278
fixity : UnaryFixity :: Post ,
1288
1279
} ;
1289
-
1290
1280
self . recover_from_inc_dec ( operand_expr, kind, op_span)
1291
1281
}
1292
1282
@@ -1315,34 +1305,25 @@ impl<'a> Parser<'a> {
1315
1305
} ;
1316
1306
1317
1307
match kind. standalone {
1318
- IsStandalone :: Standalone => self . inc_dec_standalone_suggest ( kind, spans) . emit ( & mut err) ,
1308
+ IsStandalone :: Standalone => {
1309
+ self . inc_dec_standalone_suggest ( kind, spans) . emit_verbose ( & mut err)
1310
+ }
1319
1311
IsStandalone :: Subexpr => {
1320
1312
let Ok ( base_src) = self . span_to_snippet ( base. span )
1321
- else { return help_base_case ( err, base) } ;
1313
+ else { return help_base_case ( err, base) } ;
1322
1314
match kind. fixity {
1323
1315
UnaryFixity :: Pre => {
1324
1316
self . prefix_inc_dec_suggest ( base_src, kind, spans) . emit ( & mut err)
1325
1317
}
1326
1318
UnaryFixity :: Post => {
1327
- self . postfix_inc_dec_suggest ( base_src, kind, spans) . emit ( & mut err)
1319
+ // won't suggest since we can not handle the precedences
1320
+ // for example: `a + b++` has been parsed (a + b)++ and we can not suggest here
1321
+ if !matches ! ( base. kind, ExprKind :: Binary ( _, _, _) ) {
1322
+ self . postfix_inc_dec_suggest ( base_src, kind, spans) . emit ( & mut err)
1323
+ }
1328
1324
}
1329
1325
}
1330
1326
}
1331
- IsStandalone :: Maybe => {
1332
- let Ok ( base_src) = self . span_to_snippet ( base. span )
1333
- else { return help_base_case ( err, base) } ;
1334
- let sugg1 = match kind. fixity {
1335
- UnaryFixity :: Pre => self . prefix_inc_dec_suggest ( base_src, kind, spans) ,
1336
- UnaryFixity :: Post => self . postfix_inc_dec_suggest ( base_src, kind, spans) ,
1337
- } ;
1338
- let sugg2 = self . inc_dec_standalone_suggest ( kind, spans) ;
1339
- MultiSugg :: emit_many (
1340
- & mut err,
1341
- "use `+= 1` instead" ,
1342
- Applicability :: Unspecified ,
1343
- [ sugg1, sugg2] . into_iter ( ) ,
1344
- )
1345
- }
1346
1327
}
1347
1328
Err ( err)
1348
1329
}
@@ -1392,7 +1373,6 @@ impl<'a> Parser<'a> {
1392
1373
}
1393
1374
1394
1375
patches. push ( ( post_span, format ! ( " {}= 1" , kind. op. chr( ) ) ) ) ;
1395
-
1396
1376
MultiSugg {
1397
1377
msg : format ! ( "use `{}= 1` instead" , kind. op. chr( ) ) ,
1398
1378
patches,
0 commit comments