@@ -328,6 +328,23 @@ impl<'a, 'tcx> ty::Lift<'tcx> for SelectionCandidate<'a> {
328328 }
329329}
330330
331+ EnumTypeFoldableImpl ! {
332+ impl <' tcx> TypeFoldable <' tcx> for SelectionCandidate <' tcx> {
333+ ( SelectionCandidate :: BuiltinCandidate ) { has_nested } ,
334+ ( SelectionCandidate :: ParamCandidate ) ( poly_trait_ref) ,
335+ ( SelectionCandidate :: ImplCandidate ) ( def_id) ,
336+ ( SelectionCandidate :: AutoImplCandidate ) ( def_id) ,
337+ ( SelectionCandidate :: ProjectionCandidate ) ,
338+ ( SelectionCandidate :: ClosureCandidate ) ,
339+ ( SelectionCandidate :: GeneratorCandidate ) ,
340+ ( SelectionCandidate :: FnPointerCandidate ) ,
341+ ( SelectionCandidate :: TraitAliasCandidate ) ( def_id) ,
342+ ( SelectionCandidate :: ObjectCandidate ) ,
343+ ( SelectionCandidate :: BuiltinObjectCandidate ) ,
344+ ( SelectionCandidate :: BuiltinUnsizeCandidate ) ,
345+ }
346+ }
347+
331348struct SelectionCandidateSet < ' tcx > {
332349 // a list of candidates that definitely apply to the current
333350 // obligation (meaning: types unify).
@@ -818,27 +835,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
818835
819836 ty:: Predicate :: ConstEvaluatable ( def_id, substs) => {
820837 let tcx = self . tcx ( ) ;
821- match tcx. lift_to_global ( & ( obligation. param_env , substs) ) {
822- Some ( ( param_env, substs) ) => {
823- let instance =
824- ty:: Instance :: resolve ( tcx. global_tcx ( ) , param_env, def_id, substs) ;
825- if let Some ( instance) = instance {
826- let cid = GlobalId {
827- instance,
828- promoted : None ,
829- } ;
830- match self . tcx ( ) . const_eval ( param_env. and ( cid) ) {
831- Ok ( _) => Ok ( EvaluatedToOk ) ,
832- Err ( _) => Ok ( EvaluatedToErr ) ,
833- }
834- } else {
835- Ok ( EvaluatedToErr )
838+ if !( obligation. param_env , substs) . has_local_value ( ) {
839+ let param_env = obligation. param_env ;
840+ let instance =
841+ ty:: Instance :: resolve ( tcx, param_env, def_id, substs) ;
842+ if let Some ( instance) = instance {
843+ let cid = GlobalId {
844+ instance,
845+ promoted : None ,
846+ } ;
847+ match self . tcx ( ) . const_eval ( param_env. and ( cid) ) {
848+ Ok ( _) => Ok ( EvaluatedToOk ) ,
849+ Err ( _) => Ok ( EvaluatedToErr ) ,
836850 }
851+ } else {
852+ Ok ( EvaluatedToErr )
837853 }
838- None => {
839- // Inference variables still left in param_env or substs.
840- Ok ( EvaluatedToAmbig )
841- }
854+ } else {
855+ // Inference variables still left in param_env or substs.
856+ Ok ( EvaluatedToAmbig )
842857 }
843858 }
844859 }
@@ -1172,7 +1187,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11721187 }
11731188
11741189 if self . can_use_global_caches ( param_env) {
1175- if let Some ( trait_ref) = self . tcx ( ) . lift_to_global ( & trait_ref ) {
1190+ if ! trait_ref. has_local_value ( ) {
11761191 debug ! (
11771192 "insert_evaluation_cache(trait_ref={:?}, candidate={:?}) global" ,
11781193 trait_ref, result,
@@ -1645,8 +1660,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16451660 if let Err ( Overflow ) = candidate {
16461661 // Don't cache overflow globally; we only produce this
16471662 // in certain modes.
1648- } else if let Some ( trait_ref) = tcx . lift_to_global ( & trait_ref ) {
1649- if let Some ( candidate) = tcx . lift_to_global ( & candidate ) {
1663+ } else if ! trait_ref. has_local_value ( ) {
1664+ if ! candidate. has_local_value ( ) {
16501665 debug ! (
16511666 "insert_candidate_cache(trait_ref={:?}, candidate={:?}) global" ,
16521667 trait_ref, candidate,
0 commit comments