rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.04k stars 888 forks source link

error[internal]: left behind trailing whitespace #6246

Open QuarticCat opened 4 months ago

QuarticCat commented 4 months ago

Minimum reproducible example:

fn main() {
    let foo = 
    // 114514
    if true {
        1919
    } else {
        810
    };
}

Note the extra whitespace after =.

Version: 1.7.0-stable

asukaminato0721 commented 4 months ago

https://github.com/rust-lang/rustfmt/issues/2896 ?

ytmimi commented 4 months ago

There is trailing whitespace in the input snippet. The comment // 114514 prevents formatting, which also stops rustfmt from rewriting the assignment and removing the whitespace.

johnhuichen commented 3 months ago

@rustbot claim

johnhuichen commented 3 months ago

@ytmimi

I managed to find a fix for this scenario by applying rewrite_assign_rhs_with_comments.

The problem is rewrite_assign_rhs_with_comments seems to work different when the line is super long. Would appreciate some pointers

johnhuichen commented 3 months ago

Closing my PR as https://github.com/rust-lang/rustfmt/pull/5501/files is addressing the same issue