When I format the following code using rustfmt src/cmds.rs (with rustfmt 1.5.2-stable (8ede3aa 2023-07-12)) I get invalid code.
Original valid code:
impl SwayrCommand {
fn is_scripting_command(&self) -> bool {
matches!(
self,
| SwayrCommand::GetWindowsAsJson { .. }
| SwayrCommand::ForEachWindow { .. }
)
}
}
Invalid code after formatting:
impl SwayrCommand {
fn is_scripting_command(&self) -> bool {
matches!(self, |SwayrCommand::GetWindowsAsJson { .. }| {
SwayrCommand::ForEachWindow { .. }
})
}
}
The issue seems to be caused by the pipe | before the first alternative which is probably uncommon but legal.
I hoped I could fix the subjectively strange indentation of matches!() where the 2nd to last alternative are indented much more than the first that way. I.e., that's what I get now
impl SwayrCommand {
fn is_scripting_command(&self) -> bool {
matches!(
self,
SwayrCommand::GetWindowsAsJson { .. }
| SwayrCommand::ForEachWindow { .. }
| SwayrCommand::ForEachWindow2 { .. }
| SwayrCommand::ForEachWindow4 { .. }
)
}
}
and what would please me more would be
impl SwayrCommand {
fn is_scripting_command(&self) -> bool {
matches!(
self,
SwayrCommand::GetWindowsAsJson { .. }
| SwayrCommand::ForEachWindow { .. }
| SwayrCommand::ForEachWindow2 { .. }
| SwayrCommand::ForEachWindow4 { .. }
)
}
}
and by prefixing even the first alternative with a pipe, I would get
impl SwayrCommand {
fn is_scripting_command(&self) -> bool {
matches!(
self,
| SwayrCommand::GetWindowsAsJson { .. }
| SwayrCommand::ForEachWindow { .. }
| SwayrCommand::ForEachWindow2 { .. }
| SwayrCommand::ForEachWindow4 { .. }
)
}
}
which is as aesthetically pleasing as the wished-for version.
When I format the following code using
rustfmt src/cmds.rs(with rustfmt 1.5.2-stable (8ede3aa 2023-07-12)) I get invalid code.Original valid code:
Invalid code after formatting:
The issue seems to be caused by the pipe
|before the first alternative which is probably uncommon but legal.I hoped I could fix the subjectively strange indentation of
matches!()where the 2nd to last alternative are indented much more than the first that way. I.e., that's what I get nowand what would please me more would be
and by prefixing even the first alternative with a pipe, I would get
which is as aesthetically pleasing as the wished-for version.