@@ -425,17 +425,21 @@ where
425425/// Normalizes the predicates and checks whether they hold in an empty environment. If this
426426/// returns true, then either normalize encountered an error or one of the predicates did not
427427/// hold. Used when creating vtables to check for unsatisfiable methods.
428- pub fn impossible_predicates < ' tcx > (
428+ fn has_impossible_predicates < ' tcx > (
429429 tcx : TyCtxt < ' tcx > ,
430- predicates : Vec < ty:: Predicate < ' tcx > > ,
430+ predicates : impl Iterator < Item = ty:: Predicate < ' tcx > > ,
431431) -> bool {
432- debug ! ( "impossible_predicates(predicates={:?})" , predicates) ;
432+ let predicates = elaborate_predicates ( tcx, predicates)
433+ . map ( |o| tcx. erase_regions ( o. predicate ) )
434+ . filter ( |p| p. is_global ( ) )
435+ . collect :: < Vec < _ > > ( ) ;
433436
434- let result = tcx. infer_ctxt ( ) . enter ( |infcx| {
437+ tcx. infer_ctxt ( ) . enter ( |infcx| {
435438 let param_env = ty:: ParamEnv :: reveal_all ( ) ;
436439 let mut selcx = SelectionContext :: new ( & infcx) ;
437440 let mut fulfill_cx = FulfillmentContext :: new ( ) ;
438441 let cause = ObligationCause :: dummy ( ) ;
442+
439443 let Normalized { value : predicates, obligations } =
440444 normalize ( & mut selcx, param_env, cause. clone ( ) , predicates) ;
441445 for obligation in obligations {
@@ -447,24 +451,26 @@ pub fn impossible_predicates<'tcx>(
447451 }
448452
449453 let errors = fulfill_cx. select_all_or_error ( & infcx) ;
450-
451454 !errors. is_empty ( )
452- } ) ;
453- debug ! ( "impossible_predicates = {:?}" , result) ;
454- result
455+ } )
455456}
456457
457- fn subst_and_check_impossible_predicates < ' tcx > (
458+ fn instantiated_item_has_impossible_predicates < ' tcx > (
458459 tcx : TyCtxt < ' tcx > ,
459460 key : ( DefId , SubstsRef < ' tcx > ) ,
460461) -> bool {
461- debug ! ( "subst_and_check_impossible_predicates(key={:?})" , key) ;
462-
463- let mut predicates = tcx. predicates_of ( key. 0 ) . instantiate ( tcx, key. 1 ) . predicates ;
464- predicates. retain ( |predicate| !predicate. needs_subst ( ) ) ;
465- let result = impossible_predicates ( tcx, predicates) ;
462+ debug ! ( "instantiated_item_has_impossible_predicates(key={:?})" , key) ;
463+ let predicates = tcx. predicates_of ( key. 0 ) . instantiate ( tcx, key. 1 ) . predicates ;
464+ let result = has_impossible_predicates ( tcx, predicates. into_iter ( ) ) ;
465+ debug ! ( "instantiated_item_has_impossible_predicates(key={:?}) = {:?}" , key, result) ;
466+ result
467+ }
466468
467- debug ! ( "subst_and_check_impossible_predicates(key={:?}) = {:?}" , key, result) ;
469+ fn item_has_impossible_predicates < ' tcx > ( tcx : TyCtxt < ' tcx > , key : DefId ) -> bool {
470+ debug ! ( "item_has_impossible_predicates(key={:?})" , key) ;
471+ let predicates = tcx. predicates_of ( key) . instantiate_identity ( tcx) . predicates ;
472+ let result = has_impossible_predicates ( tcx, predicates. into_iter ( ) ) ;
473+ debug ! ( "item_has_impossible_predicates(key={:?}) = {:?}" , key, result) ;
468474 result
469475}
470476
@@ -715,8 +721,7 @@ fn vtable_entries<'tcx>(
715721 // do not hold for this particular set of type parameters.
716722 // Note that this method could then never be called, so we
717723 // do not want to try and codegen it, in that case (see #23435).
718- let predicates = tcx. predicates_of ( def_id) . instantiate_own ( tcx, substs) ;
719- if impossible_predicates ( tcx, predicates. predicates ) {
724+ if tcx. instantiated_item_has_impossible_predicates ( ( def_id, substs) ) {
720725 debug ! ( "vtable_entries: predicates do not hold" ) ;
721726 return VtblEntry :: Vacant ;
722727 }
@@ -847,7 +852,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
847852 own_existential_vtable_entries,
848853 vtable_entries,
849854 vtable_trait_upcasting_coercion_new_vptr_slot,
850- subst_and_check_impossible_predicates,
855+ instantiated_item_has_impossible_predicates,
856+ item_has_impossible_predicates,
851857 thir_abstract_const : |tcx, def_id| {
852858 let def_id = def_id. expect_local ( ) ;
853859 if let Some ( def) = ty:: WithOptConstParam :: try_lookup ( def_id, tcx) {
0 commit comments