-
-
Notifications
You must be signed in to change notification settings - Fork 328
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
Make all source files visible to rustfmt #1398
Make all source files visible to rustfmt #1398
Conversation
@@ -116,6 +116,16 @@ mod debug; | |||
mod serde; | |||
pub(crate) mod utils; | |||
|
|||
// Make formattable by rustfmt. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So just to confirm: this cfg
is always evaluated to false
but at least it allows rustfmt
to see the file. That's a super clever trick. Thanks for that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right.
In the longer term, hopefully rustfmt will get a built-in understanding of the syntax of cfg_if!
(rust-lang/rustfmt#3253) or cfg_match!
(rust-lang/rust#115585) and the workaround won't be needed.
Or alternatively, someone might make an alternative macro that doesn't rely on dedicated rustfmt support for its syntax, something like:
#[apply_cfg]
enum __ {
r#if = #[cfg(feature = "unknown-ci")]
{
// This is used in CI to check that the build for unknown targets is compiling fine.
mod unknown;
use crate::unknown as sys;
#[cfg(test)]
pub(crate) const MIN_USERS: usize = 0;
},
r#else = #[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "linux",
target_os = "android",
target_os = "freebsd"
))]
{
mod unix;
use crate::unix::sys;
#[cfg(feature = "network")]
mod network;
#[cfg(feature = "network")]
use crate::unix::network_helper;
#[cfg(test)]
pub(crate) const MIN_USERS: usize = 1;
},
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the current solution. It duplicates code but at least it's "easy" to see what's going on. Gonna check with rustfmt team if they'd be open to add some special cases for macros like cfg_if!
.
Makes me a bit sad to have all these manual imports but the code formatting is finally working, thanks a lot! Gonna open an issue on rustfmt to see if they can work with |
The pervasive reliance on
cfg_if!
, which is not understandable by rustfmt, was leading to only 18/81 source files in this crate able to be covered bycargo fmt
. This PR works around that and formats the other 63 files.