Rustfmt: Don't erase a use with attributes attached

Created on 6 Aug 2017  Â·  2Comments  Â·  Source: rust-lang/rustfmt

I'm writing some platform code, and I have code like the following:

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use self::linux::{};

the pub use self::linux::{}; is a placeholder to match the uses that are on the other platforms (currently the Linux matches the macOS implementation, so they're both under the unix config…)

Running rustfmt erases the use line, producing:

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]

which in addition to being annoying, also changes the semantics of the program because now the attribute will attach to the next available item.

bug

Most helpful comment

I'm interested in trying to contribute a fix for this.

All 2 comments

hmm, I think we need to either delete the attribute if we delete the import, or not delete an import if it has an attribute. The latter sounds both easier and like it would be more helpful for you.

I'm interested in trying to contribute a fix for this.

Was this page helpful?
0 / 5 - 0 ratings