Skip to content

Commit

Permalink
Update tests for imports_granularity=Item.
Browse files Browse the repository at this point in the history
  • Loading branch information
msmorgan committed Jan 14, 2021
1 parent ba12968 commit ae2735e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
5 changes: 5 additions & 0 deletions src/formatting/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ impl UseTree {
for flattened in &mut nested_use_tree.clone().flatten() {
let mut new_path = prefix.to_vec();
new_path.append(&mut flattened.path);
if flattened.path.len() == 1 {
if let UseSegment::Slf(..) = flattened.path[0] {
new_path.pop();
}
}
result.push(UseTree {
path: new_path,
span: self.span,
Expand Down
5 changes: 5 additions & 0 deletions src/formatting/reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ fn rewrite_reorderable_or_regroupable_items(
}
ImportGranularity::Preserve => normalized_items,
};
for item in normalized_items.iter_mut() {
if let Some(UseSegment::Slf(None)) = item.path.last() {
item.path.pop();
}
}

let mut regrouped_items = match context.config.group_imports() {
GroupImportsTactic::Preserve => vec![normalized_items],
Expand Down
6 changes: 6 additions & 0 deletions tests/source/imports_granularity_item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-imports_granularity: Item

use a::{b, c, d};
use a::{f::g, h::{i, j}};
use a::{l::{self, m, n::o, p::*}};
use a::q::{self};
32 changes: 11 additions & 21 deletions tests/target/imports_granularity_item.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
// rustfmt-imports_granularity: Item

use a::b::c;
use a::d::e;
use a::f;
use a::g::h;
use a::g::i;
use a::j;
use a::j::k;
use a::j::k::l;
use a::j::m;
use a::n::o::p;
use a::n::q;
pub use a::r::s;
pub use a::t;

use foo::e;
#[cfg(test)]
use foo::{a::b, c::d};

use bar::a::b;
use bar::c::d;
use bar::e::f;
use a::b;
use a::c;
use a::d;
use a::f::g;
use a::h::i;
use a::h::j;
use a::l;
use a::l::m;
use a::l::n::o;
use a::l::p::*;
use a::q::{self};

0 comments on commit ae2735e

Please sign in to comment.