@@ -87,12 +87,7 @@ impl<'a> Parser<'a> {
87
87
self . expect_and ( ) ?;
88
88
self . parse_borrowed_pointee ( ) ?
89
89
} else if self . eat_keyword_noexpect ( kw:: Typeof ) {
90
- // `typeof(EXPR)`
91
- // In order to not be ambiguous, the type must be surrounded by parens.
92
- self . expect ( & token:: OpenDelim ( token:: Paren ) ) ?;
93
- let expr = self . parse_anon_const_expr ( ) ?;
94
- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
95
- TyKind :: Typeof ( expr)
90
+ self . parse_typeof_ty ( ) ?
96
91
} else if self . eat_keyword ( kw:: Underscore ) {
97
92
// A type to be inferred `_`
98
93
TyKind :: Infer
@@ -268,7 +263,16 @@ impl<'a> Parser<'a> {
268
263
let opt_lifetime = if self . check_lifetime ( ) { Some ( self . expect_lifetime ( ) ) } else { None } ;
269
264
let mutbl = self . parse_mutability ( ) ;
270
265
let ty = self . parse_ty_no_plus ( ) ?;
271
- return Ok ( TyKind :: Rptr ( opt_lifetime, MutTy { ty, mutbl } ) ) ;
266
+ Ok ( TyKind :: Rptr ( opt_lifetime, MutTy { ty, mutbl } ) )
267
+ }
268
+
269
+ // Parses the `typeof(EXPR)`.
270
+ // To avoid ambiguity, the type is surrounded by parenthesis.
271
+ fn parse_typeof_ty ( & mut self ) -> PResult < ' a , TyKind > {
272
+ self . expect ( & token:: OpenDelim ( token:: Paren ) ) ?;
273
+ let expr = self . parse_anon_const_expr ( ) ?;
274
+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
275
+ Ok ( TyKind :: Typeof ( expr) )
272
276
}
273
277
274
278
/// Is the current token one of the keywords that signals a bare function type?
0 commit comments