@@ -3,7 +3,7 @@ use clippy_utils::{higher, peel_blocks_with_stmt, SpanlessEq};
3
3
use if_chain:: if_chain;
4
4
use rustc_ast:: ast:: LitKind ;
5
5
use rustc_errors:: Applicability ;
6
- use rustc_hir:: { lang_items :: LangItem , BinOpKind , Expr , ExprKind , QPath } ;
6
+ use rustc_hir:: { BinOpKind , Expr , ExprKind , QPath } ;
7
7
use rustc_lint:: { LateContext , LateLintPass } ;
8
8
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
9
9
@@ -82,14 +82,6 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
82
82
83
83
// Get the variable name
84
84
let var_name = ares_path. segments[ 0 ] . ident. name. as_str( ) ;
85
- const INT_TYPES : [ LangItem ; 5 ] = [
86
- LangItem :: I8 ,
87
- LangItem :: I16 ,
88
- LangItem :: I32 ,
89
- LangItem :: I64 ,
90
- LangItem :: Isize
91
- ] ;
92
-
93
85
match cond_num_val. kind {
94
86
ExprKind :: Lit ( ref cond_lit) => {
95
87
// Check if the constant is zero
@@ -105,8 +97,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
105
97
if name. ident. as_str( ) == "MIN" ;
106
98
if let Some ( const_id) = cx. typeck_results( ) . type_dependent_def_id( cond_num_val. hir_id) ;
107
99
if let Some ( impl_id) = cx. tcx. impl_of_method( const_id) ;
108
- let mut int_ids = INT_TYPES . iter ( ) . filter_map ( | & ty| cx. tcx. lang_items ( ) . require ( ty ) . ok ( ) ) ;
109
- if int_ids . any ( |int_id| int_id == impl_id) ;
100
+ if let None = cx. tcx. impl_trait_ref ( impl_id ) ; // An inherent impl
101
+ if cx . tcx . type_of ( impl_id) . is_integral ( ) ;
110
102
then {
111
103
print_lint_and_sugg( cx, var_name, expr)
112
104
}
@@ -118,8 +110,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
118
110
if name. ident. as_str( ) == "min_value" ;
119
111
if let Some ( func_id) = cx. typeck_results( ) . type_dependent_def_id( func. hir_id) ;
120
112
if let Some ( impl_id) = cx. tcx. impl_of_method( func_id) ;
121
- let mut int_ids = INT_TYPES . iter ( ) . filter_map ( | & ty| cx. tcx. lang_items ( ) . require ( ty ) . ok ( ) ) ;
122
- if int_ids . any ( |int_id| int_id == impl_id) ;
113
+ if let None = cx. tcx. impl_trait_ref ( impl_id ) ; // An inherent impl
114
+ if cx . tcx . type_of ( impl_id) . is_integral ( ) ;
123
115
then {
124
116
print_lint_and_sugg( cx, var_name, expr)
125
117
}
0 commit comments