Format fails if if expression is used on left side of `+` but not if used on right side
Open
Nobody has claimed this yet.
A-binary-ops
A-closures
I-poor-formatting
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
the following string will successfully reformat with rusfmt
let check = code.chars().rev().enumerate().filter(|(i, c)| c.is_digit(10)).try_fold(0u32, |sum, (i, c)| c.to_digit(10).map(|d| sum + if (i + 1) % 2 == 0 { if 2*d > 9 { 2*d - 9} else { 2*d }} else {d})).map_or(false, |sum| sum % 10 == 0);
and this one will not
code.chars().rev().enumerate().filter(|(i, c)| c.is_digit(10)).try_fold(0u32, |sum, (i, c)| c.to_digit(10).map(|d| if (i + 1) % 2 == 0 { if 2*d > 9 { 2*d - 9} else { 2*d }} else {d} + sum)).map_or(false, |sum| sum % 10 == 0);
the only difference being that sum was moved from the back of the if expression to the front.
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 reproducing the two Rust snippets from the issue with rusfmt and compare their formatting behavior. Trace the formatter path handling an if expression used on either side of +; done means both equivalent expressions reformat successfully and regression coverage verifies the behavior.
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