diff options
| author | Takayuki Maeda <takoyaki0316@gmail.com> | 2021-03-03 00:31:15 +0900 |
|---|---|---|
| committer | Takayuki Maeda <takoyaki0316@gmail.com> | 2021-03-11 19:37:16 +0900 |
| commit | 483bac2dc0a47df87141a98df1d470b25cd2eda3 (patch) | |
| tree | 26d467f555e9c471029e6ce88c8aa36cf1aea8f7 | |
| parent | f0f07accbce24adb5706eeb4e14e0e1c6b2b973b (diff) | |
| download | rust-483bac2dc0a47df87141a98df1d470b25cd2eda3.tar.gz rust-483bac2dc0a47df87141a98df1d470b25cd2eda3.zip | |
move skip_while_next to its own module
| -rw-r--r-- | clippy_lints/src/methods/mod.rs | 22 | ||||
| -rw-r--r-- | clippy_lints/src/methods/skip_while_next.rs | 20 |
2 files changed, 22 insertions, 20 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 71080e9bef0..34def45a8dd 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -11,6 +11,7 @@ mod iter_count; mod manual_saturating_arithmetic; mod ok_expect; mod option_map_unwrap_or; +mod skip_while_next; mod unnecessary_filter_map; mod unnecessary_lazy_eval; mod unwrap_used; @@ -1679,7 +1680,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { } }, ["next", "filter"] => filter_next::check(cx, expr, arg_lists[1]), - ["next", "skip_while"] => lint_skip_while_next(cx, expr, arg_lists[1]), + ["next", "skip_while"] => skip_while_next::check(cx, expr, arg_lists[1]), ["next", "iter"] => lint_iter_next(cx, expr, arg_lists[1]), ["map", "filter"] => lint_filter_map(cx, expr, false), ["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 ); } -/// lint use of `skip_while().next()` for `Iterators` -fn lint_skip_while_next<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - _skip_while_args: &'tcx [hir::Expr<'_>], -) { - // lint if caller of `.skip_while().next()` is an Iterator - if match_trait_method(cx, expr, &paths::ITERATOR) { - span_lint_and_help( - cx, - SKIP_WHILE_NEXT, - expr.span, - "called `skip_while(<p>).next()` on an `Iterator`", - None, - "this is more succinctly expressed by calling `.find(!<p>)` instead", - ); - } -} - /// lint use of `filter().map()` or `find().map()` for `Iterators` fn lint_filter_map<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, is_find: bool) { if_chain! { diff --git a/clippy_lints/src/methods/skip_while_next.rs b/clippy_lints/src/methods/skip_while_next.rs new file mode 100644 index 00000000000..8ba6ae95200 --- /dev/null +++ b/clippy_lints/src/methods/skip_while_next.rs @@ -0,0 +1,20 @@ +use crate::utils::{match_trait_method, paths, span_lint_and_help}; +use rustc_hir as hir; +use rustc_lint::LateContext; + +use super::SKIP_WHILE_NEXT; + +/// lint use of `skip_while().next()` for `Iterators` +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, _skip_while_args: &'tcx [hir::Expr<'_>]) { + // lint if caller of `.skip_while().next()` is an Iterator + if match_trait_method(cx, expr, &paths::ITERATOR) { + span_lint_and_help( + cx, + SKIP_WHILE_NEXT, + expr.span, + "called `skip_while(<p>).next()` on an `Iterator`", + None, + "this is more succinctly expressed by calling `.find(!<p>)` instead", + ); + } +} |
