@@ -8,7 +8,7 @@ use syntax::source_map::Spanned;
88
99use crate :: utils:: sugg:: Sugg ;
1010use 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} ;
1212
1313declare_clippy_lint ! {
1414 /// **What it does:** Checks for calling `.step_by(0)` on iterators,
@@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
132132 if iter_path. ident. name == sym!( iter) ;
133133 // range expression in `.zip()` call: `0..x.len()`
134134 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 ) ;
136136 // `.len()` call
137137 if let ExprKind :: MethodCall ( ref len_path, _, ref len_args) = end. node;
138138 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) {
164164 end: Some ( end) ,
165165 limits: RangeLimits :: HalfOpen
166166 } ) = higher:: range( cx, expr) ;
167- if let Some ( y) = y_plus_one( end) ;
167+ if let Some ( y) = y_plus_one( cx , end) ;
168168 then {
169169 let span = if expr. span. from_expansion( ) {
170170 expr. span
@@ -209,7 +209,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr) {
209209fn check_inclusive_range_minus_one ( cx : & LateContext < ' _ , ' _ > , expr : & Expr ) {
210210 if_chain ! {
211211 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) ;
213213 then {
214214 span_lint_and_then(
215215 cx,
@@ -239,7 +239,7 @@ fn has_step_by(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
239239 get_trait_def_id ( cx, & paths:: ITERATOR ) . map_or ( false , |iterator_trait| implements_trait ( cx, ty, iterator_trait, & [ ] ) )
240240}
241241
242- fn y_plus_one ( expr : & Expr ) -> Option < & Expr > {
242+ fn y_plus_one < ' t > ( cx : & LateContext < ' _ , ' _ > , expr : & ' t Expr ) -> Option < & ' t Expr > {
243243 match expr. node {
244244 ExprKind :: Binary (
245245 Spanned {
@@ -248,9 +248,9 @@ fn y_plus_one(expr: &Expr) -> Option<&Expr> {
248248 ref lhs,
249249 ref rhs,
250250 ) => {
251- if is_integer_literal ( lhs, 1 ) {
251+ if is_integer_const ( cx , lhs, 1 ) {
252252 Some ( rhs)
253- } else if is_integer_literal ( rhs, 1 ) {
253+ } else if is_integer_const ( cx , rhs, 1 ) {
254254 Some ( lhs)
255255 } else {
256256 None
@@ -260,15 +260,15 @@ fn y_plus_one(expr: &Expr) -> Option<&Expr> {
260260 }
261261}
262262
263- fn y_minus_one ( expr : & Expr ) -> Option < & Expr > {
263+ fn y_minus_one < ' t > ( cx : & LateContext < ' _ , ' _ > , expr : & ' t Expr ) -> Option < & ' t Expr > {
264264 match expr. node {
265265 ExprKind :: Binary (
266266 Spanned {
267267 node : BinOpKind :: Sub , ..
268268 } ,
269269 ref lhs,
270270 ref rhs,
271- ) if is_integer_literal ( rhs, 1 ) => Some ( lhs) ,
271+ ) if is_integer_const ( cx , rhs, 1 ) => Some ( lhs) ,
272272 _ => None ,
273273 }
274274}
0 commit comments