Skip to content

eq_op false positive when statically asserting that a numeric value is equal to a byte literal #15609

@Zalathar

Description

@Zalathar

Summary

I was writing some code where I wanted to reassure readers that a particular numeric value corresponds to a particular ASCII character (e.g. 0x20 == b' ').

I expressed this fact as a compiler-checked static assertion:

const _: () = assert!(0x20 == b' ');

Surprisingly, clippy flags this pattern not just as a warning, but as a hard error by default.

Lint Name

eq_op

Reproducer

I tried this code:

fn main() {
    const _: () = assert!(0x20 == b' ');
}

I saw this happen:

error: equal expressions as operands to `==`
 --> src/main.rs:2:27
  |
2 |     const _: () = assert!(0x20 == b' ');
  |                           ^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op
  = note: `#[deny(clippy::eq_op)]` on by default

I expected to see this happen:

  • No error or warning.

Version

rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: aarch64-apple-darwin
release: 1.89.0
LLVM version: 20.1.7

Additional Labels

No response

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 have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions