@@ -13,6 +13,7 @@ pub enum NonStructuralMatchTy<'tcx> {
13
13
Adt ( & ' tcx AdtDef ) ,
14
14
Param ,
15
15
Dynamic ,
16
+ Foreign ,
16
17
}
17
18
18
19
/// This method traverses the structure of `ty`, trying to find an
@@ -143,6 +144,10 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
143
144
self . found = Some ( NonStructuralMatchTy :: Dynamic ) ;
144
145
return true ; // Stop visiting.
145
146
}
147
+ ty:: Foreign ( _) => {
148
+ self . found = Some ( NonStructuralMatchTy :: Foreign ) ;
149
+ return true ; // Stop visiting
150
+ }
146
151
ty:: RawPtr ( ..) => {
147
152
// structural-match ignores substructure of
148
153
// `*const _`/`*mut _`, so skip `super_visit_with`.
@@ -163,7 +168,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
163
168
return false ;
164
169
}
165
170
ty:: FnDef ( ..) | ty:: FnPtr ( ..) => {
166
- // types of formals and return in `fn(_) -> _` are also irrelevant;
171
+ // Types of formals and return in `fn(_) -> _` are also irrelevant;
167
172
// so we do not recur into them via `super_visit_with`
168
173
//
169
174
// (But still tell caller to continue search.)
@@ -176,7 +181,33 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
176
181
// for empty array.
177
182
return false ;
178
183
}
179
- _ => {
184
+ ty:: Bool
185
+ | ty:: Char
186
+ | ty:: Int ( _)
187
+ | ty:: Uint ( _)
188
+ | ty:: Float ( _)
189
+ | ty:: Str
190
+ | ty:: Never
191
+ | ty:: Error => {
192
+ // These primitive types are always structural match.
193
+ //
194
+ // `Never` is kind of special here, but as it is not inhabitable, this should be fine.
195
+ return false ;
196
+ }
197
+
198
+ ty:: Array ( ..)
199
+ | ty:: Slice ( _)
200
+ | ty:: Ref ( ..)
201
+ | ty:: Closure ( ..)
202
+ | ty:: Generator ( ..)
203
+ | ty:: GeneratorWitness ( ..)
204
+ | ty:: Tuple ( ..)
205
+ | ty:: Projection ( ..)
206
+ | ty:: UnnormalizedProjection ( ..)
207
+ | ty:: Opaque ( ..)
208
+ | ty:: Bound ( ..)
209
+ | ty:: Placeholder ( _)
210
+ | ty:: Infer ( _) => {
180
211
ty. super_visit_with ( self ) ;
181
212
return false ;
182
213
}
0 commit comments