Skip to content

Rustfmt moves comment from one import to another #5485

Closed as not planned
Closed as not planned
@RalfJung

Description

@RalfJung

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions