rust-lang / rust-lang/rust

`expect` on struct does not cover the derives

Open
#130,019 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lints C-bug F-lint_reasons T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Minimal reproducer:

#[expect(clippy::derived_hash_with_manual_eq)]
#[derive(Hash)]
pub struct Thing;

impl PartialEq<Thing> for Thing {
    fn eq(&self, _other: &Thing) -> bool {
        true
    }
}

I ran cargo clippy, and I expected the expect to suppress the clippy::derived_hash_with_manual_eq lint. Instead, I got the following:

error: you are deriving `Hash` but have implemented `PartialEq` explicitly
 --> src/lib.rs:2:10
  |
2 | #[derive(Hash)]
  |          ^^^^
  |
note: `PartialEq` implemented here
 --> src/lib.rs:5:1
  |
5 | impl PartialEq<Thing> for Thing {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derived_hash_with_manual_eq
  = note: `#[deny(clippy::derived_hash_with_manual_eq)]` on by default
  = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: this lint expectation is unfulfilled
 --> src/lib.rs:1:10
  |
1 | #[expect(clippy::derived_hash_with_manual_eq)]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unfulfilled_lint_expectations)]` on by default

I haven't found any way to apply the expect to the derive except by putting it on the containing module.

Note, however, that replacing the expect with an allow does successfully suppress the warning. This seems particularly surprising, and violates the expectation that replacing an allow with an expect should always work.

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

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

Reproduce the issue from the minimal example in src/lib.rs by running cargo clippy, comparing #[expect] with #[allow] on the Hash derive. Trace how the derived_hash_with_manual_eq lint and the derive macro handle expectations; done means #[expect] suppresses the lint without producing an unfulfilled_lint_expectations warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
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.