@@ -495,64 +495,6 @@ impl<'a> Parser<'a> {
495
495
}
496
496
}
497
497
498
- /// Check for erroneous `ident { }`; if matches, signal error and
499
- /// recover (without consuming any expected input token). Returns
500
- /// true if and only if input was consumed for recovery.
501
- pub fn check_for_erroneous_unit_struct_expecting ( & mut self ,
502
- expected : & [ token:: Token ] )
503
- -> bool {
504
- if self . token == token:: OpenDelim ( token:: Brace )
505
- && expected. iter ( ) . all ( |t| * t != token:: OpenDelim ( token:: Brace ) )
506
- && self . look_ahead ( 1 , |t| * t == token:: CloseDelim ( token:: Brace ) ) {
507
- // matched; signal non-fatal error and recover.
508
- let span = self . span ;
509
- self . span_err ( span, "unit-like struct construction is written with no trailing `{ }`" ) ;
510
- self . eat ( & token:: OpenDelim ( token:: Brace ) ) ;
511
- self . eat ( & token:: CloseDelim ( token:: Brace ) ) ;
512
- true
513
- } else {
514
- false
515
- }
516
- }
517
-
518
- /// Commit to parsing a complete expression `e` expected to be
519
- /// followed by some token from the set edible + inedible. Recover
520
- /// from anticipated input errors, discarding erroneous characters.
521
- pub fn commit_expr ( & mut self , e : & Expr , edible : & [ token:: Token ] ,
522
- inedible : & [ token:: Token ] ) -> PResult < ' a , ( ) > {
523
- debug ! ( "commit_expr {:?}" , e) ;
524
- if let ExprKind :: Path ( ..) = e. node {
525
- // might be unit-struct construction; check for recoverableinput error.
526
- let expected = edible. iter ( )
527
- . cloned ( )
528
- . chain ( inedible. iter ( ) . cloned ( ) )
529
- . collect :: < Vec < _ > > ( ) ;
530
- self . check_for_erroneous_unit_struct_expecting ( & expected[ ..] ) ;
531
- }
532
- self . expect_one_of ( edible, inedible)
533
- }
534
-
535
- pub fn commit_expr_expecting ( & mut self , e : & Expr , edible : token:: Token ) -> PResult < ' a , ( ) > {
536
- self . commit_expr ( e, & [ edible] , & [ ] )
537
- }
538
-
539
- /// Commit to parsing a complete statement `s`, which expects to be
540
- /// followed by some token from the set edible + inedible. Check
541
- /// for recoverable input errors, discarding erroneous characters.
542
- pub fn commit_stmt ( & mut self , edible : & [ token:: Token ] ,
543
- inedible : & [ token:: Token ] ) -> PResult < ' a , ( ) > {
544
- if self . last_token
545
- . as_ref ( )
546
- . map_or ( false , |t| t. is_ident ( ) || t. is_path ( ) ) {
547
- let expected = edible. iter ( )
548
- . cloned ( )
549
- . chain ( inedible. iter ( ) . cloned ( ) )
550
- . collect :: < Vec < _ > > ( ) ;
551
- self . check_for_erroneous_unit_struct_expecting ( & expected) ;
552
- }
553
- self . expect_one_of ( edible, inedible)
554
- }
555
-
556
498
/// returns the span of expr, if it was not interpolated or the span of the interpolated token
557
499
fn interpolated_or_expr_span ( & self ,
558
500
expr : PResult < ' a , P < Expr > > )
@@ -1247,7 +1189,7 @@ impl<'a> Parser<'a> {
1247
1189
let default = if self . check ( & token:: Eq ) {
1248
1190
self . bump ( ) ;
1249
1191
let expr = self . parse_expr ( ) ?;
1250
- self . commit_expr_expecting ( & expr , token:: Semi ) ?;
1192
+ self . expect ( & token:: Semi ) ?;
1251
1193
Some ( expr)
1252
1194
} else {
1253
1195
self . expect ( & token:: Semi ) ?;
@@ -2195,8 +2137,7 @@ impl<'a> Parser<'a> {
2195
2137
let mut trailing_comma = false ;
2196
2138
while self . token != token:: CloseDelim ( token:: Paren ) {
2197
2139
es. push ( self . parse_expr ( ) ?) ;
2198
- self . commit_expr ( & es. last ( ) . unwrap ( ) , & [ ] ,
2199
- & [ token:: Comma , token:: CloseDelim ( token:: Paren ) ] ) ?;
2140
+ self . expect_one_of ( & [ ] , & [ token:: Comma , token:: CloseDelim ( token:: Paren ) ] ) ?;
2200
2141
if self . check ( & token:: Comma ) {
2201
2142
trailing_comma = true ;
2202
2143
@@ -2407,9 +2348,8 @@ impl<'a> Parser<'a> {
2407
2348
}
2408
2349
}
2409
2350
2410
- match self . commit_expr ( & fields. last ( ) . unwrap ( ) . expr ,
2411
- & [ token:: Comma ] ,
2412
- & [ token:: CloseDelim ( token:: Brace ) ] ) {
2351
+ match self . expect_one_of ( & [ token:: Comma ] ,
2352
+ & [ token:: CloseDelim ( token:: Brace ) ] ) {
2413
2353
Ok ( ( ) ) => { }
2414
2354
Err ( mut e) => {
2415
2355
e. emit ( ) ;
@@ -2662,7 +2602,7 @@ impl<'a> Parser<'a> {
2662
2602
self . bump ( ) ;
2663
2603
let ix = self . parse_expr ( ) ?;
2664
2604
hi = self . span . hi ;
2665
- self . commit_expr_expecting ( & ix , token:: CloseDelim ( token:: Bracket ) ) ?;
2605
+ self . expect ( & token:: CloseDelim ( token:: Bracket ) ) ?;
2666
2606
let index = self . mk_index ( e, ix) ;
2667
2607
e = self . mk_expr ( lo, hi, index, ThinVec :: new ( ) )
2668
2608
}
@@ -3329,8 +3269,7 @@ impl<'a> Parser<'a> {
3329
3269
let lo = self . last_span . lo ;
3330
3270
let discriminant = self . parse_expr_res ( Restrictions :: RESTRICTION_NO_STRUCT_LITERAL ,
3331
3271
None ) ?;
3332
- if let Err ( mut e) = self . commit_expr_expecting ( & discriminant,
3333
- token:: OpenDelim ( token:: Brace ) ) {
3272
+ if let Err ( mut e) = self . expect ( & token:: OpenDelim ( token:: Brace ) ) {
3334
3273
if self . token == token:: Token :: Semi {
3335
3274
e. span_note ( match_span, "did you mean to remove this `match` keyword?" ) ;
3336
3275
}
@@ -3376,7 +3315,7 @@ impl<'a> Parser<'a> {
3376
3315
&& self . token != token:: CloseDelim ( token:: Brace ) ;
3377
3316
3378
3317
if require_comma {
3379
- self . commit_expr ( & expr , & [ token:: Comma ] , & [ token:: CloseDelim ( token:: Brace ) ] ) ?;
3318
+ self . expect_one_of ( & [ token:: Comma ] , & [ token:: CloseDelim ( token:: Brace ) ] ) ?;
3380
3319
} else {
3381
3320
self . eat ( & token:: Comma ) ;
3382
3321
}
@@ -4118,7 +4057,7 @@ impl<'a> Parser<'a> {
4118
4057
_ => { // all other kinds of statements:
4119
4058
let mut hi = span. hi ;
4120
4059
if classify:: stmt_ends_with_semi ( & node) {
4121
- self . commit_stmt ( & [ token:: Semi ] , & [ ] ) ?;
4060
+ self . expect ( & token:: Semi ) ?;
4122
4061
hi = self . last_span . hi ;
4123
4062
}
4124
4063
@@ -4196,7 +4135,7 @@ impl<'a> Parser<'a> {
4196
4135
if classify:: expr_requires_semi_to_be_stmt ( & e) {
4197
4136
// Just check for errors and recover; do not eat semicolon yet.
4198
4137
if let Err ( mut e) =
4199
- self . commit_stmt ( & [ ] , & [ token:: Semi , token:: CloseDelim ( token:: Brace ) ] )
4138
+ self . expect_one_of ( & [ ] , & [ token:: Semi , token:: CloseDelim ( token:: Brace ) ] )
4200
4139
{
4201
4140
e. emit ( ) ;
4202
4141
self . recover_stmt ( ) ;
@@ -4863,7 +4802,7 @@ impl<'a> Parser<'a> {
4863
4802
let typ = self . parse_ty_sum ( ) ?;
4864
4803
self . expect ( & token:: Eq ) ?;
4865
4804
let expr = self . parse_expr ( ) ?;
4866
- self . commit_expr_expecting ( & expr , token:: Semi ) ?;
4805
+ self . expect ( & token:: Semi ) ?;
4867
4806
( name, ast:: ImplItemKind :: Const ( typ, expr) )
4868
4807
} else {
4869
4808
let ( name, inner_attrs, node) = self . parse_impl_method ( & vis) ?;
@@ -5287,7 +5226,7 @@ impl<'a> Parser<'a> {
5287
5226
let ty = self . parse_ty_sum ( ) ?;
5288
5227
self . expect ( & token:: Eq ) ?;
5289
5228
let e = self . parse_expr ( ) ?;
5290
- self . commit_expr_expecting ( & e , token:: Semi ) ?;
5229
+ self . expect ( & token:: Semi ) ?;
5291
5230
let item = match m {
5292
5231
Some ( m) => ItemKind :: Static ( ty, m, e) ,
5293
5232
None => ItemKind :: Const ( ty, e) ,
0 commit comments