Skip to content

Commit b651f19

Browse files
committed
Rename 'flat_map' → 'flat_map_identity'
1 parent f0ce04f commit b651f19

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ Released 2018-09-13
947947
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
948948
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
949949
[`find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#find_map
950-
[`flat_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map
950+
[`flat_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_identity
951951
[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic
952952
[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
953953
[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
643643
methods::FILTER_MAP,
644644
methods::FILTER_MAP_NEXT,
645645
methods::FIND_MAP,
646-
methods::FLAT_MAP,
646+
methods::FLAT_MAP_IDENTITY,
647647
methods::MAP_FLATTEN,
648648
methods::OPTION_MAP_UNWRAP_OR,
649649
methods::OPTION_MAP_UNWRAP_OR_ELSE,

clippy_lints/src/methods/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ declare_clippy_lint! {
357357
/// ```rust
358358
/// iter.flatten()
359359
/// ```
360-
pub FLAT_MAP,
360+
pub FLAT_MAP_IDENTITY,
361361
pedantic,
362362
"call to `flat_map` where `flatten` is sufficient"
363363
}
@@ -912,7 +912,7 @@ declare_lint_pass!(Methods => [
912912
FILTER_NEXT,
913913
FILTER_MAP,
914914
FILTER_MAP_NEXT,
915-
FLAT_MAP,
915+
FLAT_MAP_IDENTITY,
916916
FIND_MAP,
917917
MAP_FLATTEN,
918918
ITER_NTH,
@@ -953,7 +953,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
953953
["map", "find"] => lint_find_map(cx, expr, arg_lists[1], arg_lists[0]),
954954
["flat_map", "filter"] => lint_filter_flat_map(cx, expr, arg_lists[1], arg_lists[0]),
955955
["flat_map", "filter_map"] => lint_filter_map_flat_map(cx, expr, arg_lists[1], arg_lists[0]),
956-
["flat_map", ..] => lint_flat_map(cx, expr, arg_lists[0]),
956+
["flat_map", ..] => lint_flat_map_identity(cx, expr, arg_lists[0]),
957957
["flatten", "map"] => lint_map_flatten(cx, expr, arg_lists[1]),
958958
["is_some", "find"] => lint_search_is_some(cx, expr, "find", arg_lists[1], arg_lists[0]),
959959
["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>(
21652165
}
21662166

21672167
/// lint use of `flat_map` for `Iterators` where `flatten` would be sufficient
2168-
fn lint_flat_map<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, flat_map_args: &'tcx [hir::Expr]) {
2168+
fn lint_flat_map_identity<'a, 'tcx>(
2169+
cx: &LateContext<'a, 'tcx>,
2170+
expr: &'tcx hir::Expr,
2171+
flat_map_args: &'tcx [hir::Expr],
2172+
) {
21692173
if_chain! {
21702174
if match_trait_method(cx, expr, &paths::ITERATOR);
21712175

@@ -2183,7 +2187,7 @@ fn lint_flat_map<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, fl
21832187
then {
21842188
let msg = "called `flat_map(|x| x)` on an `Iterator`. \
21852189
This can be simplified by calling `flatten().`";
2186-
span_lint(cx, FLAT_MAP, expr.span, msg);
2190+
span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
21872191
}
21882192
}
21892193

@@ -2201,7 +2205,7 @@ fn lint_flat_map<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, fl
22012205
then {
22022206
let msg = "called `flat_map(std::convert::identity)` on an `Iterator`. \
22032207
This can be simplified by calling `flatten().`";
2204-
span_lint(cx, FLAT_MAP, expr.span, msg);
2208+
span_lint(cx, FLAT_MAP_IDENTITY, expr.span, msg);
22052209
}
22062210
}
22072211
}

src/lintlist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ pub const ALL_LINTS: [Lint; 310] = [
554554
module: "methods",
555555
},
556556
Lint {
557-
name: "flat_map",
557+
name: "flat_map_identity",
558558
group: "pedantic",
559559
desc: "call to `flat_map` where `flatten` is sufficient",
560560
deprecation: None,

tests/ui/unnecessary_flat_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::flat_map)]
1+
#![warn(clippy::flat_map_identity)]
22

33
use std::convert;
44

tests/ui/unnecessary_flat_map.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: called `flat_map(|x| x)` on an `Iterator`. This can be simplified by call
44
LL | iterator.flat_map(|x| x);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::flat-map` implied by `-D warnings`
7+
= note: `-D clippy::flat-map-identity` implied by `-D warnings`
88

99
error: called `flat_map(std::convert::identity)` on an `Iterator`. This can be simplified by calling `flatten().`
1010
--> $DIR/unnecessary_flat_map.rs:10:23

0 commit comments

Comments
 (0)