-
Notifications
You must be signed in to change notification settings - Fork 972
Open
Labels
A-macrosArea: macros (procedural macros, macro_rules! macros, etc.)Area: macros (procedural macros, macro_rules! macros, etc.)C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICECategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE
Description
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.
tsdh
Metadata
Metadata
Assignees
Labels
A-macrosArea: macros (procedural macros, macro_rules! macros, etc.)Area: macros (procedural macros, macro_rules! macros, etc.)C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICECategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE