Skip to content

Commit 9de7de8

Browse files
authored
Rollup merge of rust-lang#37367 - jseyfried:import_crate_root, r=nrc
Support `use *;` and `use ::*;`. Fixes rust-lang#31484. r? @nrc
2 parents 5bc5647 + 4a93648 commit 9de7de8

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/libsyntax/parse/parser.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -6113,15 +6113,20 @@ impl<'a> Parser<'a> {
61136113
/// MOD_SEP? LBRACE item_seq RBRACE
61146114
fn parse_view_path(&mut self) -> PResult<'a, P<ViewPath>> {
61156115
let lo = self.span.lo;
6116-
if self.check(&token::OpenDelim(token::Brace)) || self.is_import_coupler() {
6117-
// `{foo, bar}` or `::{foo, bar}`
6116+
if self.check(&token::OpenDelim(token::Brace)) || self.check(&token::BinOp(token::Star)) ||
6117+
self.is_import_coupler() {
6118+
// `{foo, bar}`, `::{foo, bar}`, `*`, or `::*`.
61186119
let prefix = ast::Path {
61196120
global: self.eat(&token::ModSep),
61206121
segments: Vec::new(),
61216122
span: mk_sp(lo, self.span.hi),
61226123
};
6123-
let items = self.parse_path_list_items()?;
6124-
Ok(P(spanned(lo, self.span.hi, ViewPathList(prefix, items))))
6124+
let view_path_kind = if self.eat(&token::BinOp(token::Star)) {
6125+
ViewPathGlob(prefix)
6126+
} else {
6127+
ViewPathList(prefix, self.parse_path_list_items()?)
6128+
};
6129+
Ok(P(spanned(lo, self.span.hi, view_path_kind)))
61256130
} else {
61266131
let prefix = self.parse_path(PathStyle::Mod)?;
61276132
if self.is_import_coupler() {

src/test/run-pass/import-glob-crate.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
12-
#![allow(dead_assignment)]
13-
1411
use std::mem::*;
1512

1613
pub fn main() {
@@ -20,3 +17,12 @@ pub fn main() {
2017
assert_eq!(x, 2);
2118
assert_eq!(y, 1);
2219
}
20+
21+
#[allow(unused)]
22+
fn f() {
23+
mod foo { pub use *; }
24+
mod bar { pub use ::*; }
25+
26+
foo::main();
27+
bar::main();
28+
}

0 commit comments

Comments
 (0)