@@ -1296,12 +1296,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
12961296 return false ;
12971297 }
12981298
1299- // Using local cache if the infcx can emit `default impls`
1300- if self . infcx . emit_defaul_impl_candidates . get ( ) {
1301- return false ;
1302- }
1303-
1304-
13051299 // Otherwise, we can use the global cache.
13061300 true
13071301 }
@@ -1716,11 +1710,30 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17161710 {
17171711 debug ! ( "assemble_candidates_from_impls(obligation={:?})" , obligation) ;
17181712
1713+ // Check if default impls should be emitted.
1714+ // default impls are emitted if the param_env is refered to a default impl.
1715+ // The param_env should contain a Self: Trait<..> predicate in those cases
1716+ let self_trait_is_present: Vec < & ty:: Predicate < ' tcx > > =
1717+ obligation. param_env
1718+ . caller_bounds
1719+ . iter ( )
1720+ . filter ( |predicate| {
1721+ match * * predicate {
1722+ ty:: Predicate :: Trait ( ref trait_predicate) => {
1723+ trait_predicate. def_id ( ) ==
1724+ obligation. predicate . def_id ( ) &&
1725+ obligation. predicate . 0 . trait_ref . self_ty ( ) ==
1726+ trait_predicate. skip_binder ( ) . self_ty ( )
1727+ }
1728+ _ => false
1729+ }
1730+ } ) . collect :: < Vec < & ty:: Predicate < ' tcx > > > ( ) ;
1731+
17191732 self . tcx ( ) . for_each_relevant_impl (
17201733 obligation. predicate . def_id ( ) ,
17211734 obligation. predicate . 0 . trait_ref . self_ty ( ) ,
17221735 |impl_def_id| {
1723- if self . infcx ( ) . emit_defaul_impl_candidates . get ( ) ||
1736+ if self_trait_is_present . len ( ) > 0 ||
17241737 !self . tcx ( ) . impl_is_default ( impl_def_id) {
17251738 self . probe ( |this, snapshot| { /* [1] */
17261739 match this. match_impl ( impl_def_id, obligation, snapshot) {
0 commit comments