]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #6896 - TaKO8Ki:refactor-lints-in-methods-module, r=phansch
authorbors <bors@rust-lang.org>
Mon, 22 Mar 2021 19:36:22 +0000 (19:36 +0000)
committerbors <bors@rust-lang.org>
Mon, 22 Mar 2021 19:36:22 +0000 (19:36 +0000)
Refactor lints in methods module

This PR refactors methods lints other than the lints I refactored in https://github.com/rust-lang/rust-clippy/pull/6826 and moves some functions to methods/utils.rs.
Basically, I follow the instruction described in #6680.

**For ease of review, I refactored step by step, keeping each commit small.**

closes https://github.com/rust-lang/rust-clippy/issues/6886
cc: `@phansch,` `@flip1995,` `@Y-Nak`

changelog: Move lints in methods module to their own modules and some function to methods/utils.rs.

1  2 
clippy_lints/src/methods/mod.rs

index 5be28354769ab858f985ed0ba02ba90c231827ca,a80162015dc91c97c133a16576cbef4a0660366d..b37d744269e7314d503d9c55079b556300553fc3
@@@ -1718,49 -1714,19 +1723,49 @@@ impl<'tcx> LateLintPass<'tcx> for Metho
              ["next", "skip_while"] => skip_while_next::check(cx, expr, arg_lists[1]),
              ["next", "iter"] => iter_next_slice::check(cx, expr, arg_lists[1]),
              ["map", "filter"] => filter_map::check(cx, expr, false),
-             ["map", "filter_map"] => filter_map_map::check(cx, expr, arg_lists[1], arg_lists[0]),
+             ["map", "filter_map"] => filter_map_map::check(cx, expr),
              ["next", "filter_map"] => filter_map_next::check(cx, expr, arg_lists[1], self.msrv.as_ref()),
              ["map", "find"] => filter_map::check(cx, expr, true),
-             ["flat_map", "filter"] => filter_flat_map::check(cx, expr, arg_lists[1], arg_lists[0]),
-             ["flat_map", "filter_map"] => filter_map_flat_map::check(cx, expr, arg_lists[1], arg_lists[0]),
+             ["flat_map", "filter"] => filter_flat_map::check(cx, expr),
+             ["flat_map", "filter_map"] => filter_map_flat_map::check(cx, expr),
              ["flat_map", ..] => flat_map_identity::check(cx, expr, arg_lists[0], method_spans[0]),
              ["flatten", "map"] => map_flatten::check(cx, expr, arg_lists[1]),
 -            ["is_some", "find"] => search_is_some::check(cx, expr, "find", arg_lists[1], arg_lists[0], method_spans[1]),
 -            ["is_some", "position"] => {
 -                search_is_some::check(cx, expr, "position", arg_lists[1], arg_lists[0], method_spans[1])
 +            [option_check_method, "find"] if "is_some" == *option_check_method || "is_none" == *option_check_method => {
 +                search_is_some::check(
 +                    cx,
 +                    expr,
 +                    "find",
 +                    option_check_method,
 +                    arg_lists[1],
 +                    arg_lists[0],
 +                    method_spans[1],
 +                )
              },
 -            ["is_some", "rposition"] => {
 -                search_is_some::check(cx, expr, "rposition", arg_lists[1], arg_lists[0], method_spans[1])
 +            [option_check_method, "position"]
 +                if "is_some" == *option_check_method || "is_none" == *option_check_method =>
 +            {
 +                search_is_some::check(
 +                    cx,
 +                    expr,
 +                    "position",
 +                    option_check_method,
 +                    arg_lists[1],
 +                    arg_lists[0],
 +                    method_spans[1],
 +                )
 +            },
 +            [option_check_method, "rposition"]
 +                if "is_some" == *option_check_method || "is_none" == *option_check_method =>
 +            {
 +                search_is_some::check(
 +                    cx,
 +                    expr,
 +                    "rposition",
 +                    option_check_method,
 +                    arg_lists[1],
 +                    arg_lists[0],
 +                    method_spans[1],
 +                )
              },
              ["extend", ..] => string_extend_chars::check(cx, expr, arg_lists[0]),
              ["count", "into_iter"] => iter_count::check(cx, expr, &arg_lists[1], "into_iter"),