Skip to content

Commit 9bd7868

Browse files
committed
different paths to the same struct
1 parent 345a5ac commit 9bd7868

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

tests/ui/f1.fixed

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#![allow(clippy::disallowed_names)]
22
#![warn(clippy::map_identity)]
33

4-
#[derive(Clone, Copy)]
5-
struct Foo {
6-
foo: u8,
7-
bar: u8,
4+
mod foo {
5+
#[derive(Clone, Copy)]
6+
pub struct Foo {
7+
pub foo: u8,
8+
pub bar: u8,
9+
}
810
}
11+
use foo::Foo;
912

1013
struct Bar {
1114
foo: u8,
@@ -18,6 +21,10 @@ fn main() {
1821
let _ = x.into_iter();
1922
//~^ map_identity
2023

24+
// still lint when different paths are used for the same struct
25+
let _ = x.into_iter();
26+
//~^ map_identity
27+
2128
// don't lint: same fields but different structs
2229
let _ = x.into_iter().map(|Foo { foo, bar }| Bar { foo, bar });
2330

tests/ui/f1.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#![allow(clippy::disallowed_names)]
22
#![warn(clippy::map_identity)]
33

4-
#[derive(Clone, Copy)]
5-
struct Foo {
6-
foo: u8,
7-
bar: u8,
4+
mod foo {
5+
#[derive(Clone, Copy)]
6+
pub struct Foo {
7+
pub foo: u8,
8+
pub bar: u8,
9+
}
810
}
11+
use foo::Foo;
912

1013
struct Bar {
1114
foo: u8,
@@ -18,6 +21,10 @@ fn main() {
1821
let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo, bar });
1922
//~^ map_identity
2023

24+
// still lint when different paths are used for the same struct
25+
let _ = x.into_iter().map(|Foo { foo, bar }| foo::Foo { foo, bar });
26+
//~^ map_identity
27+
2128
// don't lint: same fields but different structs
2229
let _ = x.into_iter().map(|Foo { foo, bar }| Bar { foo, bar });
2330

tests/ui/f1.stderr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unnecessary map of the identity function
2-
--> tests/ui/f1.rs:18:26
2+
--> tests/ui/f1.rs:21:26
33
|
44
LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo, bar });
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
@@ -8,16 +8,22 @@ LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo, bar });
88
= help: to override `-D warnings` add `#[allow(clippy::map_identity)]`
99

1010
error: unnecessary map of the identity function
11-
--> tests/ui/f1.rs:26:26
11+
--> tests/ui/f1.rs:25:26
12+
|
13+
LL | let _ = x.into_iter().map(|Foo { foo, bar }| foo::Foo { foo, bar });
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
15+
16+
error: unnecessary map of the identity function
17+
--> tests/ui/f1.rs:33:26
1218
|
1319
LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo: foo, bar: bar });
1420
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
1521

1622
error: unnecessary map of the identity function
17-
--> tests/ui/f1.rs:30:26
23+
--> tests/ui/f1.rs:37:26
1824
|
1925
LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { bar, foo });
2026
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
2127

22-
error: aborting due to 3 previous errors
28+
error: aborting due to 4 previous errors
2329

0 commit comments

Comments
 (0)