Skip to content

Strange formatted comments behind if let in a new line  #3979

Closed
@CYBAI

Description

@CYBAI
$ rustfmt --version
rustfmt 1.4.11-nightly (1838235 2019-12-03)

I'm not sure if this is duplicate with #3937 so filed this one.

Code:

fn main() {
    let o_num = Some(123);
    
    let x = if let Some(n) =
        // this is a test comment
        // to see if rustfmt will break
        // after using the lateset version
        o_num {
            n * 2
        } else {
            0
        };
    
    println!("Number: {}", x);
}

Actual Formatted:

fn main() {
    let o_num = Some(123);

    let x = if let Some(n) =
        // this is a test comment
    // to see if rustfmt will break
    // after using the lateset version
        o_num
    {
        n * 2
    } else {
        0
    };

    println!("Number: {}", x);
}

Personal Expected Formatted:

fn main() {
    let o_num = Some(123);

    let x = if let Some(n) =
        // this is a test comment
        // to see if rustfmt will break
        // after using the lateset version
        o_num
    {
        n * 2
    } else {
        0
    };

    println!("Number: {}", x);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions