@@ -431,8 +431,6 @@ impl<'a> Parser<'a> {
431431 /// ```
432432 /// BOUND = TY_BOUND | LT_BOUND
433433 /// 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>`)
436434 /// ```
437435 fn parse_generic_bound (
438436 & mut self ,
@@ -454,22 +452,11 @@ impl<'a> Parser<'a> {
454452 }
455453 Ok ( Ok ( bound) )
456454 } 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) ?;
463456 if is_negative {
464457 Ok ( Err ( last_plus_span. or ( colon_span) . map ( |sp| sp. to ( poly_span) ) ) )
465458 } 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) )
473460 }
474461 }
475462 }
@@ -501,6 +488,28 @@ impl<'a> Parser<'a> {
501488 Ok ( ( ) )
502489 }
503490
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+
504513 pub ( super ) fn parse_late_bound_lifetime_defs ( & mut self ) -> PResult < ' a , Vec < GenericParam > > {
505514 if self . eat_keyword ( kw:: For ) {
506515 self . expect_lt ( ) ?;
0 commit comments