@@ -31,6 +31,7 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
31
31
use rustc_infer:: traits:: ObligationCause ;
32
32
use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind } ;
33
33
use rustc_middle:: middle:: stability:: AllowUnstable ;
34
+ use rustc_middle:: ty:: fold:: FnMutDelegate ;
34
35
use rustc_middle:: ty:: subst:: { self , GenericArgKind , InternalSubsts , SubstsRef } ;
35
36
use rustc_middle:: ty:: DynKind ;
36
37
use rustc_middle:: ty:: GenericParamDefKind ;
@@ -2226,47 +2227,66 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2226
2227
2227
2228
let param_env = tcx. param_env ( block. owner . to_def_id ( ) ) ;
2228
2229
let cause = ObligationCause :: misc ( span, block. owner . def_id ) ;
2230
+
2229
2231
let mut fulfillment_errors = Vec :: new ( ) ;
2230
- let mut applicable_candidates: Vec < _ > = candidates
2231
- . iter ( )
2232
- . filter_map ( |& ( impl_, ( assoc_item, def_scope) ) | {
2233
- infcx. probe ( |_| {
2234
- let ocx = ObligationCtxt :: new_in_snapshot ( & infcx) ;
2232
+ let mut applicable_candidates: Vec < _ > = infcx. probe ( |_| {
2233
+ let universe = infcx. create_next_universe ( ) ;
2234
+
2235
+ // Regions are not considered during selection.
2236
+ let self_ty = tcx. replace_escaping_bound_vars_uncached (
2237
+ self_ty,
2238
+ FnMutDelegate {
2239
+ regions : & mut |_| tcx. lifetimes . re_erased ,
2240
+ types : & mut |bv| {
2241
+ tcx. mk_placeholder ( ty:: PlaceholderType { universe, name : bv. kind } )
2242
+ } ,
2243
+ consts : & mut |bv, ty| {
2244
+ tcx. mk_const ( ty:: PlaceholderConst { universe, name : bv } , ty)
2245
+ } ,
2246
+ } ,
2247
+ ) ;
2235
2248
2236
- let impl_ty = tcx. type_of ( impl_) ;
2237
- let impl_substs = infcx. fresh_item_substs ( impl_) ;
2238
- let impl_ty = impl_ty. subst ( tcx, impl_substs) ;
2239
- let impl_ty = ocx. normalize ( & cause, param_env, impl_ty) ;
2249
+ candidates
2250
+ . iter ( )
2251
+ . filter_map ( |& ( impl_, ( assoc_item, def_scope) ) | {
2252
+ infcx. probe ( |_| {
2253
+ let ocx = ObligationCtxt :: new_in_snapshot ( & infcx) ;
2240
2254
2241
- // Check that the Self-types can be related.
2242
- // FIXME(fmease): Should we use `eq` here?
2243
- ocx. sup ( & ObligationCause :: dummy ( ) , param_env, impl_ty, self_ty) . ok ( ) ?;
2255
+ let impl_ty = tcx. type_of ( impl_) ;
2256
+ let impl_substs = infcx. fresh_item_substs ( impl_) ;
2257
+ let impl_ty = impl_ty. subst ( tcx, impl_substs) ;
2258
+ let impl_ty = ocx. normalize ( & cause, param_env, impl_ty) ;
2244
2259
2245
- // Check whether the impl imposes obligations we have to worry about .
2246
- let impl_bounds = tcx . predicates_of ( impl_ ) ;
2247
- let impl_bounds = impl_bounds . instantiate ( tcx , impl_substs ) ;
2260
+ // Check that the Self-types can be related .
2261
+ // FIXME(fmease): Should we use `eq` here?
2262
+ ocx . sup ( & ObligationCause :: dummy ( ) , param_env , impl_ty , self_ty ) . ok ( ) ? ;
2248
2263
2249
- let impl_bounds = ocx. normalize ( & cause, param_env, impl_bounds) ;
2264
+ // Check whether the impl imposes obligations we have to worry about.
2265
+ let impl_bounds = tcx. predicates_of ( impl_) ;
2266
+ let impl_bounds = impl_bounds. instantiate ( tcx, impl_substs) ;
2250
2267
2251
- let impl_obligations = traits:: predicates_for_generics (
2252
- |_, _| cause. clone ( ) ,
2253
- param_env,
2254
- impl_bounds,
2255
- ) ;
2268
+ let impl_bounds = ocx. normalize ( & cause, param_env, impl_bounds) ;
2256
2269
2257
- ocx. register_obligations ( impl_obligations) ;
2270
+ let impl_obligations = traits:: predicates_for_generics (
2271
+ |_, _| cause. clone ( ) ,
2272
+ param_env,
2273
+ impl_bounds,
2274
+ ) ;
2258
2275
2259
- let mut errors = ocx. select_where_possible ( ) ;
2260
- if !errors. is_empty ( ) {
2261
- fulfillment_errors. append ( & mut errors) ;
2262
- return None ;
2263
- }
2276
+ ocx. register_obligations ( impl_obligations) ;
2277
+
2278
+ let mut errors = ocx. select_where_possible ( ) ;
2279
+ if !errors. is_empty ( ) {
2280
+ fulfillment_errors. append ( & mut errors) ;
2281
+ return None ;
2282
+ }
2264
2283
2265
- // FIXME(fmease): Unsolved vars can escape this InferCtxt snapshot.
2266
- Some ( ( assoc_item, def_scope, infcx. resolve_vars_if_possible ( impl_substs) ) )
2284
+ // FIXME(fmease): Unsolved vars can escape this InferCtxt snapshot.
2285
+ Some ( ( assoc_item, def_scope, infcx. resolve_vars_if_possible ( impl_substs) ) )
2286
+ } )
2267
2287
} )
2268
- } )
2269
- . collect ( ) ;
2288
+ . collect ( )
2289
+ } ) ;
2270
2290
2271
2291
if applicable_candidates. len ( ) > 1 {
2272
2292
return Err ( self . complain_about_ambiguous_inherent_assoc_type (
0 commit comments