@@ -4086,32 +4086,37 @@ impl<'a> Parser<'a> {
40864086 fn parse_ty_param_bounds_common ( & mut self , allow_plus : bool ) -> PResult < ' a , TyParamBounds > {
40874087 let mut bounds = Vec :: new ( ) ;
40884088 loop {
4089- let has_parens = self . eat ( & token:: OpenDelim ( token:: Paren ) ) ;
4090- let question = if self . eat ( & token:: Question ) { Some ( self . prev_span ) } else { None } ;
4091- if self . check_lifetime ( ) {
4092- if let Some ( question_span) = question {
4093- self . span_err ( question_span,
4094- "`?` may only modify trait bounds, not lifetime bounds" ) ;
4095- }
4096- bounds. push ( RegionTyParamBound ( self . expect_lifetime ( ) ) ) ;
4097- if has_parens {
4098- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
4099- self . span_err ( self . prev_span ,
4100- "parenthesized lifetime bounds are not supported" ) ;
4101- }
4102- } else if self . check_keyword ( keywords:: For ) || self . check_path ( ) {
4103- let lo = self . span ;
4104- let lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
4105- let path = self . parse_path ( PathStyle :: Type ) ?;
4106- let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, lo. to ( self . prev_span ) ) ;
4107- let modifier = if question. is_some ( ) {
4108- TraitBoundModifier :: Maybe
4089+ let is_bound_start = self . check_path ( ) || self . check_lifetime ( ) ||
4090+ self . check ( & token:: Question ) ||
4091+ self . check_keyword ( keywords:: For ) ||
4092+ self . check ( & token:: OpenDelim ( token:: Paren ) ) ;
4093+ if is_bound_start {
4094+ let has_parens = self . eat ( & token:: OpenDelim ( token:: Paren ) ) ;
4095+ let question = if self . eat ( & token:: Question ) { Some ( self . prev_span ) } else { None } ;
4096+ if self . token . is_lifetime ( ) {
4097+ if let Some ( question_span) = question {
4098+ self . span_err ( question_span,
4099+ "`?` may only modify trait bounds, not lifetime bounds" ) ;
4100+ }
4101+ bounds. push ( RegionTyParamBound ( self . expect_lifetime ( ) ) ) ;
41094102 } else {
4110- TraitBoundModifier :: None
4111- } ;
4112- bounds. push ( TraitTyParamBound ( poly_trait, modifier) ) ;
4103+ let lo = self . span ;
4104+ let lifetime_defs = self . parse_late_bound_lifetime_defs ( ) ?;
4105+ let path = self . parse_path ( PathStyle :: Type ) ?;
4106+ let poly_trait = PolyTraitRef :: new ( lifetime_defs, path, lo. to ( self . prev_span ) ) ;
4107+ let modifier = if question. is_some ( ) {
4108+ TraitBoundModifier :: Maybe
4109+ } else {
4110+ TraitBoundModifier :: None
4111+ } ;
4112+ bounds. push ( TraitTyParamBound ( poly_trait, modifier) ) ;
4113+ }
41134114 if has_parens {
41144115 self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
4116+ if let Some ( & RegionTyParamBound ( ..) ) = bounds. last ( ) {
4117+ self . span_err ( self . prev_span ,
4118+ "parenthesized lifetime bounds are not supported" ) ;
4119+ }
41154120 }
41164121 } else {
41174122 break
0 commit comments