Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename 'flat_map' → 'flat_map_identity'
  • Loading branch information
jeremystucki committed Aug 11, 2019
commit b651f19eb87db789f8fd24a7791add446d869630
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 10 additions & 6 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ declare_clippy_lint! {
/// ```rust
/// iter.flatten()
/// ```
pub FLAT_MAP,
pub FLAT_MAP_IDENTITY,
pedantic,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a style or complexity lint IMO.

Everything else LGTM

"call to `flat_map` where `flatten` is sufficient"
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unnecessary_flat_map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![warn(clippy::flat_map)]
#![warn(clippy::flat_map_identity)]

use std::convert;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unnecessary_flat_map.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down