@@ -45,6 +45,7 @@ mod iter_overeager_cloned;
45
45
mod iter_skip_next;
46
46
mod iter_with_drain;
47
47
mod iterator_step_by_zero;
48
+ mod manual_next_back;
48
49
mod manual_ok_or;
49
50
mod manual_saturating_arithmetic;
50
51
mod manual_str_repeat;
@@ -3193,6 +3194,29 @@ declare_clippy_lint! {
3193
3194
"calling `drain` in order to `clear` a container"
3194
3195
}
3195
3196
3197
+ declare_clippy_lint ! {
3198
+ /// ### What it does
3199
+ /// Checks for `.rev().next()` on a `DoubleEndedIterator`
3200
+ ///
3201
+ /// ### Why is this bad?
3202
+ /// `.next_back()` is cleaner.
3203
+ ///
3204
+ /// ### Example
3205
+ /// ```rust
3206
+ /// # let foo = [0; 10];
3207
+ /// foo.iter().rev().next();
3208
+ /// ```
3209
+ /// Use instead:
3210
+ /// ```rust
3211
+ /// # let foo = [0; 10];
3212
+ /// foo.iter().next_back();
3213
+ /// ```
3214
+ #[ clippy:: version = "1.71.0" ]
3215
+ pub MANUAL_NEXT_BACK ,
3216
+ style,
3217
+ "manual reverse iteration of `DoubleEndedIterator`"
3218
+ }
3219
+
3196
3220
pub struct Methods {
3197
3221
avoid_breaking_exported_api : bool ,
3198
3222
msrv : Msrv ,
@@ -3321,6 +3345,7 @@ impl_lint_pass!(Methods => [
3321
3345
NEEDLESS_COLLECT ,
3322
3346
SUSPICIOUS_COMMAND_ARG_SPACE ,
3323
3347
CLEAR_WITH_DRAIN ,
3348
+ MANUAL_NEXT_BACK ,
3324
3349
] ) ;
3325
3350
3326
3351
/// Extracts a method call name, args, and `Span` of the method name.
@@ -3677,6 +3702,7 @@ impl Methods {
3677
3702
( "iter" , [ ] ) => iter_next_slice:: check ( cx, expr, recv2) ,
3678
3703
( "skip" , [ arg] ) => iter_skip_next:: check ( cx, expr, recv2, arg) ,
3679
3704
( "skip_while" , [ _] ) => skip_while_next:: check ( cx, expr) ,
3705
+ ( "rev" , [ ] ) => manual_next_back:: check ( cx, expr, recv, recv2) ,
3680
3706
_ => { } ,
3681
3707
}
3682
3708
}
0 commit comments