Skip to content

Commit 483bac2

Browse files
committed
move skip_while_next to its own module
1 parent f0f07ac commit 483bac2

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod iter_count;
1111
mod manual_saturating_arithmetic;
1212
mod ok_expect;
1313
mod option_map_unwrap_or;
14+
mod skip_while_next;
1415
mod unnecessary_filter_map;
1516
mod unnecessary_lazy_eval;
1617
mod unwrap_used;
@@ -1679,7 +1680,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
16791680
}
16801681
},
16811682
["next", "filter"] => filter_next::check(cx, expr, arg_lists[1]),
1682-
["next", "skip_while"] => lint_skip_while_next(cx, expr, arg_lists[1]),
1683+
["next", "skip_while"] => skip_while_next::check(cx, expr, arg_lists[1]),
16831684
["next", "iter"] => lint_iter_next(cx, expr, arg_lists[1]),
16841685
["map", "filter"] => lint_filter_map(cx, expr, false),
16851686
["map", "filter_map"] => lint_filter_map_map(cx, expr, arg_lists[1], arg_lists[0]),
@@ -2965,25 +2966,6 @@ fn lint_map_or_none<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map
29652966
);
29662967
}
29672968

2968-
/// lint use of `skip_while().next()` for `Iterators`
2969-
fn lint_skip_while_next<'tcx>(
2970-
cx: &LateContext<'tcx>,
2971-
expr: &'tcx hir::Expr<'_>,
2972-
_skip_while_args: &'tcx [hir::Expr<'_>],
2973-
) {
2974-
// lint if caller of `.skip_while().next()` is an Iterator
2975-
if match_trait_method(cx, expr, &paths::ITERATOR) {
2976-
span_lint_and_help(
2977-
cx,
2978-
SKIP_WHILE_NEXT,
2979-
expr.span,
2980-
"called `skip_while(<p>).next()` on an `Iterator`",
2981-
None,
2982-
"this is more succinctly expressed by calling `.find(!<p>)` instead",
2983-
);
2984-
}
2985-
}
2986-
29872969
/// lint use of `filter().map()` or `find().map()` for `Iterators`
29882970
fn lint_filter_map<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, is_find: bool) {
29892971
if_chain! {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::utils::{match_trait_method, paths, span_lint_and_help};
2+
use rustc_hir as hir;
3+
use rustc_lint::LateContext;
4+
5+
use super::SKIP_WHILE_NEXT;
6+
7+
/// lint use of `skip_while().next()` for `Iterators`
8+
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, _skip_while_args: &'tcx [hir::Expr<'_>]) {
9+
// lint if caller of `.skip_while().next()` is an Iterator
10+
if match_trait_method(cx, expr, &paths::ITERATOR) {
11+
span_lint_and_help(
12+
cx,
13+
SKIP_WHILE_NEXT,
14+
expr.span,
15+
"called `skip_while(<p>).next()` on an `Iterator`",
16+
None,
17+
"this is more succinctly expressed by calling `.find(!<p>)` instead",
18+
);
19+
}
20+
}

0 commit comments

Comments
 (0)