@@ -1296,12 +1296,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1296
1296
return false ;
1297
1297
}
1298
1298
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
-
1305
1299
// Otherwise, we can use the global cache.
1306
1300
true
1307
1301
}
@@ -1716,11 +1710,30 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1716
1710
{
1717
1711
debug ! ( "assemble_candidates_from_impls(obligation={:?})" , obligation) ;
1718
1712
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
+
1719
1732
self . tcx ( ) . for_each_relevant_impl (
1720
1733
obligation. predicate . def_id ( ) ,
1721
1734
obligation. predicate . 0 . trait_ref . self_ty ( ) ,
1722
1735
|impl_def_id| {
1723
- if self . infcx ( ) . emit_defaul_impl_candidates . get ( ) ||
1736
+ if self_trait_is_present . len ( ) > 0 ||
1724
1737
!self . tcx ( ) . impl_is_default ( impl_def_id) {
1725
1738
self . probe ( |this, snapshot| { /* [1] */
1726
1739
match this. match_impl ( impl_def_id, obligation, snapshot) {
0 commit comments