@@ -3,7 +3,7 @@ use clippy_utils::{higher, peel_blocks_with_stmt, SpanlessEq};
33use if_chain:: if_chain;
44use rustc_ast:: ast:: LitKind ;
55use rustc_errors:: Applicability ;
6- use rustc_hir:: { lang_items :: LangItem , BinOpKind , Expr , ExprKind , QPath } ;
6+ use rustc_hir:: { BinOpKind , Expr , ExprKind , QPath } ;
77use rustc_lint:: { LateContext , LateLintPass } ;
88use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
99
@@ -82,14 +82,6 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
8282
8383 // Get the variable name
8484 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-
9385 match cond_num_val. kind {
9486 ExprKind :: Lit ( ref cond_lit) => {
9587 // Check if the constant is zero
@@ -105,8 +97,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
10597 if name. ident. as_str( ) == "MIN" ;
10698 if let Some ( const_id) = cx. typeck_results( ) . type_dependent_def_id( cond_num_val. hir_id) ;
10799 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 ( ) ;
110102 then {
111103 print_lint_and_sugg( cx, var_name, expr)
112104 }
@@ -118,8 +110,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
118110 if name. ident. as_str( ) == "min_value" ;
119111 if let Some ( func_id) = cx. typeck_results( ) . type_dependent_def_id( func. hir_id) ;
120112 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 ( ) ;
123115 then {
124116 print_lint_and_sugg( cx, var_name, expr)
125117 }
0 commit comments