Skip to content

Format fails if if expression is used on left side of + but not if used on right side #3203

Open
@yaahc

Description

@yaahc

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions