rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

collapsible_if lint is confused by comments and sometimes deletes them with --fix

Open e00E opened this issue 3 years ago • 0 comments

Summary

fn v1(a: bool, b: bool) {
    if a {
        if b {
            todo!()
        }
    }
}

fn v2(a: bool, b: bool) {
    if a {
        // comment
        if b {
            todo!()
        }
    }
}

fn v3(a: bool, b: bool) {
    if a {
        if 
        // comment
        b {
            todo!()
        }
    }
}

fn v4(a: bool, b: bool) {
    if a {
        if b
        // comment
        {
            todo!()
        }
    }
}

v1, v3, v4 trigger the collapsible_if lint with the suggestion

if a && b {
    todo!()
}

Bug 1: It is inconsistent that v2 does not trigger the lint while v3, v4 do. Bug 2: When automatically applying the suggestion in v3, v4 through clippy --fix the comment is removed. It is not acceptable for the suggestion to remove comments.

Reproducer

No response

Version

rustc 1.62.0 (a8314ef7d 2022-06-27)
binary: rustc
commit-hash: a8314ef7d0ec7b75c336af2c9857bfaf43002bfc
commit-date: 2022-06-27
host: x86_64-unknown-linux-gnu
release: 1.62.0
LLVM version: 14.0.5

Additional Labels

No response

e00E avatar Jul 23 '22 13:07 e00E