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