-
Notifications
You must be signed in to change notification settings - Fork 888
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
bug: imports_granularity = "Module"/"Crate"/"One" crash code when de-duplicate dependencies #5131
Comments
Can you provide a reproducible example? |
Ok, will do it soon. |
I created a repo to reproduce this bug: https://github.com/Sunt-ing/rustfmt_bug_example |
Consider creating a single file for this issue, which is easier to test and reproduce. e.g., https://github.com/rust-lang/rustfmt/blob/master/tests/source/imports_granularity_crate.rs |
@skyzh Good advice. I will try to do that. |
@skyzh Since the bug occurs when imports_granularity = "Module", I think it's hard to reproduce it within a single file. I'd like to leave it to the one who wants to fix it after the bug is verified. He or she could create such a file as a test. |
In fact, rustfmt always accept a single file as input, and |
OK, I created one. This code snippet will crash if you format it with any one of the following options:
Yes, imports_granularity = "Item" will not crash it. #![allow(dead_code)]
mod a {
pub mod b {
pub struct Data {
pub a: i32,
}
}
use crate::a::b::Data;
use crate::a::b::Data as Data2;
pub fn data(a: i32) -> Data {
Data { a }
}
pub fn data2(a: i32) -> Data2 {
Data2 { a }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
pub fn test() {
data(1);
data2(1);
}
}
} |
Recently, I enabled a rustfmt rule:
After I re-fmt, the code failed to be compiled. And thus I found an unexpected rustfmt behaviour:
before fmt:
after fmt:
But the codes that use "DataType" are not changed.
I don't think that rustfmt should turn the correct code into incorrect in any condition.
The text was updated successfully, but these errors were encountered: