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

Rustfmt wrongly alphabatizes raw identifiers in use statements #5362

Closed
InsertCreativityHere opened this issue Jun 1, 2022 · 1 comment · Fixed by #5384
Closed

Rustfmt wrongly alphabatizes raw identifiers in use statements #5362

InsertCreativityHere opened this issue Jun 1, 2022 · 1 comment · Fixed by #5384
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-imports `use` syntax duplicate

Comments

@InsertCreativityHere
Copy link

Description

I'm writing a toy compiler, and recently split up the elements of my grammar into their own modules.
Unfortunately, there's overlap between the elements and some Rust keywords, so sometimes I need to use raw identifiers:

use self::r#enum::*;
use self::interface::*;
use self::struct::*;

I would expect these to be sorted alphabetically, not including the r#
But, rustfmt seems to include it when sorting, and changes this to:

use self::interface::*;
use self::r#enum::*;
use self::struct::*;

Note that this doesn't happen with modules:

mod r#enum;
mod interface;
mod struct;

here rustfmt correctly ignores the r# prefix when sorting.

I'm open to fixing this, if someone could point me in the right direction! Since it seems *crosses fingers* like an easy fix.

Environment

rustfmt 1.4.38-nightly (e0944922 2022-05-31) on macOS Monterey

@calebcartwright
Copy link
Member

Thanks for reaching out and being willing to work on it!

Fortunately (perhaps), this is one that was actually already reported (see #3791) and fixed in source control a while ago (and #3795).

However, the fix was made on a different branch that hasn't been pulled in yet. The only outstanding issue is that it technically qualifies as a formatting change which we have to gate against, and no one has had the time/motivation to figure out how to apply the gating yet.

Definitely feel free to take a look at the old PR, you may be able to cherry-pick the commit and apply @ytmimi's suggestion from #3795 (comment) to gate the change, and let us know if you have any questions.

@ytmimi ytmimi mentioned this issue Jun 13, 2022
@ytmimi ytmimi added the 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release label Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-imports `use` syntax duplicate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants