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

group_imports reorders use statements arounds comments, changing their meaning #6241

Open
RalfJung opened this issue Jul 14, 2024 · 1 comment
Labels
a-comments a-imports `use` syntax only-with-option requires a non-default option value to reproduce

Comments

@RalfJung
Copy link
Member

This is similar to #3720, but for group_imports settings such as StdExternalCrate. rust-lang/rust#126776 shows the consequences of that: it is now impossible to have a "chunk" of use statements that have a comment above them. rustfmt will happily reorder them and keep the comment attached to the immediate use item after it, therefore fundamentally changing its meaning. That's extremely frustrating -- having the tool make it essentially impossible to have comments that clarify the intent of my code.

In situations like this:

use a;
use b;
use c;

// comment
use d;
use e;

rustfmt should view the comment as "breaking apart" the use block into multiple blocks, similar to what it does if there was something else, like a mod, in place of the comment. group_imports should then be applied to both groups separately. That would avoid such semantics-altering reformatting.

@ytmimi ytmimi added a-comments a-imports `use` syntax only-with-option requires a non-default option value to reproduce labels Jul 15, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Jul 15, 2024

Linking the tracking issue for group_imports #5083

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments a-imports `use` syntax only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

No branches or pull requests

2 participants