@@ -431,8 +431,6 @@ impl<'a> Parser<'a> {
431
431
/// ```
432
432
/// BOUND = TY_BOUND | LT_BOUND
433
433
/// LT_BOUND = LIFETIME (e.g., `'a`)
434
- /// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)
435
- /// TY_BOUND_NOPAREN = [?] [for<LT_PARAM_DEFS>] SIMPLE_PATH (e.g., `?for<'a: 'b> m::Trait<'a>`)
436
434
/// ```
437
435
fn parse_generic_bound (
438
436
& mut self ,
@@ -454,22 +452,11 @@ impl<'a> Parser<'a> {
454
452
}
455
453
Ok ( Ok ( bound) )
456
454
} else {
457
- let lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
458
- let path = self . parse_path ( PathStyle :: Type ) ?;
459
- if has_parens {
460
- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
461
- }
462
- let poly_span = lo. to ( self . prev_span ) ;
455
+ let ( poly_span, bound) = self . parse_generic_ty_bound ( lo, has_parens, question) ?;
463
456
if is_negative {
464
457
Ok ( Err ( last_plus_span. or ( colon_span) . map ( |sp| sp. to ( poly_span) ) ) )
465
458
} else {
466
- let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, poly_span) ;
467
- let modifier = if question. is_some ( ) {
468
- TraitBoundModifier :: Maybe
469
- } else {
470
- TraitBoundModifier :: None
471
- } ;
472
- Ok ( Ok ( GenericBound :: Trait ( poly_trait, modifier) ) )
459
+ Ok ( Ok ( bound) )
473
460
}
474
461
}
475
462
}
@@ -501,6 +488,28 @@ impl<'a> Parser<'a> {
501
488
Ok ( ( ) )
502
489
}
503
490
491
+ /// Parses a type bound according to:
492
+ /// ```
493
+ /// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)
494
+ /// TY_BOUND_NOPAREN = [?] [for<LT_PARAM_DEFS>] SIMPLE_PATH (e.g., `?for<'a: 'b> m::Trait<'a>`)
495
+ /// ```
496
+ fn parse_generic_ty_bound (
497
+ & mut self ,
498
+ lo : Span ,
499
+ has_parens : bool ,
500
+ question : Option < Span > ,
501
+ ) -> PResult < ' a , ( Span , GenericBound ) > {
502
+ let lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
503
+ let path = self . parse_path ( PathStyle :: Type ) ?;
504
+ if has_parens {
505
+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
506
+ }
507
+ let poly_span = lo. to ( self . prev_span ) ;
508
+ let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, poly_span) ;
509
+ let modifier = question. map_or ( TraitBoundModifier :: None , |_| TraitBoundModifier :: Maybe ) ;
510
+ Ok ( ( poly_span, GenericBound :: Trait ( poly_trait, modifier) ) )
511
+ }
512
+
504
513
pub ( super ) fn parse_late_bound_lifetime_defs ( & mut self ) -> PResult < ' a , Vec < GenericParam > > {
505
514
if self . eat_keyword ( kw:: For ) {
506
515
self . expect_lt ( ) ?;
0 commit comments