Skip to content

Commit e08886d

Browse files
committed
extract parse_typeof_ty
1 parent 211560d commit e08886d

File tree

1 file changed

+11
-7
lines changed
  • src/librustc_parse/parser

1 file changed

+11
-7
lines changed

src/librustc_parse/parser/ty.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,7 @@ impl<'a> Parser<'a> {
8787
self.expect_and()?;
8888
self.parse_borrowed_pointee()?
8989
} 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()?
9691
} else if self.eat_keyword(kw::Underscore) {
9792
// A type to be inferred `_`
9893
TyKind::Infer
@@ -268,7 +263,16 @@ impl<'a> Parser<'a> {
268263
let opt_lifetime = if self.check_lifetime() { Some(self.expect_lifetime()) } else { None };
269264
let mutbl = self.parse_mutability();
270265
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))
272276
}
273277

274278
/// Is the current token one of the keywords that signals a bare function type?

0 commit comments

Comments
 (0)