Skip to content

bool_assert_comparison suggests wrongly for macros #16279

@profetia

Description

@profetia

Summary

bool_assert_comparison suggests wrongly for macros

Reproducer

Code:

fn foo() {
    macro_rules! is_empty {
        ($x:expr) => {
            $x.is_empty()
        };
    }

    assert_eq!(is_empty!("a"), false);
}

Current output:

warning: used `assert_eq!` with a literal bool
  --> src/main.rs:10:5
   |
10 |     assert_eq!(is_empty!("a"), false);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison
   = note: `#[warn(clippy::bool_assert_comparison)]` on by default
help: replace it with `assert!(..)`
   |
 6 ~             !$x.is_empty()
 7 |         };
 8 |     }
 9 |
10 ~     assert!(is_empty!("a"));
   |

Desired output:

warning: used `assert_eq!` with a literal bool
  --> src/main.rs:10:5
   |
10 |     assert_eq!(is_empty!("a"), false);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison
   = note: `#[warn(clippy::bool_assert_comparison)]` on by default
help: replace it with `assert!(..)`
   |
10 ~     assert!(!is_empty!("a"));
   |

Version

rustc 1.94.0-nightly (f52090008 2025-12-10)
binary: rustc
commit-hash: f5209000832c9d3bc29c91f4daef4ca9f28dc797
commit-date: 2025-12-10
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.5

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions