@@ -1296,6 +1296,12 @@ 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+
12991305 // Otherwise, we can use the global cache.
13001306 true
13011307 }
@@ -1714,18 +1720,21 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17141720 obligation. predicate . def_id ( ) ,
17151721 obligation. predicate . 0 . trait_ref . self_ty ( ) ,
17161722 |impl_def_id| {
1717- self . probe ( |this, snapshot| { /* [1] */
1718- match this. match_impl ( impl_def_id, obligation, snapshot) {
1719- Ok ( skol_map) => {
1720- candidates. vec . push ( ImplCandidate ( impl_def_id) ) ;
1721-
1722- // NB: we can safely drop the skol map
1723- // since we are in a probe [1]
1724- mem:: drop ( skol_map) ;
1723+ if self . infcx ( ) . emit_defaul_impl_candidates . get ( ) ||
1724+ !self . tcx ( ) . impl_is_default ( impl_def_id) {
1725+ self . probe ( |this, snapshot| { /* [1] */
1726+ match this. match_impl ( impl_def_id, obligation, snapshot) {
1727+ Ok ( skol_map) => {
1728+ candidates. vec . push ( ImplCandidate ( impl_def_id) ) ;
1729+
1730+ // NB: we can safely drop the skol map
1731+ // since we are in a probe [1]
1732+ mem:: drop ( skol_map) ;
1733+ }
1734+ Err ( _) => { }
17251735 }
1726- Err ( _) => { }
1727- }
1728- } ) ;
1736+ } ) ;
1737+ }
17291738 }
17301739 ) ;
17311740
0 commit comments