@@ -159,8 +159,6 @@ enum IsStandalone {
159159 Standalone ,
160160 /// It's a subexpression, i.e., *not* standalone.
161161 Subexpr ,
162- /// It's maybe standalone; we're not sure.
163- Maybe ,
164162}
165163
166164#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
@@ -213,14 +211,8 @@ impl MultiSugg {
213211 err. multipart_suggestion ( & self . msg , self . patches , self . applicability ) ;
214212 }
215213
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 ) ;
224216 }
225217}
226218
@@ -1267,26 +1259,24 @@ impl<'a> Parser<'a> {
12671259 & mut self ,
12681260 operand_expr : P < Expr > ,
12691261 op_span : Span ,
1270- prev_is_semi : bool ,
1262+ start_stmt : bool ,
12711263 ) -> 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 } ;
12741265 let kind = IncDecRecovery { standalone, op : IncOrDec :: Inc , fixity : UnaryFixity :: Pre } ;
1275-
12761266 self . recover_from_inc_dec ( operand_expr, kind, op_span)
12771267 }
12781268
12791269 pub ( super ) fn recover_from_postfix_increment (
12801270 & mut self ,
12811271 operand_expr : P < Expr > ,
12821272 op_span : Span ,
1273+ start_stmt : bool ,
12831274 ) -> PResult < ' a , P < Expr > > {
12841275 let kind = IncDecRecovery {
1285- standalone : IsStandalone :: Maybe ,
1276+ standalone : if start_stmt { IsStandalone :: Standalone } else { IsStandalone :: Subexpr } ,
12861277 op : IncOrDec :: Inc ,
12871278 fixity : UnaryFixity :: Post ,
12881279 } ;
1289-
12901280 self . recover_from_inc_dec ( operand_expr, kind, op_span)
12911281 }
12921282
@@ -1315,34 +1305,25 @@ impl<'a> Parser<'a> {
13151305 } ;
13161306
13171307 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+ }
13191311 IsStandalone :: Subexpr => {
13201312 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) } ;
13221314 match kind. fixity {
13231315 UnaryFixity :: Pre => {
13241316 self . prefix_inc_dec_suggest ( base_src, kind, spans) . emit ( & mut err)
13251317 }
13261318 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+ }
13281324 }
13291325 }
13301326 }
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- }
13461327 }
13471328 Err ( err)
13481329 }
@@ -1392,7 +1373,6 @@ impl<'a> Parser<'a> {
13921373 }
13931374
13941375 patches. push ( ( post_span, format ! ( " {}= 1" , kind. op. chr( ) ) ) ) ;
1395-
13961376 MultiSugg {
13971377 msg : format ! ( "use `{}= 1` instead" , kind. op. chr( ) ) ,
13981378 patches,
0 commit comments