Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't merge crates when imports_granularity="Module" #6192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,12 @@ impl UseTree {
match shared_prefix {
SharedPrefix::Crate => self.path[0] == other.path[0],
SharedPrefix::Module => {
self.path[..self.path.len() - 1] == other.path[..other.path.len() - 1]
if self.path.len() == 1 && other.path.len() == 1 {
// When importing an entire crate, use the crate name for comparison.
self.path[0] == other.path[0]
} else {
self.path[..self.path.len() - 1] == other.path[..other.path.len() - 1]
}
}
SharedPrefix::One => true,
}
Expand Down
4 changes: 4 additions & 0 deletions tests/source/imports/imports_granularity_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ use b::v::{
};
use b::t::{/* Before b::t::self */ self};
use b::c;

// Issue #6191: grouping of top-level modules
use library1;
use {library2 as lib2, library3};
4 changes: 4 additions & 0 deletions tests/source/issue-6191.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// rustfmt-imports_granularity: Module

use library1;
use {library2 as lib2, library3};
5 changes: 5 additions & 0 deletions tests/target/imports/imports_granularity_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ use b::{
/* Before b::l group */ l::{self, m, n::o, p::*},
q,
};

// Issue #6191: grouping of top-level modules
use library1;
use library2 as lib2;
use library3;
5 changes: 5 additions & 0 deletions tests/target/issue-6191.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// rustfmt-imports_granularity: Module

use library1;
use library2 as lib2;
use library3;
Loading