@@ -31,6 +31,7 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
3131use rustc_infer:: traits:: ObligationCause ;
3232use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind } ;
3333use rustc_middle:: middle:: stability:: AllowUnstable ;
34+ use rustc_middle:: ty:: fold:: FnMutDelegate ;
3435use rustc_middle:: ty:: subst:: { self , GenericArgKind , InternalSubsts , SubstsRef } ;
3536use rustc_middle:: ty:: DynKind ;
3637use rustc_middle:: ty:: GenericParamDefKind ;
@@ -2225,47 +2226,66 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22252226
22262227 let param_env = tcx. param_env ( block. owner . to_def_id ( ) ) ;
22272228 let cause = ObligationCause :: misc ( span, block. owner . def_id ) ;
2229+
22282230 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+ ) ;
22342247
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) ;
22392253
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) ;
22432258
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 ( ) ? ;
22472262
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) ;
22492266
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) ;
22552268
2256- ocx. register_obligations ( impl_obligations) ;
2269+ let impl_obligations = traits:: predicates_for_generics (
2270+ |_, _| cause. clone ( ) ,
2271+ param_env,
2272+ impl_bounds,
2273+ ) ;
22572274
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+ }
22632282
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+ } )
22662286 } )
2267- } )
2268- . collect ( ) ;
2287+ . collect ( )
2288+ } ) ;
22692289
22702290 if applicable_candidates. len ( ) > 1 {
22712291 return Err ( self . complain_about_ambiguous_inherent_assoc_type (
0 commit comments