Skip to content

Commit 238c5f9

Browse files
Add ui tests for UNNECESSARY_TO_OWNED on split
1 parent 71ea36b commit 238c5f9

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[allow(clippy::single_char_pattern)]
2+
3+
fn main() {
4+
let _ = "a".split('a').next().unwrap();
5+
//~^ ERROR: unnecessary use of `to_string`
6+
let _ = "a".split("a").next().unwrap();
7+
//~^ ERROR: unnecessary use of `to_string`
8+
let _ = "a".split('a').next().unwrap();
9+
//~^ ERROR: unnecessary use of `to_owned`
10+
let _ = "a".split("a").next().unwrap();
11+
//~^ ERROR: unnecessary use of `to_owned`
12+
13+
let _ = [1].split(|x| *x == 2).next().unwrap();
14+
//~^ ERROR: unnecessary use of `to_vec`
15+
let _ = [1].split(|x| *x == 2).next().unwrap();
16+
//~^ ERROR: unnecessary use of `to_vec`
17+
let _ = [1].split(|x| *x == 2).next().unwrap();
18+
//~^ ERROR: unnecessary use of `to_owned`
19+
let _ = [1].split(|x| *x == 2).next().unwrap();
20+
//~^ ERROR: unnecessary use of `to_owned`
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[allow(clippy::single_char_pattern)]
2+
3+
fn main() {
4+
let _ = "a".to_string().split('a').next().unwrap();
5+
//~^ ERROR: unnecessary use of `to_string`
6+
let _ = "a".to_string().split("a").next().unwrap();
7+
//~^ ERROR: unnecessary use of `to_string`
8+
let _ = "a".to_owned().split('a').next().unwrap();
9+
//~^ ERROR: unnecessary use of `to_owned`
10+
let _ = "a".to_owned().split("a").next().unwrap();
11+
//~^ ERROR: unnecessary use of `to_owned`
12+
13+
let _ = [1].to_vec().split(|x| *x == 2).next().unwrap();
14+
//~^ ERROR: unnecessary use of `to_vec`
15+
let _ = [1].to_vec().split(|x| *x == 2).next().unwrap();
16+
//~^ ERROR: unnecessary use of `to_vec`
17+
let _ = [1].to_owned().split(|x| *x == 2).next().unwrap();
18+
//~^ ERROR: unnecessary use of `to_owned`
19+
let _ = [1].to_owned().split(|x| *x == 2).next().unwrap();
20+
//~^ ERROR: unnecessary use of `to_owned`
21+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
error: unnecessary use of `to_string`
2+
--> $DIR/unnecessary_to_owned_on_split.rs:4:13
3+
|
4+
LL | let _ = "a".to_string().split('a').next().unwrap();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split('a')`
6+
|
7+
= note: `-D clippy::unnecessary-to-owned` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]`
9+
10+
error: unnecessary use of `to_string`
11+
--> $DIR/unnecessary_to_owned_on_split.rs:6:13
12+
|
13+
LL | let _ = "a".to_string().split("a").next().unwrap();
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split("a")`
15+
16+
error: unnecessary use of `to_owned`
17+
--> $DIR/unnecessary_to_owned_on_split.rs:8:13
18+
|
19+
LL | let _ = "a".to_owned().split('a').next().unwrap();
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split('a')`
21+
22+
error: unnecessary use of `to_owned`
23+
--> $DIR/unnecessary_to_owned_on_split.rs:10:13
24+
|
25+
LL | let _ = "a".to_owned().split("a").next().unwrap();
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split("a")`
27+
28+
error: unnecessary use of `to_vec`
29+
--> $DIR/unnecessary_to_owned_on_split.rs:13:13
30+
|
31+
LL | let _ = [1].to_vec().split(|x| *x == 2).next().unwrap();
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)`
33+
34+
error: unnecessary use of `to_vec`
35+
--> $DIR/unnecessary_to_owned_on_split.rs:15:13
36+
|
37+
LL | let _ = [1].to_vec().split(|x| *x == 2).next().unwrap();
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)`
39+
40+
error: unnecessary use of `to_owned`
41+
--> $DIR/unnecessary_to_owned_on_split.rs:17:13
42+
|
43+
LL | let _ = [1].to_owned().split(|x| *x == 2).next().unwrap();
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)`
45+
46+
error: unnecessary use of `to_owned`
47+
--> $DIR/unnecessary_to_owned_on_split.rs:19:13
48+
|
49+
LL | let _ = [1].to_owned().split(|x| *x == 2).next().unwrap();
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)`
51+
52+
error: aborting due to 8 previous errors
53+

0 commit comments

Comments
 (0)