@@ -425,17 +425,21 @@ where
425
425
/// Normalizes the predicates and checks whether they hold in an empty environment. If this
426
426
/// returns true, then either normalize encountered an error or one of the predicates did not
427
427
/// hold. Used when creating vtables to check for unsatisfiable methods.
428
- pub fn impossible_predicates < ' tcx > (
428
+ fn has_impossible_predicates < ' tcx > (
429
429
tcx : TyCtxt < ' tcx > ,
430
- predicates : Vec < ty:: Predicate < ' tcx > > ,
430
+ predicates : impl Iterator < Item = ty:: Predicate < ' tcx > > ,
431
431
) -> 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 < _ > > ( ) ;
433
436
434
- let result = tcx. infer_ctxt ( ) . enter ( |infcx| {
437
+ tcx. infer_ctxt ( ) . enter ( |infcx| {
435
438
let param_env = ty:: ParamEnv :: reveal_all ( ) ;
436
439
let mut selcx = SelectionContext :: new ( & infcx) ;
437
440
let mut fulfill_cx = FulfillmentContext :: new ( ) ;
438
441
let cause = ObligationCause :: dummy ( ) ;
442
+
439
443
let Normalized { value : predicates, obligations } =
440
444
normalize ( & mut selcx, param_env, cause. clone ( ) , predicates) ;
441
445
for obligation in obligations {
@@ -447,24 +451,26 @@ pub fn impossible_predicates<'tcx>(
447
451
}
448
452
449
453
let errors = fulfill_cx. select_all_or_error ( & infcx) ;
450
-
451
454
!errors. is_empty ( )
452
- } ) ;
453
- debug ! ( "impossible_predicates = {:?}" , result) ;
454
- result
455
+ } )
455
456
}
456
457
457
- fn subst_and_check_impossible_predicates < ' tcx > (
458
+ fn instantiated_item_has_impossible_predicates < ' tcx > (
458
459
tcx : TyCtxt < ' tcx > ,
459
460
key : ( DefId , SubstsRef < ' tcx > ) ,
460
461
) -> 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
+ }
466
468
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) ;
468
474
result
469
475
}
470
476
@@ -715,8 +721,7 @@ fn vtable_entries<'tcx>(
715
721
// do not hold for this particular set of type parameters.
716
722
// Note that this method could then never be called, so we
717
723
// 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) ) {
720
725
debug ! ( "vtable_entries: predicates do not hold" ) ;
721
726
return VtblEntry :: Vacant ;
722
727
}
@@ -847,7 +852,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
847
852
own_existential_vtable_entries,
848
853
vtable_entries,
849
854
vtable_trait_upcasting_coercion_new_vptr_slot,
850
- subst_and_check_impossible_predicates,
855
+ instantiated_item_has_impossible_predicates,
856
+ item_has_impossible_predicates,
851
857
thir_abstract_const : |tcx, def_id| {
852
858
let def_id = def_id. expect_local ( ) ;
853
859
if let Some ( def) = ty:: WithOptConstParam :: try_lookup ( def_id, tcx) {
0 commit comments