Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustfmt does not put short if-else at the end of the block #2777

Closed
topecongiro opened this Issue Jun 9, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@topecongiro
Copy link
Collaborator

topecongiro commented Jun 9, 2018

As of rustfmt 0.8.2-nightly (08da30d 2018-06-06), rustfmt formats short if expressions like the following:

fn plain_if(x: bool) -> u8 {
    if x {
        0
    } else {
        1
    }
}

fn paren_if(x: bool) -> u8 {
    (if x { 0 } else { 1 })
}

fn let_if(x: bool) -> u8 {
    let x = if x { 0 } else { 1 };
    x
}

fn return_if(x: bool) -> u8 {
    return if x { 0 } else { 1 };
}

This is becuase the if in plain_if is parsed as a statement, whereas others are parsed as an expression (rustfmt rewrites if in a single line only when it apprears in the expression place).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.