@@ -93,17 +93,20 @@ pub fn type_marked_structural(id: hir::HirId,
93
93
fulfillment_cx. select_all_or_error ( infcx) . is_ok ( )
94
94
}
95
95
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`).
96
99
struct Search < ' a , ' tcx > {
97
100
id : hir:: HirId ,
98
101
span : Span ,
99
102
100
103
infcx : InferCtxt < ' a , ' tcx > ,
101
104
102
- // records the first ADT we find that does not implement `Structural` .
105
+ /// Records first ADT that does not implement a structural-match trait .
103
106
found : Option < NonStructuralMatchTy < ' tcx > > ,
104
107
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.
107
110
seen : FxHashSet < hir:: def_id:: DefId > ,
108
111
}
109
112
@@ -129,13 +132,26 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
129
132
}
130
133
ty:: RawPtr ( ..) => {
131
134
// structural-match ignores substructure of
132
- // `*const _`/`*mut _`, so skip super_visit_with
135
+ // `*const _`/`*mut _`, so skip ` super_visit_with`.
133
136
//
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
+
134
149
// (But still tell caller to continue search.)
135
150
return false ;
136
151
}
137
152
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`
139
155
//
140
156
// (But still tell caller to continue search.)
141
157
return false ;
0 commit comments