rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
5.99k stars 882 forks source link

rustfmt seems to have stopped formatting files behind configurations? #4034

Open Lokathor opened 4 years ago

Lokathor commented 4 years ago

rustfmt 1.4.11-nightly (18382352 2019-12-03)

Recently all of my files that are behind config flags stopped formatting with cargo fmt, even if the code would be configured into a current build (eg: a cfg(windows) module on a windows machine).

topecongiro commented 4 years ago

@Lokathor Thank you for filing an issue! Is it possible to provide a link to the repository with which you have a problem?

Lokathor commented 4 years ago

Yes, the repo in question was https://github.com/Lokathor/vanadium

topecongiro commented 4 years ago

@Lokathor Thank you for sharing the problematic repository. It looks like the crate is using pick! macro, which rustfmt does not support yet:

pick! {
  if #[cfg(windows)] {
    mod windows;
    use windows as sys;
    type SysTerm = sys::WindowsTerminal;
  } else if #[cfg(unix)] {
    mod unix;
    use unix as sys;
    type SysTerm = sys::UnixTerminal;
  } else {
    compile_error!("This crate doesn't support this system.");
  }
}

Currently, rustfmt is only able to resolve modules that are declared inside macros.