-
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
rustfmt removes import if it only contains comments #5899
Comments
@rsammelson any interest in helping out with this one since you also worked on #5853? |
I also noticed that comments aren't necessary to trigger this. input use a::b::c::{}; output |
With the comment I would agree that this is definitely a bug, but without the comment isn't this desirable (just like removing the braces when they are unused; once the braces are gone it would be an invalid statement so it's just removed)? |
I found this comment that suggests that the case without any comments is intentional: Lines 537 to 543 in b636723
|
That's how I found the originally posted issue, I was trying to work around that behavior which I do not find desirable and would like if there was an option to disable. I would prefer that an unused import is preserved rather than deleted. This crops up for me while refactoring and prototyping with format-on-save, which results in having to retype it or go back in the undo-stack to find the deleted import (or disable formatting temporarily which is also inconvenient). |
@okaneco thanks for providing that additional context! |
Formatting deletes the import if all of the items are commented out.
Reproducible using
rustfmt 1.6.0-nightly (16db2a4b 2023-08-18)
andrustfmt 1.5.3-nightly (f4b80cac 2023-06-30)
. Likely other versions as well.input
output
expect
Originally posted by @okaneco in #5852 (comment)
The text was updated successfully, but these errors were encountered: