-
Notifications
You must be signed in to change notification settings - Fork 898
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
Formatting with merge_imports creates invalid Rust #3321
Comments
Note that since the input is semantically incorrect, rustfmt is not guaranteed to produce the valid Rust code. |
@topecongiro Thanks for pointing out that my example is already invalid code. It was late when I posted this. |
Input use std::fmt::{self, Display};
use std::fmt;
fn main() {
println!("Hello, world!");
} Outupt use std::{
fmt,
fmt::{self, Display},
};
fn main() {
println!("Hello, world!");
} Trying to compile either the Input or the Output with rustc leads to compilation issues. @calebcartwright do you think there is any actions we can take here since |
Linking the |
I'm going to close as there's no action to be taken. The title is misleading, as the only thing that's happening is that rustfmt is not converting invalid rust code to valid rust code by deduping an import, but that is intentional as it's not a change rustfmt can make because doing so is not always semantics preserving and can actually convert valid rust code to invalid rust code. |
As noted below the before version is already not valid Rust. However, it would be nice if it could be supported because I run into such cases during refactoring or adding new code.
I use
merge_imports
to keep the imports looking clean and sometimes I want to merge different sets of imports. Then it can happen that duplicates arise. This is normally handled well, in that duplicates are merged, just not here.Before rustfmt:
After rustfmt:
rustc error after formatting:
rustfmt.toml
rustc + rustfmt versions
The text was updated successfully, but these errors were encountered: