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

ifs_same_cond bails out on equal methods that return bool #10272

Closed
matthiaskrgr opened this issue Feb 1, 2023 · 1 comment · Fixed by #10350
Closed

ifs_same_cond bails out on equal methods that return bool #10272

matthiaskrgr opened this issue Feb 1, 2023 · 1 comment · Fixed by #10350
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 1, 2023

Summary

apparently we detect boolan expressions of the form x == y but we don't detect fn(&self) -> bool ones???
I get it that this can be iffy if sideeffects are involved but in this example the fn does not even need &mut self :/

Could we somehow warn here for const-fns at least maybe?

Lint Name

ifs_same_cond

Reproducer

I tried this code:

pub fn main() {
    let a = Some(32);
    if let Some(32) = a {
        let b = String::from("x");
        if b.contains("ah") { // same as
            eprintln!("AAA");
        } else if b.contains("ah") { // here
            println!("AAA");
        }
    }
}

I expected to see this happen:
clippy warning

Instead, this happened:

Version

rustc 1.69.0-nightly (dc1d9d50f 2023-01-31)
binary: rustc
commit-hash: dc1d9d50fba2f6a1ccab8748a0050cde38253f60
commit-date: 2023-01-31
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7
@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Feb 1, 2023
@J-ZhengLi
Copy link
Member

claim first, question it later~ @rustbot claim

bors added a commit that referenced this issue Mar 13, 2023
enhance [`ifs_same_cond`] to warn same immutable method calls as well

fixes: #10272

---

changelog: Enhancement: [`ifs_same_cond`]: Now also detects immutable method calls.
[#10350](#10350)
<!-- changelog_checked -->
@bors bors closed this as completed in ff843ac Mar 14, 2023
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 I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants