Rename 'flat_map' → 'flat_map_identity'

This commit is contained in:
Jeremy Stucki 2019-08-11 20:34:25 +02:00
parent f0ce04f814
commit b651f19eb8
No known key found for this signature in database
GPG Key ID: EEFCA93148042655
6 changed files with 15 additions and 11 deletions

View File

@ -947,7 +947,7 @@ Released 2018-09-13
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
[`find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#find_map
[`flat_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map
[`flat_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_identity
[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic
[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const

View File

@ -643,7 +643,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
methods::FILTER_MAP,
methods::FILTER_MAP_NEXT,
methods::FIND_MAP,
methods::FLAT_MAP,
methods::FLAT_MAP_IDENTITY,
methods::MAP_FLATTEN,
methods::OPTION_MAP_UNWRAP_OR,
methods::OPTION_MAP_UNWRAP_OR_ELSE,

View File

@ -357,7 +357,7 @@ declare_clippy_lint! {
/// ```rust
/// iter.flatten()
/// ```
pub FLAT_MAP,
pub FLAT_MAP_IDENTITY,
pedantic,
"call to `flat_map` where `flatten` is sufficient"
}
@ -912,7 +912,7 @@ declare_lint_pass!(Methods => [
FILTER_NEXT,
FILTER_MAP,
FILTER_MAP_NEXT,
FLAT_MAP,
FLAT_MAP_IDENTITY,
FIND_MAP,
MAP_FLATTEN,
ITER_NTH,
@ -953,7 +953,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
["map", "find"] => lint_find_map(cx, expr, arg_lists[1], arg_lists[0]),
["flat_map", "filter"] => lint_filter_flat_map(cx, expr, arg_lists[1], arg_lists[0]),
["flat_map", "filter_map"] => lint_filter_map_flat_map(cx, expr, arg_lists[1], arg_lists[0]),
["flat_map", ..] => lint_flat_map(cx, expr, arg_lists[0]),
["flat_map", ..] => lint_flat_map_identity(cx, expr, arg_lists[0]),
["flatten", "map"] => lint_map_flatten(cx, expr, arg_lists[1]),
["is_some", "find"] => lint_search_is_some(cx, expr, "find", arg_lists[1], arg_lists[0]),
["is_some", "position"] => lint_search_is_some(cx, expr, "position", arg_lists[1], arg_lists[0]),
@ -2165,7 +2165,11 @@ fn lint_filter_map_flat_map<'a, 'tcx>(
}
/// lint use of `flat_map` for `Iterators` where `flatten` would be sufficient
fn lint_flat_map<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, flat_map_args: &'tcx [hir::Expr]) {
fn lint_flat_map_identity<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
expr: &'tcx hir::Expr,
flat_map_args: &'tcx [hir::Expr],
) {
if_chain! {
if match_trait_method(cx, expr, &paths::ITERATOR);
@ -2183,7 +2187,7 @@ fn lint_flat_map<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, fl
then {
let msg = "called `flat_map(|x| x)` on an `Iterator`. \
This can be simplified by calling `flatten().`";
span_lint(cx, FLAT_MAP, expr.span, msg);
span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
}
}
@ -2201,7 +2205,7 @@ fn lint_flat_map<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, fl
then {
let msg = "called `flat_map(std::convert::identity)` on an `Iterator`. \
This can be simplified by calling `flatten().`";
span_lint(cx, FLAT_MAP, expr.span, msg);
span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
}
}
}

View File

@ -554,7 +554,7 @@ pub const ALL_LINTS: [Lint; 310] = [
module: "methods",
},
Lint {
name: "flat_map",
name: "flat_map_identity",
group: "pedantic",
desc: "call to `flat_map` where `flatten` is sufficient",
deprecation: None,

View File

@ -1,4 +1,4 @@
#![warn(clippy::flat_map)]
#![warn(clippy::flat_map_identity)]
use std::convert;

View File

@ -4,7 +4,7 @@ error: called `flat_map(|x| x)` on an `Iterator`. This can be simplified by call
LL | iterator.flat_map(|x| x);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::flat-map` implied by `-D warnings`
= note: `-D clippy::flat-map-identity` implied by `-D warnings`
error: called `flat_map(std::convert::identity)` on an `Iterator`. This can be simplified by calling `flatten().`
--> $DIR/unnecessary_flat_map.rs:10:23