Skip to content

False Positive equatable_if_let in macro #9066

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
daxpedda opened this issue Jun 29, 2022 · 4 comments · Fixed by #9074
Closed

False Positive equatable_if_let in macro #9066

daxpedda opened this issue Jun 29, 2022 · 4 comments · Fixed by #9074
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion

Comments

@daxpedda
Copy link
Contributor

daxpedda commented Jun 29, 2022

Summary

equatable_if_let is triggered from inside an external macro.

Lint Name

equatable_if_let

Reproducer

I tried this code:

macro_rules! concat_assert {
    ($condition:expr) => {
        if let false = $condition {
            
        }
    };
}

const _: () = {
	concat_assert!(true);
};

I saw this happen:

warning: this pattern matching can be expressed using equality
  --> src/render/shader/shader_manual.rs:32:12
   |
30 | / macro_rules! test {
31 | |     ($condition:expr) => {
32 | |         if let false = $condition {
   | |            ^^^ help: try: `true == false`
33 | |             
34 | |         }
35 | |     };
36 | | }
   | |_- in this expansion of `test!`
...
39 |       test!(true);
   |       ----------- in this macro invocation
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#equatable_if_let

I expected to see this happen:
No warning. Obviously this example code has to be split up into different crates, personally I'm fine with this lint triggering for internal macros.

Version

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0

Additional Labels

@rustbot label T-macros

@daxpedda daxpedda added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jun 29, 2022
@rustbot rustbot added the T-macros Type: Issues with macros and macro expansion label Jun 29, 2022
@daxpedda
Copy link
Contributor Author

daxpedda commented Jun 29, 2022

Lints being triggered in macros is the most frequent "false-positive" issue I have with Clippy, I agree with flip1995 that Clippy should make it easier for lint implementations to avoid this issue alltogether:
#8694 (comment).

@kyoto7250
Copy link
Contributor

@rustbot claim

@daxpedda
Copy link
Contributor Author

@kyoto7250 I'm already working on it, sorry, didn't know about this claim system.

@kyoto7250 kyoto7250 removed their assignment Jun 30, 2022
@kyoto7250
Copy link
Contributor

Okay, I understood 👍🏻

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants