Skip to content

False Positive equatable_if_let in macro #9066

@daxpedda

Description

@daxpedda

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions