@@ -53,25 +53,25 @@ enum Side {
53
53
54
54
impl IntPlusOne {
55
55
#[ 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 {
57
57
if let LitKind :: Int ( value, ..) = lit. kind {
58
58
return value == ( target_value as u128 ) ;
59
59
}
60
60
false
61
61
}
62
62
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 > {
64
64
match ( binop, & lhs. kind , & rhs. kind ) {
65
65
// case where `x - 1 >= ...` or `-1 + x >= ...`
66
66
( BinOpKind :: Ge , & ExprKind :: Binary ( ref lhskind, ref lhslhs, ref lhsrhs) , _) => {
67
67
match ( lhskind. node , & lhslhs. kind , & lhsrhs. kind ) {
68
68
// `-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 )
71
71
} ,
72
72
// `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 )
75
75
} ,
76
76
_ => None ,
77
77
}
@@ -82,11 +82,11 @@ impl IntPlusOne {
82
82
{
83
83
match ( & rhslhs. kind , & rhsrhs. kind ) {
84
84
// `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 )
87
87
} ,
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 )
90
90
} ,
91
91
_ => None ,
92
92
}
@@ -97,11 +97,11 @@ impl IntPlusOne {
97
97
{
98
98
match ( & lhslhs. kind , & lhsrhs. kind ) {
99
99
// `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 )
102
102
} ,
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 )
105
105
} ,
106
106
_ => None ,
107
107
}
@@ -110,12 +110,12 @@ impl IntPlusOne {
110
110
( BinOpKind :: Le , _, & ExprKind :: Binary ( ref rhskind, ref rhslhs, ref rhsrhs) ) => {
111
111
match ( rhskind. node , & rhslhs. kind , & rhsrhs. kind ) {
112
112
// `-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 )
115
115
} ,
116
116
// `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 )
119
119
} ,
120
120
_ => None ,
121
121
}
@@ -125,7 +125,6 @@ impl IntPlusOne {
125
125
}
126
126
127
127
fn generate_recommendation (
128
- self ,
129
128
cx : & EarlyContext < ' _ > ,
130
129
binop : BinOpKind ,
131
130
node : & Expr ,
@@ -149,7 +148,7 @@ impl IntPlusOne {
149
148
None
150
149
}
151
150
152
- fn emit_warning ( self , cx : & EarlyContext < ' _ > , block : & Expr , recommendation : String ) {
151
+ fn emit_warning ( cx : & EarlyContext < ' _ > , block : & Expr , recommendation : String ) {
153
152
span_lint_and_then (
154
153
cx,
155
154
INT_PLUS_ONE ,
@@ -170,8 +169,8 @@ impl IntPlusOne {
170
169
impl EarlyLintPass for IntPlusOne {
171
170
fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , item : & Expr ) {
172
171
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 ( ) ) ;
175
174
}
176
175
}
177
176
}
0 commit comments