@@ -8,7 +8,7 @@ use syntax::source_map::Spanned;
8
8
9
9
use crate :: utils:: sugg:: Sugg ;
10
10
use crate :: utils:: { get_trait_def_id, higher, implements_trait, SpanlessEq } ;
11
- use crate :: utils:: { is_integer_literal , paths, snippet, snippet_opt, span_lint, span_lint_and_then} ;
11
+ use crate :: utils:: { is_integer_const , paths, snippet, snippet_opt, span_lint, span_lint_and_then} ;
12
12
13
13
declare_clippy_lint ! {
14
14
/// **What it does:** Checks for calling `.step_by(0)` on iterators,
@@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
132
132
if iter_path. ident. name == sym!( iter) ;
133
133
// range expression in `.zip()` call: `0..x.len()`
134
134
if let Some ( higher:: Range { start: Some ( start) , end: Some ( end) , .. } ) = higher:: range( cx, zip_arg) ;
135
- if is_integer_literal ( start, 0 ) ;
135
+ if is_integer_const ( cx , start, 0 ) ;
136
136
// `.len()` call
137
137
if let ExprKind :: MethodCall ( ref len_path, _, ref len_args) = end. node;
138
138
if len_path. ident. name == sym!( len) && len_args. len( ) == 1 ;
@@ -164,7 +164,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr) {
164
164
end: Some ( end) ,
165
165
limits: RangeLimits :: HalfOpen
166
166
} ) = higher:: range( cx, expr) ;
167
- if let Some ( y) = y_plus_one( end) ;
167
+ if let Some ( y) = y_plus_one( cx , end) ;
168
168
then {
169
169
let span = if expr. span. from_expansion( ) {
170
170
expr. span
@@ -209,7 +209,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr) {
209
209
fn check_inclusive_range_minus_one ( cx : & LateContext < ' _ , ' _ > , expr : & Expr ) {
210
210
if_chain ! {
211
211
if let Some ( higher:: Range { start, end: Some ( end) , limits: RangeLimits :: Closed } ) = higher:: range( cx, expr) ;
212
- if let Some ( y) = y_minus_one( end) ;
212
+ if let Some ( y) = y_minus_one( cx , end) ;
213
213
then {
214
214
span_lint_and_then(
215
215
cx,
@@ -239,7 +239,7 @@ fn has_step_by(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
239
239
get_trait_def_id ( cx, & paths:: ITERATOR ) . map_or ( false , |iterator_trait| implements_trait ( cx, ty, iterator_trait, & [ ] ) )
240
240
}
241
241
242
- fn y_plus_one ( expr : & Expr ) -> Option < & Expr > {
242
+ fn y_plus_one < ' t > ( cx : & LateContext < ' _ , ' _ > , expr : & ' t Expr ) -> Option < & ' t Expr > {
243
243
match expr. node {
244
244
ExprKind :: Binary (
245
245
Spanned {
@@ -248,9 +248,9 @@ fn y_plus_one(expr: &Expr) -> Option<&Expr> {
248
248
ref lhs,
249
249
ref rhs,
250
250
) => {
251
- if is_integer_literal ( lhs, 1 ) {
251
+ if is_integer_const ( cx , lhs, 1 ) {
252
252
Some ( rhs)
253
- } else if is_integer_literal ( rhs, 1 ) {
253
+ } else if is_integer_const ( cx , rhs, 1 ) {
254
254
Some ( lhs)
255
255
} else {
256
256
None
@@ -260,15 +260,15 @@ fn y_plus_one(expr: &Expr) -> Option<&Expr> {
260
260
}
261
261
}
262
262
263
- fn y_minus_one ( expr : & Expr ) -> Option < & Expr > {
263
+ fn y_minus_one < ' t > ( cx : & LateContext < ' _ , ' _ > , expr : & ' t Expr ) -> Option < & ' t Expr > {
264
264
match expr. node {
265
265
ExprKind :: Binary (
266
266
Spanned {
267
267
node : BinOpKind :: Sub , ..
268
268
} ,
269
269
ref lhs,
270
270
ref rhs,
271
- ) if is_integer_literal ( rhs, 1 ) => Some ( lhs) ,
271
+ ) if is_integer_const ( cx , rhs, 1 ) => Some ( lhs) ,
272
272
_ => None ,
273
273
}
274
274
}
0 commit comments