Skip to content

Commit 6b23c22

Browse files
committed
syntax: refactor with new fn parse_use_tree_glob_or_nested.
1 parent 9c6582a commit 6b23c22

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/libsyntax/parse/parser/item.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1077,21 +1077,13 @@ impl<'a> Parser<'a> {
10771077
);
10781078
}
10791079

1080-
if self.eat(&token::BinOp(token::Star)) {
1081-
UseTreeKind::Glob
1082-
} else {
1083-
UseTreeKind::Nested(self.parse_use_tree_list()?)
1084-
}
1080+
self.parse_use_tree_glob_or_nested()?
10851081
} else {
10861082
// `use path::*;` or `use path::{...};` or `use path;` or `use path as bar;`
10871083
prefix = self.parse_path(PathStyle::Mod)?;
10881084

10891085
if self.eat(&token::ModSep) {
1090-
if self.eat(&token::BinOp(token::Star)) {
1091-
UseTreeKind::Glob
1092-
} else {
1093-
UseTreeKind::Nested(self.parse_use_tree_list()?)
1094-
}
1086+
self.parse_use_tree_glob_or_nested()?
10951087
} else {
10961088
UseTreeKind::Simple(self.parse_rename()?, DUMMY_NODE_ID, DUMMY_NODE_ID)
10971089
}
@@ -1100,6 +1092,15 @@ impl<'a> Parser<'a> {
11001092
Ok(UseTree { prefix, kind, span: lo.to(self.prev_span) })
11011093
}
11021094

1095+
/// Parses `*` or `{...}`.
1096+
fn parse_use_tree_glob_or_nested(&mut self) -> PResult<'a, UseTreeKind> {
1097+
Ok(if self.eat(&token::BinOp(token::Star)) {
1098+
UseTreeKind::Glob
1099+
} else {
1100+
UseTreeKind::Nested(self.parse_use_tree_list()?)
1101+
})
1102+
}
1103+
11031104
/// Parses a `UseTreeKind::Nested(list)`.
11041105
///
11051106
/// ```

0 commit comments

Comments
 (0)