Skip to content

Commit 47fc453

Browse files
committed
Update tests for imports_granularity=Item.
1 parent ba12968 commit 47fc453

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

src/formatting/imports.rs

+5
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ impl UseTree {
561561
for flattened in &mut nested_use_tree.clone().flatten() {
562562
let mut new_path = prefix.to_vec();
563563
new_path.append(&mut flattened.path);
564+
if flattened.path.len() == 1 {
565+
if let UseSegment::Slf(..) = flattened.path[0] {
566+
new_path.pop();
567+
}
568+
}
564569
result.push(UseTree {
565570
path: new_path,
566571
span: self.span,

src/formatting/reorder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ fn rewrite_reorderable_or_regroupable_items(
238238
}
239239
ImportGranularity::Preserve => normalized_items,
240240
};
241+
for item in normalized_items.iter_mut() {
242+
if let Some(UseSegment::Slf(None)) = item.path.last() {
243+
item.path.pop().unwrap();
244+
}
245+
}
241246

242247
let mut regrouped_items = match context.config.group_imports() {
243248
GroupImportsTactic::Preserve => vec![normalized_items],
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// rustfmt-imports_granularity: Item
2+
3+
use a::{b, c, d};
4+
use a::{f::g, h::{i, j}};
5+
use a::{l::{self, m, n::o, p::*}};
6+
use a::q::{self};
+11-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
// rustfmt-imports_granularity: Item
22

3-
use a::b::c;
4-
use a::d::e;
5-
use a::f;
6-
use a::g::h;
7-
use a::g::i;
8-
use a::j;
9-
use a::j::k;
10-
use a::j::k::l;
11-
use a::j::m;
12-
use a::n::o::p;
13-
use a::n::q;
14-
pub use a::r::s;
15-
pub use a::t;
16-
17-
use foo::e;
18-
#[cfg(test)]
19-
use foo::{a::b, c::d};
20-
21-
use bar::a::b;
22-
use bar::c::d;
23-
use bar::e::f;
3+
use a::b;
4+
use a::c;
5+
use a::d;
6+
use a::f::g;
7+
use a::h::i;
8+
use a::h::j;
9+
use a::l;
10+
use a::l::m;
11+
use a::l::n::o;
12+
use a::l::p::*;
13+
use a::q::{self};

0 commit comments

Comments
 (0)