@@ -93,17 +93,20 @@ pub fn type_marked_structural(id: hir::HirId,
9393 fulfillment_cx. select_all_or_error ( infcx) . is_ok ( )
9494}
9595
96+ /// This implements the traversal over the structure of a given type to try to
97+ /// find instances of ADTs (specifically structs or enums) that do not implement
98+ /// the structural-match traits (`StructuralPartialEq` and `StructuralEq`).
9699struct Search < ' a , ' tcx > {
97100 id : hir:: HirId ,
98101 span : Span ,
99102
100103 infcx : InferCtxt < ' a , ' tcx > ,
101104
102- // records the first ADT we find that does not implement `Structural` .
105+ /// Records first ADT that does not implement a structural-match trait .
103106 found : Option < NonStructuralMatchTy < ' tcx > > ,
104107
105- // tracks ADT's previously encountered during search, so that
106- // we will not recur on them again.
108+ /// Tracks ADTs previously encountered during search, so that
109+ /// we will not recur on them again.
107110 seen : FxHashSet < hir:: def_id:: DefId > ,
108111}
109112
@@ -129,13 +132,26 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
129132 }
130133 ty:: RawPtr ( ..) => {
131134 // structural-match ignores substructure of
132- // `*const _`/`*mut _`, so skip super_visit_with
135+ // `*const _`/`*mut _`, so skip ` super_visit_with`.
133136 //
137+ // For example, if you have:
138+ // ```
139+ // struct NonStructural;
140+ // #[derive(PartialEq, Eq)]
141+ // struct T(*const NonStructural);
142+ // const C: T = T(std::ptr::null());
143+ // ```
144+ //
145+ // Even though `NonStructural` does not implement `PartialEq`,
146+ // structural equality on `T` does not recur into the raw
147+ // pointer. Therefore, one can still use `C` in a pattern.
148+
134149 // (But still tell caller to continue search.)
135150 return false ;
136151 }
137152 ty:: FnDef ( ..) | ty:: FnPtr ( ..) => {
138- // types of formals and return in `fn(_) -> _` are also irrelevant
153+ // types of formals and return in `fn(_) -> _` are also irrelevant;
154+ // so we do not recur into them via `super_visit_with`
139155 //
140156 // (But still tell caller to continue search.)
141157 return false ;
0 commit comments