Skip to content

Commit d3c4522

Browse files
committed
Add run-rustfix to starts_ends_with
1 parent 2d11a44 commit d3c4522

File tree

3 files changed

+60
-13
lines changed

3 files changed

+60
-13
lines changed

tests/ui/starts_ends_with.fixed

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// run-rustfix
2+
#![allow(dead_code, unused_must_use)]
3+
4+
fn main() {}
5+
6+
#[allow(clippy::unnecessary_operation)]
7+
fn starts_with() {
8+
"".starts_with(' ');
9+
!"".starts_with(' ');
10+
}
11+
12+
fn chars_cmp_with_unwrap() {
13+
let s = String::from("foo");
14+
if s.starts_with('f') {
15+
// s.starts_with('f')
16+
// Nothing here
17+
}
18+
if s.ends_with('o') {
19+
// s.ends_with('o')
20+
// Nothing here
21+
}
22+
if s.ends_with('o') {
23+
// s.ends_with('o')
24+
// Nothing here
25+
}
26+
if !s.starts_with('f') {
27+
// !s.starts_with('f')
28+
// Nothing here
29+
}
30+
if !s.ends_with('o') {
31+
// !s.ends_with('o')
32+
// Nothing here
33+
}
34+
if !s.ends_with('o') {
35+
// !s.ends_with('o')
36+
// Nothing here
37+
}
38+
}
39+
40+
#[allow(clippy::unnecessary_operation)]
41+
fn ends_with() {
42+
"".ends_with(' ');
43+
!"".ends_with(' ');
44+
"".ends_with(' ');
45+
!"".ends_with(' ');
46+
}

tests/ui/starts_ends_with.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![allow(dead_code)]
1+
// run-rustfix
2+
#![allow(dead_code, unused_must_use)]
23

34
fn main() {}
45

tests/ui/starts_ends_with.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
11
error: you should use the `starts_with` method
2-
--> $DIR/starts_ends_with.rs:7:5
2+
--> $DIR/starts_ends_with.rs:8:5
33
|
44
LL | "".chars().next() == Some(' ');
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with(' ')`
66
|
77
= note: `-D clippy::chars-next-cmp` implied by `-D warnings`
88

99
error: you should use the `starts_with` method
10-
--> $DIR/starts_ends_with.rs:8:5
10+
--> $DIR/starts_ends_with.rs:9:5
1111
|
1212
LL | Some(' ') != "".chars().next();
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with(' ')`
1414

1515
error: you should use the `starts_with` method
16-
--> $DIR/starts_ends_with.rs:13:8
16+
--> $DIR/starts_ends_with.rs:14:8
1717
|
1818
LL | if s.chars().next().unwrap() == 'f' {
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.starts_with('f')`
2020

2121
error: you should use the `ends_with` method
22-
--> $DIR/starts_ends_with.rs:17:8
22+
--> $DIR/starts_ends_with.rs:18:8
2323
|
2424
LL | if s.chars().next_back().unwrap() == 'o' {
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')`
2626
|
2727
= note: `-D clippy::chars-last-cmp` implied by `-D warnings`
2828

2929
error: you should use the `ends_with` method
30-
--> $DIR/starts_ends_with.rs:21:8
30+
--> $DIR/starts_ends_with.rs:22:8
3131
|
3232
LL | if s.chars().last().unwrap() == 'o' {
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')`
3434

3535
error: you should use the `starts_with` method
36-
--> $DIR/starts_ends_with.rs:25:8
36+
--> $DIR/starts_ends_with.rs:26:8
3737
|
3838
LL | if s.chars().next().unwrap() != 'f' {
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.starts_with('f')`
4040

4141
error: you should use the `ends_with` method
42-
--> $DIR/starts_ends_with.rs:29:8
42+
--> $DIR/starts_ends_with.rs:30:8
4343
|
4444
LL | if s.chars().next_back().unwrap() != 'o' {
4545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')`
4646

4747
error: you should use the `ends_with` method
48-
--> $DIR/starts_ends_with.rs:33:8
48+
--> $DIR/starts_ends_with.rs:34:8
4949
|
5050
LL | if s.chars().last().unwrap() != 'o' {
5151
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')`
5252

5353
error: you should use the `ends_with` method
54-
--> $DIR/starts_ends_with.rs:41:5
54+
--> $DIR/starts_ends_with.rs:42:5
5555
|
5656
LL | "".chars().last() == Some(' ');
5757
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')`
5858

5959
error: you should use the `ends_with` method
60-
--> $DIR/starts_ends_with.rs:42:5
60+
--> $DIR/starts_ends_with.rs:43:5
6161
|
6262
LL | Some(' ') != "".chars().last();
6363
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')`
6464

6565
error: you should use the `ends_with` method
66-
--> $DIR/starts_ends_with.rs:43:5
66+
--> $DIR/starts_ends_with.rs:44:5
6767
|
6868
LL | "".chars().next_back() == Some(' ');
6969
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')`
7070

7171
error: you should use the `ends_with` method
72-
--> $DIR/starts_ends_with.rs:44:5
72+
--> $DIR/starts_ends_with.rs:45:5
7373
|
7474
LL | Some(' ') != "".chars().next_back();
7575
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')`

0 commit comments

Comments
 (0)