@@ -1145,6 +1145,30 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
1145
1145
}
1146
1146
}
1147
1147
1148
+ /// This method traverses the structure of `ty`, trying to find an
1149
+ /// instance of an ADT (i.e. struct or enum) that was declared without
1150
+ /// the `#[structural_match]` attribute.
1151
+ ///
1152
+ /// The "structure of a type" includes all components that would be
1153
+ /// considered when doing a pattern match on a constant of that
1154
+ /// type.
1155
+ ///
1156
+ /// * This means this method descends into fields of structs/enums,
1157
+ /// and also descends into the inner type `T` of `&T` and `&mut T`
1158
+ ///
1159
+ /// * The traversal doesn't dereference unsafe pointers (`*const T`,
1160
+ /// `*mut T`), and it does not visit the type arguments of an
1161
+ /// instantiated generic like `PhantomData<T>`.
1162
+ ///
1163
+ /// The reason we do this search is Rust currently require all ADT's
1164
+ /// reachable from a constant's type to be annotated with
1165
+ /// `#[structural_match]`, an attribute which essentially says that
1166
+ /// the implementation of `PartialEq::eq` behaves *equivalently* to a
1167
+ /// comparison against the unfolded structure.
1168
+ ///
1169
+ /// For more background on why Rust has this requirement, and issues
1170
+ /// that arose when the requirement was not enforced completely, see
1171
+ /// Rust RFC 1445, rust-lang/rust#61188, and rust-lang/rust#62307.
1148
1172
fn search_for_adt_without_structural_match < ' tcx > ( tcx : TyCtxt < ' tcx > ,
1149
1173
ty : Ty < ' tcx > )
1150
1174
-> Option < & ' tcx AdtDef >
0 commit comments