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

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

Open
e00E opened this issue Jul 23, 2022 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@e00E
Copy link

e00E commented Jul 23, 2022

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 e00E added the C-bug Category: Clippy is not doing the correct thing label Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

1 participant