@@ -3192,6 +3192,8 @@ impl<'tcx> TraitDef<'tcx> {
3192
3192
}
3193
3193
}
3194
3194
3195
+ /// Iterate over every impl that could possibly match the
3196
+ /// self-type `self_ty`.
3195
3197
pub fn for_each_relevant_impl < F : FnMut ( DefId ) > ( & self ,
3196
3198
tcx : & ctxt < ' tcx > ,
3197
3199
self_ty : Ty < ' tcx > ,
@@ -3203,18 +3205,29 @@ impl<'tcx> TraitDef<'tcx> {
3203
3205
f ( impl_def_id) ;
3204
3206
}
3205
3207
3206
- if let Some ( simp) = fast_reject:: simplify_type ( tcx, self_ty, false ) {
3208
+ // simplify_type(.., false) basically replaces type parameters and
3209
+ // projections with infer-variables. This is, of course, done on
3210
+ // the impl trait-ref when it is instantiated, but not on the
3211
+ // predicate trait-ref which is passed here.
3212
+ //
3213
+ // for example, if we match `S: Copy` against an impl like
3214
+ // `impl<T:Copy> Copy for Option<T>`, we replace the type variable
3215
+ // in `Option<T>` with an infer variable, to `Option<_>` (this
3216
+ // doesn't actually change fast_reject output), but we don't
3217
+ // replace `S` with anything - this impl of course can't be
3218
+ // selected, and as there are hundreds of similar impls,
3219
+ // considering them would significantly harm performance.
3220
+ if let Some ( simp) = fast_reject:: simplify_type ( tcx, self_ty, true ) {
3207
3221
if let Some ( impls) = self . nonblanket_impls . borrow ( ) . get ( & simp) {
3208
3222
for & impl_def_id in impls {
3209
3223
f ( impl_def_id) ;
3210
3224
}
3211
- return ; // we don't need to process the other non-blanket impls
3212
3225
}
3213
- }
3214
-
3215
- for v in self . nonblanket_impls . borrow ( ) . values ( ) {
3216
- for & impl_def_id in v {
3217
- f ( impl_def_id ) ;
3226
+ } else {
3227
+ for v in self . nonblanket_impls . borrow ( ) . values ( ) {
3228
+ for & impl_def_id in v {
3229
+ f ( impl_def_id ) ;
3230
+ }
3218
3231
}
3219
3232
}
3220
3233
}
@@ -7267,6 +7280,24 @@ impl<'tcx,T:HasTypeFlags> HasTypeFlags for VecPerParamSpace<T> {
7267
7280
}
7268
7281
}
7269
7282
7283
+ impl HasTypeFlags for abi:: Abi {
7284
+ fn has_type_flags ( & self , _flags : TypeFlags ) -> bool {
7285
+ false
7286
+ }
7287
+ }
7288
+
7289
+ impl HasTypeFlags for ast:: Unsafety {
7290
+ fn has_type_flags ( & self , _flags : TypeFlags ) -> bool {
7291
+ false
7292
+ }
7293
+ }
7294
+
7295
+ impl HasTypeFlags for BuiltinBounds {
7296
+ fn has_type_flags ( & self , _flags : TypeFlags ) -> bool {
7297
+ false
7298
+ }
7299
+ }
7300
+
7270
7301
impl < ' tcx > HasTypeFlags for ClosureTy < ' tcx > {
7271
7302
fn has_type_flags ( & self , flags : TypeFlags ) -> bool {
7272
7303
self . sig . has_type_flags ( flags)
@@ -7279,6 +7310,12 @@ impl<'tcx> HasTypeFlags for ClosureUpvar<'tcx> {
7279
7310
}
7280
7311
}
7281
7312
7313
+ impl < ' tcx > HasTypeFlags for ExistentialBounds < ' tcx > {
7314
+ fn has_type_flags ( & self , flags : TypeFlags ) -> bool {
7315
+ self . projection_bounds . has_type_flags ( flags)
7316
+ }
7317
+ }
7318
+
7282
7319
impl < ' tcx > HasTypeFlags for ty:: InstantiatedPredicates < ' tcx > {
7283
7320
fn has_type_flags ( & self , flags : TypeFlags ) -> bool {
7284
7321
self . predicates . has_type_flags ( flags)
@@ -7354,6 +7391,12 @@ impl<'tcx> HasTypeFlags for Ty<'tcx> {
7354
7391
}
7355
7392
}
7356
7393
7394
+ impl < ' tcx > HasTypeFlags for TypeAndMut < ' tcx > {
7395
+ fn has_type_flags ( & self , flags : TypeFlags ) -> bool {
7396
+ self . ty . has_type_flags ( flags)
7397
+ }
7398
+ }
7399
+
7357
7400
impl < ' tcx > HasTypeFlags for TraitRef < ' tcx > {
7358
7401
fn has_type_flags ( & self , flags : TypeFlags ) -> bool {
7359
7402
self . substs . has_type_flags ( flags)
0 commit comments