pub fn search_for_structural_match_violation<'tcx>( span: Span, tcx: TyCtxt<'tcx>, ty: Ty<'tcx> ) -> Option<Ty<'tcx>>
This method traverses the structure of
ty, trying to find an
instance of an ADT (i.e. struct or enum) that doesn’t implement
the structural-match traits, or a generic type parameter
(which cannot be determined to be structural-match).
The “structure of a type” includes all components that would be considered when doing a pattern match on a constant of that type.
This means this method descends into fields of structs/enums, and also descends into the inner type
The traversal doesn’t dereference unsafe pointers (
*mut T), and it does not visit the type arguments of an instantiated generic like
The reason we do this search is Rust currently require all ADTs
reachable from a constant’s type to implement the
structural-match traits, which essentially say that
the implementation of
PartialEq::eq behaves equivalently to a
comparison against the unfolded structure.
For more background on why Rust has this requirement, and issues that arose when the requirement was not enforced completely, see Rust RFC 1445, rust-lang/rust#61188, and rust-lang/rust#62307.