@@ -562,11 +562,20 @@ fn is_impossible_associated_item(
562562
563563 let generics = tcx. generics_of ( trait_item_def_id) ;
564564 let predicates = tcx. predicates_of ( trait_item_def_id) ;
565+
566+ // Be conservative in cases where we have `W<T: ?Sized>` and a method like `Self: Sized`,
567+ // since that method *may* have some substitutions where the predicates hold.
568+ //
569+ // This replicates the logic we use in coherence.
570+ let infcx =
571+ tcx. infer_ctxt ( ) . ignoring_regions ( ) . with_next_trait_solver ( true ) . intercrate ( true ) . build ( ) ;
572+ let param_env = ty:: ParamEnv :: empty ( ) ;
573+ let fresh_args = infcx. fresh_args_for_item ( tcx. def_span ( impl_def_id) , impl_def_id) ;
574+
565575 let impl_trait_ref = tcx
566576 . impl_trait_ref ( impl_def_id)
567577 . expect ( "expected impl to correspond to trait" )
568- . instantiate_identity ( ) ;
569- let param_env = tcx. param_env ( impl_def_id) ;
578+ . instantiate ( tcx, fresh_args) ;
570579
571580 let mut visitor = ReferencesOnlyParentGenerics { tcx, generics, trait_item_def_id } ;
572581 let predicates_for_trait = predicates. predicates . iter ( ) . filter_map ( |( pred, span) | {
@@ -580,16 +589,9 @@ fn is_impossible_associated_item(
580589 } )
581590 } ) ;
582591
583- let infcx = tcx. infer_ctxt ( ) . ignoring_regions ( ) . build ( ) ;
584- for obligation in predicates_for_trait {
585- // Ignore overflow error, to be conservative.
586- if let Ok ( result) = infcx. evaluate_obligation ( & obligation)
587- && !result. may_apply ( )
588- {
589- return true ;
590- }
591- }
592- false
592+ let ocx = ObligationCtxt :: new ( & infcx) ;
593+ ocx. register_obligations ( predicates_for_trait) ;
594+ !ocx. select_where_possible ( ) . is_empty ( )
593595}
594596
595597pub fn provide ( providers : & mut Providers ) {
0 commit comments