Skip to content

Commit ac75ec3

Browse files
committed
make the unfixable case fixable by using path_to_local_with_projections
1 parent 0ba5e60 commit ac75ec3

File tree

6 files changed

+36
-37
lines changed

6 files changed

+36
-37
lines changed

clippy_lints/src/methods/map_identity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::ty::is_type_diagnostic_item;
3-
use clippy_utils::{is_expr_untyped_identity_function, is_mutable, is_trait_method, path_to_local};
3+
use clippy_utils::{is_expr_untyped_identity_function, is_mutable, is_trait_method, path_to_local_with_projections};
44
use rustc_errors::Applicability;
55
use rustc_hir::{self as hir, ExprKind, Node, PatKind};
66
use rustc_lint::LateContext;
@@ -27,7 +27,7 @@ pub(super) fn check(
2727
let mut sugg = vec![(call_span, String::new())];
2828
let mut apply = true;
2929
if !is_mutable(cx, caller) {
30-
if let Some(hir_id) = path_to_local(caller)
30+
if let Some(hir_id) = path_to_local_with_projections(caller)
3131
&& let Node::Pat(pat) = cx.tcx.hir_node(hir_id)
3232
&& let PatKind::Binding(_, _, ident, _) = pat.kind
3333
{

tests/ui/map_identity.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ fn issue13904() {
7979
let _ = it.next();
8080
//~^ map_identity
8181

82+
// lint
83+
let mut index = [1, 2, 3].into_iter();
84+
let mut subindex = (index.by_ref().take(3), 42);
85+
let _ = subindex.0.next();
86+
//~^ map_identity
87+
8288
// lint
8389
#[allow(unused_mut)]
8490
let mut it = [1, 2, 3].into_iter();

tests/ui/map_identity.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ fn issue13904() {
8585
let _ = it.map(|x| x).next();
8686
//~^ map_identity
8787

88+
// lint
89+
let mut index = [1, 2, 3].into_iter();
90+
let subindex = (index.by_ref().take(3), 42);
91+
let _ = subindex.0.map(|n| n).next();
92+
//~^ map_identity
93+
8894
// lint
8995
#[allow(unused_mut)]
9096
let mut it = [1, 2, 3].into_iter();

tests/ui/map_identity.stderr

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,58 +88,70 @@ LL ~ let _ = it.next();
8888
|
8989

9090
error: unnecessary map of the identity function
91-
--> tests/ui/map_identity.rs:91:15
91+
--> tests/ui/map_identity.rs:91:23
92+
|
93+
LL | let _ = subindex.0.map(|n| n).next();
94+
| ^^^^^^^^^^^
95+
|
96+
help: remove the call to `map`
97+
|
98+
LL ~ let mut subindex = (index.by_ref().take(3), 42);
99+
LL ~ let _ = subindex.0.next();
100+
|
101+
102+
error: unnecessary map of the identity function
103+
--> tests/ui/map_identity.rs:97:15
92104
|
93105
LL | let _ = it.map(|x| x).next();
94106
| ^^^^^^^^^^^ help: remove the call to `map`
95107

96108
error: unnecessary map of the identity function
97-
--> tests/ui/map_identity.rs:96:19
109+
--> tests/ui/map_identity.rs:102:19
98110
|
99111
LL | let _ = { it }.map(|x| x).next();
100112
| ^^^^^^^^^^^ help: remove the call to `map`
101113

102114
error: unnecessary map of the identity function
103-
--> tests/ui/map_identity.rs:108:30
115+
--> tests/ui/map_identity.rs:114:30
104116
|
105117
LL | let _ = x.iter().copied().map(|[x, y]| [x, y]);
106118
| ^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
107119

108120
error: unnecessary map of the identity function
109-
--> tests/ui/map_identity.rs:134:26
121+
--> tests/ui/map_identity.rs:140:26
110122
|
111123
LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo, bar });
112124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
113125

114126
error: unnecessary map of the identity function
115-
--> tests/ui/map_identity.rs:138:26
127+
--> tests/ui/map_identity.rs:144:26
116128
|
117129
LL | let _ = x.into_iter().map(|Foo { foo, bar }| foo::Foo { foo, bar });
118130
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
119131

120132
error: unnecessary map of the identity function
121-
--> tests/ui/map_identity.rs:146:26
133+
--> tests/ui/map_identity.rs:152:26
122134
|
123135
LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo: foo, bar: bar });
124136
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
125137

126138
error: unnecessary map of the identity function
127-
--> tests/ui/map_identity.rs:150:26
139+
--> tests/ui/map_identity.rs:156:26
128140
|
129141
LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { bar, foo });
130142
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
131143

132144
error: unnecessary map of the identity function
133-
--> tests/ui/map_identity.rs:160:26
145+
--> tests/ui/map_identity.rs:166:26
134146
|
135147
LL | let _ = x.into_iter().map(|Foo2(foo, bar)| Foo2(foo, bar));
136148
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
137149

138150
error: unnecessary map of the identity function
139-
--> tests/ui/map_identity.rs:164:26
151+
--> tests/ui/map_identity.rs:170:26
140152
|
141153
LL | let _ = x.into_iter().map(|Foo2(foo, bar)| foo::Foo2(foo, bar));
142154
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
143155

144-
error: aborting due to 21 previous errors
156+
error: aborting due to 22 previous errors
145157

tests/ui/map_identity_unfixable.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/ui/map_identity_unfixable.stderr

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)