Skip to content

Commit 5a6aaec

Browse files
committed
Passing all tests
1 parent ab4c8b4 commit 5a6aaec

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

clippy_lints/src/map_identity.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use if_chain::if_chain;
55
use rustc_errors::Applicability;
66
use rustc_lint::{LateLintPass, LateContext};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
8-
use rustc_hir::*;
8+
use rustc_hir::{Body, Expr, ExprKind, Pat, PatKind, Path, QPath, StmtKind, def};
99

1010
declare_clippy_lint! {
1111
/// **What it does:** Checks for instances of `map(f)` where `f` is the identity function.
@@ -17,15 +17,17 @@ declare_clippy_lint! {
1717
/// **Example:**
1818
///
1919
/// ```rust
20-
/// let x = [1, 2, 3].map(|x| x).
20+
/// let x = [1, 2, 3];
21+
/// let y: Vec<_> = x.iter().map(|x| x).map(|x| 2*x).collect();
2122
/// ```
2223
/// Use instead:
2324
/// ```rust
24-
/// let x =
25+
/// let x = [1, 2, 3];
26+
/// let y: Vec<_> = x.iter().map(|x| 2*x).collect();
2527
/// ```
2628
pub MAP_IDENTITY,
2729
style,
28-
"default lint description"
30+
"using iterator.map(|x| x)"
2931
}
3032

3133
declare_lint_pass!(MapIdentity => [MAP_IDENTITY]);

tests/ui/map_flatten.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![warn(clippy::all, clippy::pedantic)]
44
#![allow(clippy::missing_docs_in_private_items)]
5+
#![allow(clippy::map_identity)]
56

67
fn main() {
78
let _: Vec<_> = vec![5_i8; 6].into_iter().flat_map(|x| 0..x).collect();

tests/ui/map_flatten.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![warn(clippy::all, clippy::pedantic)]
44
#![allow(clippy::missing_docs_in_private_items)]
5+
#![allow(clippy::map_identity)]
56

67
fn main() {
78
let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();

tests/ui/map_flatten.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: called `map(..).flatten()` on an `Iterator`. This is more succinctly expressed by calling `.flat_map(..)`
2-
--> $DIR/map_flatten.rs:7:21
2+
--> $DIR/map_flatten.rs:8:21
33
|
44
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `flat_map` instead: `vec![5_i8; 6].into_iter().flat_map(|x| 0..x)`
66
|
77
= note: `-D clippy::map-flatten` implied by `-D warnings`
88

99
error: called `map(..).flatten()` on an `Option`. This is more succinctly expressed by calling `.and_then(..)`
10-
--> $DIR/map_flatten.rs:8:24
10+
--> $DIR/map_flatten.rs:9:24
1111
|
1212
LL | let _: Option<_> = (Some(Some(1))).map(|x| x).flatten();
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `(Some(Some(1))).and_then(|x| x)`

0 commit comments

Comments
 (0)