Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2125ad2

Browse files
committed
fix glob and nested global imports
1 parent a2bfc02 commit 2125ad2

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/imports.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ impl UseTree {
338338

339339
match a.kind {
340340
UseTreeKind::Glob => {
341+
// in case of a global path and the glob starts at the root, e.g., "::*"
342+
if a.prefix.segments.len() == 1 && leading_modsep {
343+
result.path.push(UseSegment::Ident("".to_owned(), None));
344+
}
341345
result.path.push(UseSegment::Glob);
342346
}
343347
UseTreeKind::Nested(ref list) => {
@@ -356,6 +360,11 @@ impl UseTree {
356360
false,
357361
)
358362
.collect();
363+
// in case of a global path and the nested list starts at the root,
364+
// e.g., "::{foo, bar}"
365+
if a.prefix.segments.len() == 1 && leading_modsep {
366+
result.path.push(UseSegment::Ident("".to_owned(), None));
367+
}
359368
result.path.push(UseSegment::List(
360369
list.iter()
361370
.zip(items.into_iter())

tests/source/issue-3241.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// rustfmt-edition: 2018
2+
3+
use ::ignore;
4+
use ::ignore::some::more;
5+
use ::{foo, bar};
6+
use ::*;
7+
use ::baz::{foo, bar};
8+
9+
fn main() {
10+
println!("Hello, world!");
11+
}

tests/target/issue-3241.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// rustfmt-edition: 2018
2+
3+
use ::baz::{bar, foo};
4+
use ::ignore;
5+
use ::ignore::some::more;
6+
use ::*;
7+
use ::{bar, foo};
8+
9+
fn main() {
10+
println!("Hello, world!");
11+
}

0 commit comments

Comments
 (0)