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