@@ -8,7 +8,7 @@ use rustc_error_codes::*;
8
8
use syntax:: ptr:: P ;
9
9
use syntax:: ast:: { self , Ty , TyKind , MutTy , BareFnTy , FunctionRetTy , GenericParam , Lifetime , Ident } ;
10
10
use syntax:: ast:: { TraitBoundModifier , TraitObjectSyntax , GenericBound , GenericBounds , PolyTraitRef } ;
11
- use syntax:: ast:: { Mutability , AnonConst , Mac } ;
11
+ use syntax:: ast:: { Mutability , Mac } ;
12
12
use syntax:: token:: { self , Token } ;
13
13
use syntax:: struct_span_err;
14
14
use syntax_pos:: source_map:: Span ;
@@ -81,18 +81,7 @@ impl<'a> Parser<'a> {
81
81
} else if self . eat ( & token:: BinOp ( token:: Star ) ) {
82
82
self . parse_ty_ptr ( ) ?
83
83
} else if self . eat ( & token:: OpenDelim ( token:: Bracket ) ) {
84
- // Array or slice
85
- let t = self . parse_ty ( ) ?;
86
- // Parse optional `; EXPR` in `[TYPE; EXPR]`
87
- let t = match self . maybe_parse_fixed_length_of_vec ( ) ? {
88
- None => TyKind :: Slice ( t) ,
89
- Some ( length) => TyKind :: Array ( t, AnonConst {
90
- id : ast:: DUMMY_NODE_ID ,
91
- value : length,
92
- } ) ,
93
- } ;
94
- self . expect ( & token:: CloseDelim ( token:: Bracket ) ) ?;
95
- t
84
+ self . parse_array_or_slice_ty ( ) ?
96
85
} else if self . check ( & token:: BinOp ( token:: And ) ) || self . check ( & token:: AndAnd ) {
97
86
// Reference
98
87
self . expect_and ( ) ?;
@@ -101,12 +90,9 @@ impl<'a> Parser<'a> {
101
90
// `typeof(EXPR)`
102
91
// In order to not be ambiguous, the type must be surrounded by parens.
103
92
self . expect ( & token:: OpenDelim ( token:: Paren ) ) ?;
104
- let e = AnonConst {
105
- id : ast:: DUMMY_NODE_ID ,
106
- value : self . parse_expr ( ) ?,
107
- } ;
93
+ let expr = self . parse_anon_const_expr ( ) ?;
108
94
self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
109
- TyKind :: Typeof ( e )
95
+ TyKind :: Typeof ( expr )
110
96
} else if self . eat_keyword ( kw:: Underscore ) {
111
97
// A type to be inferred `_`
112
98
TyKind :: Infer
@@ -265,12 +251,17 @@ impl<'a> Parser<'a> {
265
251
Ok ( TyKind :: Ptr ( MutTy { ty, mutbl } ) )
266
252
}
267
253
268
- fn maybe_parse_fixed_length_of_vec ( & mut self ) -> PResult < ' a , Option < P < ast:: Expr > > > {
269
- if self . eat ( & token:: Semi ) {
270
- Ok ( Some ( self . parse_expr ( ) ?) )
254
+ /// Parses an array (`[TYPE; EXPR]`) or slice (`[TYPE]`) type.
255
+ /// The opening `[` bracket is already eaten.
256
+ fn parse_array_or_slice_ty ( & mut self ) -> PResult < ' a , TyKind > {
257
+ let elt_ty = self . parse_ty ( ) ?;
258
+ let ty = if self . eat ( & token:: Semi ) {
259
+ TyKind :: Array ( elt_ty, self . parse_anon_const_expr ( ) ?)
271
260
} else {
272
- Ok ( None )
273
- }
261
+ TyKind :: Slice ( elt_ty)
262
+ } ;
263
+ self . expect ( & token:: CloseDelim ( token:: Bracket ) ) ?;
264
+ Ok ( ty)
274
265
}
275
266
276
267
fn parse_borrowed_pointee ( & mut self ) -> PResult < ' a , TyKind > {
0 commit comments