Skip to content

Commit 156c025

Browse files
committed
move the tests to the right file
1 parent 7a45646 commit 156c025

File tree

6 files changed

+163
-172
lines changed

6 files changed

+163
-172
lines changed

tests/ui/f1.fixed

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

tests/ui/f1.rs

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

tests/ui/f1.stderr

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

tests/ui/map_identity.fixed

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::map_identity)]
2-
#![allow(clippy::needless_return)]
2+
#![allow(clippy::needless_return, clippy::disallowed_names)]
33

44
fn main() {
55
let x: [u16; 3] = [1, 2, 3];
@@ -99,3 +99,65 @@ fn issue15198() {
9999
let _ = x.iter().copied();
100100
//~^ map_identity
101101
}
102+
103+
mod foo {
104+
#[derive(Clone, Copy)]
105+
pub struct Foo {
106+
pub foo: u8,
107+
pub bar: u8,
108+
}
109+
110+
#[derive(Clone, Copy)]
111+
pub struct Foo2(pub u8, pub u8);
112+
}
113+
use foo::{Foo, Foo2};
114+
115+
struct Bar {
116+
foo: u8,
117+
bar: u8,
118+
}
119+
120+
struct Bar2(u8, u8);
121+
122+
fn structs() {
123+
let x = [Foo { foo: 0, bar: 0 }];
124+
125+
let _ = x.into_iter();
126+
//~^ map_identity
127+
128+
// still lint when different paths are used for the same struct
129+
let _ = x.into_iter();
130+
//~^ map_identity
131+
132+
// don't lint: same fields but different structs
133+
let _ = x.into_iter().map(|Foo { foo, bar }| Bar { foo, bar });
134+
135+
// still lint with redundant field names
136+
#[allow(clippy::redundant_field_names)]
137+
let _ = x.into_iter();
138+
//~^ map_identity
139+
140+
// still lint with field order change
141+
let _ = x.into_iter();
142+
//~^ map_identity
143+
144+
// don't lint: switched field assignment
145+
let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo: bar, bar: foo });
146+
}
147+
148+
fn tuple_structs() {
149+
let x = [Foo2(0, 0)];
150+
151+
let _ = x.into_iter();
152+
//~^ map_identity
153+
154+
// still lint when different paths are used for the same struct
155+
let _ = x.into_iter();
156+
//~^ map_identity
157+
158+
// don't lint: same fields but different structs
159+
let _ = x.into_iter().map(|Foo2(foo, bar)| Bar2(foo, bar));
160+
161+
// don't lint: switched field assignment
162+
let _ = x.into_iter().map(|Foo2(foo, bar)| Foo2(bar, foo));
163+
}

tests/ui/map_identity.rs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::map_identity)]
2-
#![allow(clippy::needless_return)]
2+
#![allow(clippy::needless_return, clippy::disallowed_names)]
33

44
fn main() {
55
let x: [u16; 3] = [1, 2, 3];
@@ -105,3 +105,65 @@ fn issue15198() {
105105
let _ = x.iter().copied().map(|[x, y]| [x, y]);
106106
//~^ map_identity
107107
}
108+
109+
mod foo {
110+
#[derive(Clone, Copy)]
111+
pub struct Foo {
112+
pub foo: u8,
113+
pub bar: u8,
114+
}
115+
116+
#[derive(Clone, Copy)]
117+
pub struct Foo2(pub u8, pub u8);
118+
}
119+
use foo::{Foo, Foo2};
120+
121+
struct Bar {
122+
foo: u8,
123+
bar: u8,
124+
}
125+
126+
struct Bar2(u8, u8);
127+
128+
fn structs() {
129+
let x = [Foo { foo: 0, bar: 0 }];
130+
131+
let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo, bar });
132+
//~^ map_identity
133+
134+
// still lint when different paths are used for the same struct
135+
let _ = x.into_iter().map(|Foo { foo, bar }| foo::Foo { foo, bar });
136+
//~^ map_identity
137+
138+
// don't lint: same fields but different structs
139+
let _ = x.into_iter().map(|Foo { foo, bar }| Bar { foo, bar });
140+
141+
// still lint with redundant field names
142+
#[allow(clippy::redundant_field_names)]
143+
let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo: foo, bar: bar });
144+
//~^ map_identity
145+
146+
// still lint with field order change
147+
let _ = x.into_iter().map(|Foo { foo, bar }| Foo { bar, foo });
148+
//~^ map_identity
149+
150+
// don't lint: switched field assignment
151+
let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo: bar, bar: foo });
152+
}
153+
154+
fn tuple_structs() {
155+
let x = [Foo2(0, 0)];
156+
157+
let _ = x.into_iter().map(|Foo2(foo, bar)| Foo2(foo, bar));
158+
//~^ map_identity
159+
160+
// still lint when different paths are used for the same struct
161+
let _ = x.into_iter().map(|Foo2(foo, bar)| foo::Foo2(foo, bar));
162+
//~^ map_identity
163+
164+
// don't lint: same fields but different structs
165+
let _ = x.into_iter().map(|Foo2(foo, bar)| Bar2(foo, bar));
166+
167+
// don't lint: switched field assignment
168+
let _ = x.into_iter().map(|Foo2(foo, bar)| Foo2(bar, foo));
169+
}

tests/ui/map_identity.stderr

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,41 @@ error: unnecessary map of the identity function
9393
LL | let _ = x.iter().copied().map(|[x, y]| [x, y]);
9494
| ^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
9595

96-
error: aborting due to 14 previous errors
96+
error: unnecessary map of the identity function
97+
--> tests/ui/map_identity.rs:131:26
98+
|
99+
LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo, bar });
100+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
101+
102+
error: unnecessary map of the identity function
103+
--> tests/ui/map_identity.rs:135:26
104+
|
105+
LL | let _ = x.into_iter().map(|Foo { foo, bar }| foo::Foo { foo, bar });
106+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
107+
108+
error: unnecessary map of the identity function
109+
--> tests/ui/map_identity.rs:143:26
110+
|
111+
LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { foo: foo, bar: bar });
112+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
113+
114+
error: unnecessary map of the identity function
115+
--> tests/ui/map_identity.rs:147:26
116+
|
117+
LL | let _ = x.into_iter().map(|Foo { foo, bar }| Foo { bar, foo });
118+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
119+
120+
error: unnecessary map of the identity function
121+
--> tests/ui/map_identity.rs:157:26
122+
|
123+
LL | let _ = x.into_iter().map(|Foo2(foo, bar)| Foo2(foo, bar));
124+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
125+
126+
error: unnecessary map of the identity function
127+
--> tests/ui/map_identity.rs:161:26
128+
|
129+
LL | let _ = x.into_iter().map(|Foo2(foo, bar)| foo::Foo2(foo, bar));
130+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`
131+
132+
error: aborting due to 20 previous errors
97133

0 commit comments

Comments
 (0)