rust-lang / rust-lang/rust-clippy

Custom `assert_*!` macros for `eq_op` (and possibly others)

Open
#14,903 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

G-Rust-for-Linux
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Description

In Linux, we use custom assert*! macros for KUnit tests. The eq_op lint only triggers for the standard ones, so e.g. the following doesn't lint:

fn f() {
    macro_rules! assert_eq {
        ($l:expr, $r:expr) => {}
    }

    assert_eq!(1 + 1, 2);
}

https://godbolt.org/z/W99Wsvs4r

Could a list of custom macros for assert*! ones be configured (similar to the lists for e.g. disallowed_macros) so that lints know they should apply to those too? Or, even better, could there be an attribute that users could apply to their macros.

This is similar to https://github.com/rust-lang/rust-clippy/issues/11303, in the sense that it is another case of linting not applying with custom versions of standard macros.

Not sure if this should be considered a false negative for eq_op or others, since it may be designed on purpose to only lint on the standard ones.

Version
rustc 1.87.0 (17067e9ac 2025-05-09)
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the custom assert_eq! example from the issue and inspect how the eq_op lint recognizes standard assertion macros. Compare that path with the existing disallowed_macros configuration, then determine whether custom assertion names or a macro attribute should be supported; done means the custom macro is linted as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.