@@ -53,25 +53,25 @@ enum Side {
5353
5454impl IntPlusOne {
5555 #[ allow( clippy:: cast_sign_loss) ]
56- fn check_lit ( self , lit : & Lit , target_value : i128 ) -> bool {
56+ fn check_lit ( lit : & Lit , target_value : i128 ) -> bool {
5757 if let LitKind :: Int ( value, ..) = lit. kind {
5858 return value == ( target_value as u128 ) ;
5959 }
6060 false
6161 }
6262
63- fn check_binop ( self , cx : & EarlyContext < ' _ > , binop : BinOpKind , lhs : & Expr , rhs : & Expr ) -> Option < String > {
63+ fn check_binop ( cx : & EarlyContext < ' _ > , binop : BinOpKind , lhs : & Expr , rhs : & Expr ) -> Option < String > {
6464 match ( binop, & lhs. kind , & rhs. kind ) {
6565 // case where `x - 1 >= ...` or `-1 + x >= ...`
6666 ( BinOpKind :: Ge , & ExprKind :: Binary ( ref lhskind, ref lhslhs, ref lhsrhs) , _) => {
6767 match ( lhskind. node , & lhslhs. kind , & lhsrhs. kind ) {
6868 // `-1 + x`
69- ( BinOpKind :: Add , & ExprKind :: Lit ( ref lit) , _) if self . check_lit ( lit, -1 ) => {
70- self . generate_recommendation ( cx, binop, lhsrhs, rhs, Side :: LHS )
69+ ( BinOpKind :: Add , & ExprKind :: Lit ( ref lit) , _) if Self :: check_lit ( lit, -1 ) => {
70+ Self :: generate_recommendation ( cx, binop, lhsrhs, rhs, Side :: LHS )
7171 } ,
7272 // `x - 1`
73- ( BinOpKind :: Sub , _, & ExprKind :: Lit ( ref lit) ) if self . check_lit ( lit, 1 ) => {
74- self . generate_recommendation ( cx, binop, lhslhs, rhs, Side :: LHS )
73+ ( BinOpKind :: Sub , _, & ExprKind :: Lit ( ref lit) ) if Self :: check_lit ( lit, 1 ) => {
74+ Self :: generate_recommendation ( cx, binop, lhslhs, rhs, Side :: LHS )
7575 } ,
7676 _ => None ,
7777 }
@@ -82,11 +82,11 @@ impl IntPlusOne {
8282 {
8383 match ( & rhslhs. kind , & rhsrhs. kind ) {
8484 // `y + 1` and `1 + y`
85- ( & ExprKind :: Lit ( ref lit) , _) if self . check_lit ( lit, 1 ) => {
86- self . generate_recommendation ( cx, binop, rhsrhs, lhs, Side :: RHS )
85+ ( & ExprKind :: Lit ( ref lit) , _) if Self :: check_lit ( lit, 1 ) => {
86+ Self :: generate_recommendation ( cx, binop, rhsrhs, lhs, Side :: RHS )
8787 } ,
88- ( _, & ExprKind :: Lit ( ref lit) ) if self . check_lit ( lit, 1 ) => {
89- self . generate_recommendation ( cx, binop, rhslhs, lhs, Side :: RHS )
88+ ( _, & ExprKind :: Lit ( ref lit) ) if Self :: check_lit ( lit, 1 ) => {
89+ Self :: generate_recommendation ( cx, binop, rhslhs, lhs, Side :: RHS )
9090 } ,
9191 _ => None ,
9292 }
@@ -97,11 +97,11 @@ impl IntPlusOne {
9797 {
9898 match ( & lhslhs. kind , & lhsrhs. kind ) {
9999 // `1 + x` and `x + 1`
100- ( & ExprKind :: Lit ( ref lit) , _) if self . check_lit ( lit, 1 ) => {
101- self . generate_recommendation ( cx, binop, lhsrhs, rhs, Side :: LHS )
100+ ( & ExprKind :: Lit ( ref lit) , _) if Self :: check_lit ( lit, 1 ) => {
101+ Self :: generate_recommendation ( cx, binop, lhsrhs, rhs, Side :: LHS )
102102 } ,
103- ( _, & ExprKind :: Lit ( ref lit) ) if self . check_lit ( lit, 1 ) => {
104- self . generate_recommendation ( cx, binop, lhslhs, rhs, Side :: LHS )
103+ ( _, & ExprKind :: Lit ( ref lit) ) if Self :: check_lit ( lit, 1 ) => {
104+ Self :: generate_recommendation ( cx, binop, lhslhs, rhs, Side :: LHS )
105105 } ,
106106 _ => None ,
107107 }
@@ -110,12 +110,12 @@ impl IntPlusOne {
110110 ( BinOpKind :: Le , _, & ExprKind :: Binary ( ref rhskind, ref rhslhs, ref rhsrhs) ) => {
111111 match ( rhskind. node , & rhslhs. kind , & rhsrhs. kind ) {
112112 // `-1 + y`
113- ( BinOpKind :: Add , & ExprKind :: Lit ( ref lit) , _) if self . check_lit ( lit, -1 ) => {
114- self . generate_recommendation ( cx, binop, rhsrhs, lhs, Side :: RHS )
113+ ( BinOpKind :: Add , & ExprKind :: Lit ( ref lit) , _) if Self :: check_lit ( lit, -1 ) => {
114+ Self :: generate_recommendation ( cx, binop, rhsrhs, lhs, Side :: RHS )
115115 } ,
116116 // `y - 1`
117- ( BinOpKind :: Sub , _, & ExprKind :: Lit ( ref lit) ) if self . check_lit ( lit, 1 ) => {
118- self . generate_recommendation ( cx, binop, rhslhs, lhs, Side :: RHS )
117+ ( BinOpKind :: Sub , _, & ExprKind :: Lit ( ref lit) ) if Self :: check_lit ( lit, 1 ) => {
118+ Self :: generate_recommendation ( cx, binop, rhslhs, lhs, Side :: RHS )
119119 } ,
120120 _ => None ,
121121 }
@@ -125,7 +125,6 @@ impl IntPlusOne {
125125 }
126126
127127 fn generate_recommendation (
128- self ,
129128 cx : & EarlyContext < ' _ > ,
130129 binop : BinOpKind ,
131130 node : & Expr ,
@@ -149,7 +148,7 @@ impl IntPlusOne {
149148 None
150149 }
151150
152- fn emit_warning ( self , cx : & EarlyContext < ' _ > , block : & Expr , recommendation : String ) {
151+ fn emit_warning ( cx : & EarlyContext < ' _ > , block : & Expr , recommendation : String ) {
153152 span_lint_and_then (
154153 cx,
155154 INT_PLUS_ONE ,
@@ -170,8 +169,8 @@ impl IntPlusOne {
170169impl EarlyLintPass for IntPlusOne {
171170 fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , item : & Expr ) {
172171 if let ExprKind :: Binary ( ref kind, ref lhs, ref rhs) = item. kind {
173- if let Some ( ref rec) = self . check_binop ( cx, kind. node , lhs, rhs) {
174- self . emit_warning ( cx, item, rec. clone ( ) ) ;
172+ if let Some ( ref rec) = Self :: check_binop ( cx, kind. node , lhs, rhs) {
173+ Self :: emit_warning ( cx, item, rec. clone ( ) ) ;
175174 }
176175 }
177176 }
0 commit comments