@@ -1254,6 +1254,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1254
1254
for ( kind, candidates) in
1255
1255
[ ( "inherent" , & self . inherent_candidates ) , ( "extension" , & self . extension_candidates ) ]
1256
1256
{
1257
+ if kind == "inherent" && self . should_skip_shadowable_inherent_numerical_methods ( ) {
1258
+ continue ;
1259
+ }
1260
+
1257
1261
debug ! ( "searching {} candidates" , kind) ;
1258
1262
let res = self . consider_candidates (
1259
1263
self_ty,
@@ -1690,6 +1694,26 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1690
1694
} )
1691
1695
}
1692
1696
1697
+ fn should_skip_shadowable_inherent_numerical_methods ( & self ) -> bool {
1698
+ let res = self . inherent_candidates . len ( ) > 1
1699
+ && self . extension_candidates . iter ( ) . any ( |cand| match cand. kind {
1700
+ TraitCandidate ( trait_ref) => {
1701
+ let trait_def_id = trait_ref. def_id ( ) ;
1702
+ self . tcx . crate_name ( trait_def_id. krate ) == sym:: compiler_builtins
1703
+ && [ sym:: Float , sym:: Int ] . contains ( & self . tcx . item_name ( trait_def_id) )
1704
+ }
1705
+ InherentImplCandidate ( _) | ObjectCandidate ( _) | WhereClauseCandidate ( _) => false ,
1706
+ } )
1707
+ && self . inherent_candidates . iter ( ) . all ( |cand| match cand. kind {
1708
+ InherentImplCandidate ( def_id) => {
1709
+ self . tcx . type_of ( def_id) . skip_binder ( ) . is_numeric ( )
1710
+ }
1711
+ ObjectCandidate ( _) | TraitCandidate ( _) | WhereClauseCandidate ( _) => false ,
1712
+ } ) ;
1713
+
1714
+ res
1715
+ }
1716
+
1693
1717
/// Sometimes we get in a situation where we have multiple probes that are all impls of the
1694
1718
/// same trait, but we don't know which impl to use. In this case, since in all cases the
1695
1719
/// external interface of the method can be determined from the trait, it's ok not to decide.
0 commit comments