about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-10-07 06:31:02 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-10-07 06:47:24 +0200
commit6b23c22ccad4044476b65fc8f3e32794f1884781 (patch)
treea9a3726d82f50f1b45ecdc047406e33b5b11cee0 /src/libsyntax
parent9c6582a2c0c5a527e3fc3ce581244d85b3b71761 (diff)
downloadrust-6b23c22ccad4044476b65fc8f3e32794f1884781.tar.gz
rust-6b23c22ccad4044476b65fc8f3e32794f1884781.zip
syntax: refactor with new `fn parse_use_tree_glob_or_nested`.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/parse/parser/item.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/libsyntax/parse/parser/item.rs b/src/libsyntax/parse/parser/item.rs
index d2ea0829595..3c60c88e2aa 100644
--- a/src/libsyntax/parse/parser/item.rs
+++ b/src/libsyntax/parse/parser/item.rs
@@ -1077,21 +1077,13 @@ impl<'a> Parser<'a> {
                 );
             }
 
-            if self.eat(&token::BinOp(token::Star)) {
-                UseTreeKind::Glob
-            } else {
-                UseTreeKind::Nested(self.parse_use_tree_list()?)
-            }
+            self.parse_use_tree_glob_or_nested()?
         } else {
             // `use path::*;` or `use path::{...};` or `use path;` or `use path as bar;`
             prefix = self.parse_path(PathStyle::Mod)?;
 
             if self.eat(&token::ModSep) {
-                if self.eat(&token::BinOp(token::Star)) {
-                    UseTreeKind::Glob
-                } else {
-                    UseTreeKind::Nested(self.parse_use_tree_list()?)
-                }
+                self.parse_use_tree_glob_or_nested()?
             } else {
                 UseTreeKind::Simple(self.parse_rename()?, DUMMY_NODE_ID, DUMMY_NODE_ID)
             }
@@ -1100,6 +1092,15 @@ impl<'a> Parser<'a> {
         Ok(UseTree { prefix, kind, span: lo.to(self.prev_span) })
     }
 
+    /// Parses `*` or `{...}`.
+    fn parse_use_tree_glob_or_nested(&mut self) -> PResult<'a, UseTreeKind> {
+        Ok(if self.eat(&token::BinOp(token::Star)) {
+            UseTreeKind::Glob
+        } else {
+            UseTreeKind::Nested(self.parse_use_tree_list()?)
+        })
+    }
+
     /// Parses a `UseTreeKind::Nested(list)`.
     ///
     /// ```