StructuralEq
and derive(PartialEq,Eq)
in the stdlib
#84391
Labels
A-const-generics
Area: const generics (parameters and arguments)
A-patterns
Relating to patterns and pattern matching
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
I've been meaning to open this for a few weeks now, but haven't had the time.
Currently, in the implementation of the rust standard library, many types use
derive(PartialEq,Eq)
. While, for other derive macros, this isn't an issue,derive(PartialEq)
andderive(Eq)
are special, and interacts with various language features. In particular, types likeString
(suprisingly) have theStructuralEq
impl thatderive(Eq)
presents. Another example isTypeId
, which is currently bothStructuralEq
andStructuralPartialEq
, so it could be used in structural matching ofconst
s and (eventually) in const generics.This particularily affects an implementation I am working on here, which is intended to solve a longstanding soundness issue involving TypeId collisions, at the cost of a non-structural PartialEq implementation. While this is not currently an issue, the stablization of const generics, or making the
TypeId::of
functionconst
, would bindTypeId
to an implementation similar to what already exists, on all implementations (and, in any case, will run into #10389 at some level). For example, with the#[feature(const_generics)]
, it is currently possible to declare a type withTypeId
as a generic parameter (though it's not possible to instantiate that parameter).I have previously described the TypeId issue on IRLO, and the more general issue on zulip.
I maintain my recommendation from the zulip thread, that currently, if a type cannot be used in structural matching of constants, the derive be removed and replaced with something effectively similar (possibly an equivalent, unstable, derive macro that excludes the impls of Structural{Partial,}Eq).
The text was updated successfully, but these errors were encountered: