@@ -22,7 +22,6 @@ use crate::fluent_generated as fluent;
22
22
use crate :: parser;
23
23
use crate :: parser:: attr:: InnerAttrPolicy ;
24
24
use ast:: token:: IdentIsRaw ;
25
- use parser:: Recovered ;
26
25
use rustc_ast as ast;
27
26
use rustc_ast:: ptr:: P ;
28
27
use rustc_ast:: token:: { self , Delimiter , Lit , LitKind , Token , TokenKind } ;
@@ -31,7 +30,7 @@ use rustc_ast::util::parser::AssocOp;
31
30
use rustc_ast:: {
32
31
AngleBracketedArg , AngleBracketedArgs , AnonConst , AttrVec , BinOpKind , BindingMode , Block ,
33
32
BlockCheckMode , Expr , ExprKind , GenericArg , Generics , HasTokens , Item , ItemKind , Param , Pat ,
34
- PatKind , Path , PathSegment , QSelf , Ty , TyKind ,
33
+ PatKind , Path , PathSegment , QSelf , Recovered , Ty , TyKind ,
35
34
} ;
36
35
use rustc_ast_pretty:: pprust;
37
36
use rustc_data_structures:: fx:: FxHashSet ;
@@ -527,14 +526,14 @@ impl<'a> Parser<'a> {
527
526
//
528
527
// let x = 32:
529
528
// let y = 42;
530
- self . dcx ( ) . emit_err ( ExpectedSemi {
529
+ let guar = self . dcx ( ) . emit_err ( ExpectedSemi {
531
530
span : self . token . span ,
532
531
token : self . token . clone ( ) ,
533
532
unexpected_token_label : None ,
534
533
sugg : ExpectedSemiSugg :: ChangeToSemi ( self . token . span ) ,
535
534
} ) ;
536
535
self . bump ( ) ;
537
- return Ok ( Recovered :: Yes ) ;
536
+ return Ok ( Recovered :: Yes ( guar ) ) ;
538
537
} else if self . look_ahead ( 0 , |t| {
539
538
t == & token:: CloseDelim ( Delimiter :: Brace )
540
539
|| ( ( t. can_begin_expr ( ) || t. can_begin_item ( ) )
@@ -552,13 +551,13 @@ impl<'a> Parser<'a> {
552
551
// let x = 32
553
552
// let y = 42;
554
553
let span = self . prev_token . span . shrink_to_hi ( ) ;
555
- self . dcx ( ) . emit_err ( ExpectedSemi {
554
+ let guar = self . dcx ( ) . emit_err ( ExpectedSemi {
556
555
span,
557
556
token : self . token . clone ( ) ,
558
557
unexpected_token_label : Some ( self . token . span ) ,
559
558
sugg : ExpectedSemiSugg :: AddSemi ( span) ,
560
559
} ) ;
561
- return Ok ( Recovered :: Yes ) ;
560
+ return Ok ( Recovered :: Yes ( guar ) ) ;
562
561
}
563
562
}
564
563
@@ -712,8 +711,8 @@ impl<'a> Parser<'a> {
712
711
713
712
if self . check_too_many_raw_str_terminators ( & mut err) {
714
713
if expected. contains ( & TokenType :: Token ( token:: Semi ) ) && self . eat ( & token:: Semi ) {
715
- err. emit ( ) ;
716
- return Ok ( Recovered :: Yes ) ;
714
+ let guar = err. emit ( ) ;
715
+ return Ok ( Recovered :: Yes ( guar ) ) ;
717
716
} else {
718
717
return Err ( err) ;
719
718
}
@@ -1251,7 +1250,7 @@ impl<'a> Parser<'a> {
1251
1250
}
1252
1251
}
1253
1252
}
1254
- Ok ( ( _, _, Recovered :: Yes ) ) => { }
1253
+ Ok ( ( _, _, Recovered :: Yes ( _ ) ) ) => { }
1255
1254
Err ( err) => {
1256
1255
err. cancel ( ) ;
1257
1256
}
@@ -1284,21 +1283,21 @@ impl<'a> Parser<'a> {
1284
1283
1285
1284
/// Check to see if a pair of chained operators looks like an attempt at chained comparison,
1286
1285
/// e.g. `1 < x <= 3`. If so, suggest either splitting the comparison into two, or
1287
- /// parenthesising the leftmost comparison.
1286
+ /// parenthesising the leftmost comparison. The return value indicates if recovery happened.
1288
1287
fn attempt_chained_comparison_suggestion (
1289
1288
& mut self ,
1290
1289
err : & mut ComparisonOperatorsCannotBeChained ,
1291
1290
inner_op : & Expr ,
1292
1291
outer_op : & Spanned < AssocOp > ,
1293
- ) -> Recovered {
1292
+ ) -> bool {
1294
1293
if let ExprKind :: Binary ( op, l1, r1) = & inner_op. kind {
1295
1294
if let ExprKind :: Field ( _, ident) = l1. kind
1296
1295
&& ident. as_str ( ) . parse :: < i32 > ( ) . is_err ( )
1297
1296
&& !matches ! ( r1. kind, ExprKind :: Lit ( _) )
1298
1297
{
1299
1298
// The parser has encountered `foo.bar<baz`, the likelihood of the turbofish
1300
1299
// suggestion being the only one to apply is high.
1301
- return Recovered :: No ;
1300
+ return false ;
1302
1301
}
1303
1302
return match ( op. node , & outer_op. node ) {
1304
1303
// `x == y == z`
@@ -1317,7 +1316,7 @@ impl<'a> Parser<'a> {
1317
1316
span : inner_op. span . shrink_to_hi ( ) ,
1318
1317
middle_term : expr_to_str ( r1) ,
1319
1318
} ) ;
1320
- Recovered :: No // Keep the current parse behavior, where the AST is `(x < y) < z`.
1319
+ false // Keep the current parse behavior, where the AST is `(x < y) < z`.
1321
1320
}
1322
1321
// `x == y < z`
1323
1322
( BinOpKind :: Eq , AssocOp :: Less | AssocOp :: LessEqual | AssocOp :: Greater | AssocOp :: GreaterEqual ) => {
@@ -1331,12 +1330,12 @@ impl<'a> Parser<'a> {
1331
1330
left : r1. span . shrink_to_lo ( ) ,
1332
1331
right : r2. span . shrink_to_hi ( ) ,
1333
1332
} ) ;
1334
- Recovered :: Yes
1333
+ true
1335
1334
}
1336
1335
Err ( expr_err) => {
1337
1336
expr_err. cancel ( ) ;
1338
1337
self . restore_snapshot ( snapshot) ;
1339
- Recovered :: Yes
1338
+ true
1340
1339
}
1341
1340
}
1342
1341
}
@@ -1351,19 +1350,19 @@ impl<'a> Parser<'a> {
1351
1350
left : l1. span . shrink_to_lo ( ) ,
1352
1351
right : r1. span . shrink_to_hi ( ) ,
1353
1352
} ) ;
1354
- Recovered :: Yes
1353
+ true
1355
1354
}
1356
1355
Err ( expr_err) => {
1357
1356
expr_err. cancel ( ) ;
1358
1357
self . restore_snapshot ( snapshot) ;
1359
- Recovered :: No
1358
+ false
1360
1359
}
1361
1360
}
1362
1361
}
1363
- _ => Recovered :: No ,
1362
+ _ => false
1364
1363
} ;
1365
1364
}
1366
- Recovered :: No
1365
+ false
1367
1366
}
1368
1367
1369
1368
/// Produces an error if comparison operators are chained (RFC #558).
@@ -1494,7 +1493,7 @@ impl<'a> Parser<'a> {
1494
1493
// misformatted turbofish, for instance), suggest a correct form.
1495
1494
let recovered = self
1496
1495
. attempt_chained_comparison_suggestion ( & mut err, inner_op, outer_op) ;
1497
- if matches ! ( recovered, Recovered :: Yes ) {
1496
+ if recovered {
1498
1497
let guar = self . dcx ( ) . emit_err ( err) ;
1499
1498
mk_err_expr ( self , inner_op. span . to ( self . prev_token . span ) , guar)
1500
1499
} else {
@@ -1503,10 +1502,10 @@ impl<'a> Parser<'a> {
1503
1502
}
1504
1503
} ;
1505
1504
}
1506
- let recover =
1505
+ let recovered =
1507
1506
self . attempt_chained_comparison_suggestion ( & mut err, inner_op, outer_op) ;
1508
1507
let guar = self . dcx ( ) . emit_err ( err) ;
1509
- if matches ! ( recover , Recovered :: Yes ) {
1508
+ if recovered {
1510
1509
return mk_err_expr ( self , inner_op. span . to ( self . prev_token . span ) , guar) ;
1511
1510
}
1512
1511
}
0 commit comments