"Structural match" annotations should be moved from struct/enum items to impl items #63438
Labels
A-const-generics
Area: const generics (parameters and arguments)
A-macros
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
A-resolve
Area: Name resolution
A-trait-system
Area: Trait system
A-type-system
Area: Type system
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
"Structural match" property of a type means that the constants of this type can be used in patterns (#31434) or in const generics in the future.
Right now this property can be given to a type in two ways:
#[structural_match]
attribute, rarely used,PhantomData
is the only example.#[derive(PartialEq)]
and#[derive(Eq)]
then it's marked as "structural match". Derives cannot modify the items they are applied to, so this tracking is done through a special table in resolver (which is kind of a hack).To avoid hacks we need to pass the knowledge about "structural match" not through types themselves, but through impls on them (which can be generated by derives easily).
The condition for the type being "structural match" is:
PartialEq
methods are derived so their behavior is fully known to the compiler.Eq
is implemented, but not necessarily derived, it's just a marker without methods.So, the "structural match" annotation needs to be generated by
derive(PartialEq)
in the form of either#[structural_match] impl PartialEq for ...
(in this case the const check will be "implementsEq
+ implementsPartialEq
+ thePartialEq
impl has the attribute"), orimpl StructuralMatch for ...
(in this case the const check will be "implementsEq
+ implementsStructuralMatch
").cc #63248 @matthewjasper @varkor @Centril @pnkfelix
The text was updated successfully, but these errors were encountered: