Skip to content

Commit f0ab4a4

Browse files
authored
Auto merge of #37367 - jseyfried:import_crate_root, r=nrc
Support `use *;` and `use ::*;`. Fixes #31484. r? @nrc
2 parents 421b595 + 4a93648 commit f0ab4a4

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
@@ -6145,15 +6145,20 @@ impl<'a> Parser<'a> {
61456145
/// MOD_SEP? LBRACE item_seq RBRACE
61466146
fn parse_view_path(&mut self) -> PResult<'a, P<ViewPath>> {
61476147
let lo = self.span.lo;
6148-
if self.check(&token::OpenDelim(token::Brace)) || self.is_import_coupler() {
6149-
// `{foo, bar}` or `::{foo, bar}`
6148+
if self.check(&token::OpenDelim(token::Brace)) || self.check(&token::BinOp(token::Star)) ||
6149+
self.is_import_coupler() {
6150+
// `{foo, bar}`, `::{foo, bar}`, `*`, or `::*`.
61506151
let prefix = ast::Path {
61516152
global: self.eat(&token::ModSep),
61526153
segments: Vec::new(),
61536154
span: mk_sp(lo, self.span.hi),
61546155
};
6155-
let items = self.parse_path_list_items()?;
6156-
Ok(P(spanned(lo, self.span.hi, ViewPathList(prefix, items))))
6156+
let view_path_kind = if self.eat(&token::BinOp(token::Star)) {
6157+
ViewPathGlob(prefix)
6158+
} else {
6159+
ViewPathList(prefix, self.parse_path_list_items()?)
6160+
};
6161+
Ok(P(spanned(lo, self.span.hi, view_path_kind)))
61576162
} else {
61586163
let prefix = self.parse_path(PathStyle::Mod)?;
61596164
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)