@@ -73,8 +73,8 @@ impl<'a> Parser<'a> {
73
73
74
74
let lo = self . token . span ;
75
75
let mut impl_dyn_multi = false ;
76
- let kind = if self . eat ( & token:: OpenDelim ( token:: Paren ) ) {
77
- self . parse_ty_tuple_or_parens ( allow_plus) ?
76
+ let kind = if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
77
+ self . parse_ty_tuple_or_parens ( lo , allow_plus) ?
78
78
} else if self . eat ( & token:: Not ) {
79
79
// Never type `!`
80
80
TyKind :: Never
@@ -208,34 +208,26 @@ impl<'a> Parser<'a> {
208
208
/// Parses either:
209
209
/// - `(TYPE)`, a parenthesized type.
210
210
/// - `(TYPE,)`, a tuple with a single field of type TYPE.
211
- fn parse_ty_tuple_or_parens ( & mut self , allow_plus : bool ) -> PResult < ' a , TyKind > {
212
- let lo = self . token . span ;
213
- let mut ts = vec ! [ ] ;
214
- let mut last_comma = false ;
215
- while self . token != token:: CloseDelim ( token:: Paren ) {
216
- ts. push ( self . parse_ty ( ) ?) ;
217
- if self . eat ( & token:: Comma ) {
218
- last_comma = true ;
219
- } else {
220
- last_comma = false ;
221
- break ;
222
- }
223
- }
224
- let trailing_plus = self . prev_token_kind == PrevTokenKind :: Plus ;
225
- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
211
+ fn parse_ty_tuple_or_parens ( & mut self , lo : Span , allow_plus : bool ) -> PResult < ' a , TyKind > {
212
+ let mut trailing_plus = false ;
213
+ let ( ts, trailing) = self . parse_paren_comma_seq ( |p| {
214
+ let ty = p. parse_ty ( ) ?;
215
+ trailing_plus = p. prev_token_kind == PrevTokenKind :: Plus ;
216
+ Ok ( ty)
217
+ } ) ?;
226
218
227
- if ts. len ( ) == 1 && !last_comma {
219
+ if ts. len ( ) == 1 && !trailing {
228
220
let ty = ts. into_iter ( ) . nth ( 0 ) . unwrap ( ) . into_inner ( ) ;
229
221
let maybe_bounds = allow_plus && self . token . is_like_plus ( ) ;
230
222
match ty. kind {
231
223
// `(TY_BOUND_NOPAREN) + BOUND + ...`.
232
- TyKind :: Path ( None , ref path) if maybe_bounds => {
233
- self . parse_remaining_bounds ( Vec :: new ( ) , path. clone ( ) , lo, true )
224
+ TyKind :: Path ( None , path) if maybe_bounds => {
225
+ self . parse_remaining_bounds ( Vec :: new ( ) , path, lo, true )
234
226
}
235
- TyKind :: TraitObject ( ref bounds, TraitObjectSyntax :: None )
236
- if maybe_bounds && bounds. len ( ) == 1 && !trailing_plus => {
237
- let path = match bounds[ 0 ] {
238
- GenericBound :: Trait ( ref pt, ..) => pt. trait_ref . path . clone ( ) ,
227
+ TyKind :: TraitObject ( mut bounds, TraitObjectSyntax :: None )
228
+ if maybe_bounds && bounds. len ( ) == 1 && !trailing_plus => {
229
+ let path = match bounds. remove ( 0 ) {
230
+ GenericBound :: Trait ( pt, ..) => pt. trait_ref . path ,
239
231
GenericBound :: Outlives ( ..) => self . bug ( "unexpected lifetime bound" ) ,
240
232
} ;
241
233
self . parse_remaining_bounds ( Vec :: new ( ) , path, lo, true )
0 commit comments