-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Description
I tried this code:
#[allow(dead_code)]
#[derive(PartialEq)]
enum Thing<T> {
A(T),
B,
}
struct Incomparable;
impl PartialEq for Thing<Incomparable> {
fn eq(&self, _: &Self) -> bool {
panic!()
}
}
const X: Thing<Incomparable> = Thing::B;
fn main() {
if let X = X {
println!("equal");
}
}I expected the code to either produce a compile error, or panic at run time. Instead, it compiled and printed "equal". That is, if let X = X has different behavior from if X == X.
This seems to be caused by the derive(PartialEq) expanding to the following code, which seems incorrect, due to the lack of bounds on T:
impl<T> ::core::marker::StructuralPartialEq for Thing<T> { }The reference seems to be ambiguous on whether this behavior is correct or not, but I think that this behavior is incorrect, since I interpret "its PartialEq instance" to mean "the impl that caused the const's type to implement PartialEq".
Meta
Reproducible on the playground with version 1.92.0-nightly (2025-10-13 4b94758d2ba7d0ef71cc)
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team