@@ -427,10 +427,8 @@ impl<'a> Parser<'a> {
427
427
}
428
428
429
429
/// Parses a bound according to the grammar:
430
- ///
431
430
/// ```
432
431
/// BOUND = TY_BOUND | LT_BOUND
433
- /// LT_BOUND = LIFETIME (e.g., `'a`)
434
432
/// ```
435
433
fn parse_generic_bound (
436
434
& mut self ,
@@ -443,14 +441,7 @@ impl<'a> Parser<'a> {
443
441
let is_negative = self . eat ( & token:: Not ) ;
444
442
let question = if self . eat ( & token:: Question ) { Some ( self . prev_span ) } else { None } ;
445
443
if self . token . is_lifetime ( ) {
446
- self . error_opt_out_lifetime ( question) ;
447
- let bound = GenericBound :: Outlives ( self . expect_lifetime ( ) ) ;
448
- if has_parens {
449
- // FIXME(Centril): Consider not erroring here and accepting `('lt)` instead,
450
- // possibly introducing `GenericBound::Paren(P<GenericBound>)`?
451
- self . recover_paren_lifetime ( lo, inner_lo) ?;
452
- }
453
- Ok ( Ok ( bound) )
444
+ Ok ( Ok ( self . parse_generic_lt_bound ( lo, inner_lo, has_parens, question) ?) )
454
445
} else {
455
446
let ( poly_span, bound) = self . parse_generic_ty_bound ( lo, has_parens, question) ?;
456
447
if is_negative {
@@ -461,6 +452,27 @@ impl<'a> Parser<'a> {
461
452
}
462
453
}
463
454
455
+ /// Parses a lifetime ("outlives") bound, e.g. `'a`, according to:
456
+ /// ```
457
+ /// LT_BOUND = LIFETIME
458
+ /// ```
459
+ fn parse_generic_lt_bound (
460
+ & mut self ,
461
+ lo : Span ,
462
+ inner_lo : Span ,
463
+ has_parens : bool ,
464
+ question : Option < Span > ,
465
+ ) -> PResult < ' a , GenericBound > {
466
+ self . error_opt_out_lifetime ( question) ;
467
+ let bound = GenericBound :: Outlives ( self . expect_lifetime ( ) ) ;
468
+ if has_parens {
469
+ // FIXME(Centril): Consider not erroring here and accepting `('lt)` instead,
470
+ // possibly introducing `GenericBound::Paren(P<GenericBound>)`?
471
+ self . recover_paren_lifetime ( lo, inner_lo) ?;
472
+ }
473
+ Ok ( bound)
474
+ }
475
+
464
476
fn error_opt_out_lifetime ( & self , question : Option < Span > ) {
465
477
if let Some ( span) = question {
466
478
self . struct_span_err ( span, "`?` may only modify trait bounds, not lifetime bounds" )
0 commit comments