-
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
Comments on use statements incorrectly rearranged when use statements are rearranged #3720
Comments
I will add that this also has some issues with leading comments. The problem can be reproduced with two
produces
The problem seems to be in Simply extending the span to the end of the previous item and start of the next item I believe would fail because then the first and last item would "steal" comments belonging to other items. I'll take a better look when I have more time. I think it can be solved by very explicitly including the first pre- and last post-comments to |
I think this is the same bug: // original
use crate::text::TextApi;
// for doc use
#[allow(unused)]
use crate::text::TextApiExt;
use crate::macros::autoimpl;
// ——— rustfmt output ———
use crate::text::TextApi;
// for doc use
use crate::macros::autoimpl;
#[allow(unused)]
use crate::text::TextApiExt; |
related to #3127 |
#5485 is an example of this that I almost missed, where this meant a pretty fundamental change in the semantics of the comment. Is there a tag for "rustfmt does something to the source code that changes its meaning for human readers" (aka 'pretty critical')? |
To be honest I can't imagine anything comment related that would be considered critical, and even if it were, cases where comments are outright dropped would be viewed as more severe. I understand this is a source of frustration for those that encounter it, and I wish the option hadn't been stabilized given the gap with comments. However, there's no undoing the past, and this isn't something likely to be addressed in the near term. If you find yourself regularly running into this (presumably due to regular additions/removals of imports triggering order changes) then you may want to consider setting |
That is rather surprising to me. I view this as equally critical as if rustfmt had transformed compiling code into incorrect syntax -- actually probably more critical since these comment changes will not be auto-detected by the next build, they need careful human review. So IMO it's on the same level as, e.g., changing |
Folks are entitled to their own preferred priority and perceptions of criticality, but my prior comment stands relative to our position. This isn't widespread, has a perfectly viable workaround that's available on stable, and as always version control can be leveraged to check/detect diffs. |
I doubt the work-around of disabling Either way thanks for all your hard work on rustfmt! |
#4504 would likely tackle most (though perhaps not all) of these items. If someone wanted pick up those proposed changes and apply them against the current |
Input:
Expected:
Got:
The text was updated successfully, but these errors were encountered: