Possible suboptimal formatting on `if let` with multiple patterns
Open
Nobody has claimed this yet.
A-patterns
C-discussion
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
The indentation of the second pattern in these functions (especially the first one) looks kind of odd. I can look into fixing it if it should be fixed.
pub fn f(input_value: Test) -> (u8, u8) {
let intermediate = if let Test::OptionWithLongNameA { value1, value2, .. }
| Test::OptionWithLongNameB { value1, value2, .. } = input_value
{
(*value1, *value2)
} else {
unreachable!()
};
intermediate
}
pub fn g(input_value: Test) -> (u8, u8) {
let very_very_long_name_for_intermediate =
if let Test::OptionWithLongNameA { value1, value2, .. }
| Test::OptionWithLongNameB { value1, value2, .. } = input_value
{
(*value1, *value2)
} else {
unreachable!()
};
very_very_long_name_for_intermediate
}
pub fn h(long_input_value_name: Test) -> (u8, u8) {
if let Test::OptionWithLongNameA { value1, value2, .. }
| Test::OptionWithLongNameB { value1, value2, .. } = long_input_value_name
{
(*value1, *value2)
} else {
unreachable!()
}
}
enum Test {
OptionWithLongNameA { value1: u8, value2: u8, value3: u8 },
OptionWithLongNameB { value1: u8, value2: u8, value3: u8 },
NeverUsed1,
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running rustfmt on the Rust examples in this issue and compare the indentation of the second pattern across functions f, g, and h. Trace the formatter behavior responsible for these pattern layouts; done means the multiple-pattern if let formatting is consistently improved without regressing the examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100