@@ -45,6 +45,7 @@ mod iter_overeager_cloned;
4545mod iter_skip_next;
4646mod iter_with_drain;
4747mod iterator_step_by_zero;
48+ mod manual_next_back;
4849mod manual_ok_or;
4950mod manual_saturating_arithmetic;
5051mod manual_str_repeat;
@@ -3193,6 +3194,29 @@ declare_clippy_lint! {
31933194 "calling `drain` in order to `clear` a container"
31943195}
31953196
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+
31963220pub struct Methods {
31973221 avoid_breaking_exported_api : bool ,
31983222 msrv : Msrv ,
@@ -3321,6 +3345,7 @@ impl_lint_pass!(Methods => [
33213345 NEEDLESS_COLLECT ,
33223346 SUSPICIOUS_COMMAND_ARG_SPACE ,
33233347 CLEAR_WITH_DRAIN ,
3348+ MANUAL_NEXT_BACK ,
33243349] ) ;
33253350
33263351/// Extracts a method call name, args, and `Span` of the method name.
@@ -3677,6 +3702,7 @@ impl Methods {
36773702 ( "iter" , [ ] ) => iter_next_slice:: check ( cx, expr, recv2) ,
36783703 ( "skip" , [ arg] ) => iter_skip_next:: check ( cx, expr, recv2, arg) ,
36793704 ( "skip_while" , [ _] ) => skip_while_next:: check ( cx, expr) ,
3705+ ( "rev" , [ ] ) => manual_next_back:: check ( cx, expr, recv, recv2) ,
36803706 _ => { } ,
36813707 }
36823708 }
0 commit comments