]> git.lizzy.rs Git - rust.git/commitdiff
extract parse_typeof_ty
authorMazdak Farrokhzad <twingoow@gmail.com>
Sun, 8 Dec 2019 07:23:10 +0000 (08:23 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 21 Dec 2019 18:20:41 +0000 (19:20 +0100)
src/librustc_parse/parser/ty.rs

index c3d934d3503270e822fbe012fcc5bdb7768d7ac5..624719d6ca53b0f4ad603273b53f596e77a604ec 100644 (file)
@@ -87,12 +87,7 @@ fn parse_ty_common(
             self.expect_and()?;
             self.parse_borrowed_pointee()?
         } else if self.eat_keyword_noexpect(kw::Typeof) {
-            // `typeof(EXPR)`
-            // In order to not be ambiguous, the type must be surrounded by parens.
-            self.expect(&token::OpenDelim(token::Paren))?;
-            let expr = self.parse_anon_const_expr()?;
-            self.expect(&token::CloseDelim(token::Paren))?;
-            TyKind::Typeof(expr)
+            self.parse_typeof_ty()?
         } else if self.eat_keyword(kw::Underscore) {
             // A type to be inferred `_`
             TyKind::Infer
@@ -268,7 +263,16 @@ fn parse_borrowed_pointee(&mut self) -> PResult<'a, TyKind> {
         let opt_lifetime = if self.check_lifetime() { Some(self.expect_lifetime()) } else { None };
         let mutbl = self.parse_mutability();
         let ty = self.parse_ty_no_plus()?;
-        return Ok(TyKind::Rptr(opt_lifetime, MutTy { ty, mutbl }));
+        Ok(TyKind::Rptr(opt_lifetime, MutTy { ty, mutbl }))
+    }
+
+    // Parses the `typeof(EXPR)`.
+    // To avoid ambiguity, the type is surrounded by parenthesis.
+    fn parse_typeof_ty(&mut self) -> PResult<'a, TyKind> {
+        self.expect(&token::OpenDelim(token::Paren))?;
+        let expr = self.parse_anon_const_expr()?;
+        self.expect(&token::CloseDelim(token::Paren))?;
+        Ok(TyKind::Typeof(expr))
     }
 
     /// Is the current token one of the keywords that signals a bare function type?