Description
I'm trying to format code for the druid project.
Everything was working fine up until Rust 1.43.1 / rustfmt 1.4.12-stable (a828ffe 2020-03-11).
It no longer works properly with:
Rust 1.44.0 / rustfmt 1.4.14-stable (e417356 2020-04-21)
Rust 1.44.1 / rustfmt 1.4.16-stable (939e164 2020-06-11)
It does not seem to be platform dependant, the issue exists at minimum both on Windows 7 and macOS Catalina, and not just my machines.
The druid workspace consists of several packages including druid-shell
which is the package that is problematic.
If I run cargo fmt
inside the druid-shell
package root then it works.
The problem is with using cargo fmt
or cargo fmt --all
in the workspace directory.
That used to also work, but now works only partially on druid-shell
.
Some of the modules get formatted while others don't.
It seems to have something to do with the cfg-if
macro.
A file of interest is druid-shell/src/platform/mod.rs
, which has the following code:
cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
mod windows;
pub use windows::*;
} else if #[cfg(target_os = "macos")] {
mod mac;
pub use mac::*;
} else if #[cfg(all(feature = "x11", target_os = "linux"))] {
mod x11;
pub use x11::*;
} else if #[cfg(target_os = "linux")] {
mod gtk;
pub use self::gtk::*;
} else if #[cfg(target_arch = "wasm32")] {
mod web;
pub use web::*;
}
}
If I delete that macro and replace it with a simple:
mod windows;
pub use windows::*;
Then the windows
module gets formatted when I run cargo fmt
in the workspace directory. However if the cfg-if
macro is there, then none of these platform modules get formatted. Again, this is a recent regression and previously all those platform modules got formatted.
Any insight would be appreciated.