Skip to content

debug_assert_eq still requires the type(s) implement PartialEq in release mode #147241

@dcormier

Description

@dcormier

It can be surprising that debug_assert_eq still requires the type implement PartialEq in release mode.

I tried this code:

fn main() {
    let one = Thing;
    let two = Thing;

    debug_assert_eq!(one, two);
}

#[derive(Debug)]
#[cfg_attr(debug_assertions, derive(PartialEq))]
struct Thing;

I expected to see this happen: The debug_assert_eq macro would not require PartialEq when debug_assertions is not enabled (i.e. release mode).

Instead, this happened: In release mode, debug_assert_eq was expanded in such a way that PartialEq is still required to be implemented, even though it's never executed.

Meta

rustc --version --verbose:

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

As well as in the playground on stable (1.90.0), 1.91.0-beta.4 (2025-09-27 aa7859c0dec2de6c9cab), and 1.92.0-nightly (2025-09-30 fa3155a644dd62e86582).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions