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 moves comment from one import to another #5485

Closed
RalfJung opened this issue Aug 6, 2022 · 1 comment
Closed

Rustfmt moves comment from one import to another #5485

RalfJung opened this issue Aug 6, 2022 · 1 comment

Comments

@RalfJung
Copy link
Member

RalfJung commented Aug 6, 2022

Here is a case where rustfmt, as part of reordering imports, literally moves a comment from one import to another, entirely destroying its meaning:

mod realstd {
    struct __FastLocalKeyInner;
}
mod local {
    mod fast {
        struct Key;
    }
}

#[cfg(test)] // comment associated with realstd import
pub use realstd::thread::__FastLocalKeyInner;
#[cfg(test)]
pub use self::local::fast::Key as __FastLocalKeyInnerUnused; // comment associated with fast import

fn main() {}

After formatting, the imports look like

#[cfg(test)]
pub use self::local::fast::Key as __FastLocalKeyInnerUnused;
#[cfg(test)] // comment associated with realstd import
pub use realstd::thread::__FastLocalKeyInner; // comment associated with fast import

Not that the comment that explained the use self::local::fast::Key as, got moved to the other use!

This is with rustfmt 1.5.1-nightly (2022-08-05 affe0d3).

@ytmimi
Copy link
Contributor

ytmimi commented Aug 6, 2022

closing as a duplicate of #3720

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants