@@ -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 ;
@@ -2226,47 +2227,66 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22262227
22272228 let param_env = tcx. param_env ( block. owner . to_def_id ( ) ) ;
22282229 let cause = ObligationCause :: misc ( span, block. owner . def_id ) ;
2230+
22292231 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+ ) ;
22352248
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) ;
22402254
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) ;
22442259
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 ( ) ? ;
22482263
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) ;
22502267
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) ;
22562269
2257- ocx. register_obligations ( impl_obligations) ;
2270+ let impl_obligations = traits:: predicates_for_generics (
2271+ |_, _| cause. clone ( ) ,
2272+ param_env,
2273+ impl_bounds,
2274+ ) ;
22582275
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+ }
22642283
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+ } )
22672287 } )
2268- } )
2269- . collect ( ) ;
2288+ . collect ( )
2289+ } ) ;
22702290
22712291 if applicable_candidates. len ( ) > 1 {
22722292 return Err ( self . complain_about_ambiguous_inherent_assoc_type (
0 commit comments