Skip to content

Commit 5996ae1

Browse files
committed
add some test cases
1 parent 932cc08 commit 5996ae1

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

tests/ui/bytes_nth.fixed

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// run-rustfix
22

3+
#![allow(clippy::unnecessary_operation)]
34
#![warn(clippy::bytes_nth)]
45

56
fn main() {
6-
let _ = "Hello".as_bytes().get(3);
7-
8-
let _ = String::from("Hello").as_bytes().get(3);
7+
let s = String::from("String");
8+
s.as_bytes().get(3);
9+
&s.as_bytes().get(3);
10+
s[..].as_bytes().get(3);
911
}

tests/ui/bytes_nth.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// run-rustfix
22

3+
#![allow(clippy::unnecessary_operation)]
34
#![warn(clippy::bytes_nth)]
45

56
fn main() {
6-
let _ = "Hello".bytes().nth(3);
7-
8-
let _ = String::from("Hello").bytes().nth(3);
7+
let s = String::from("String");
8+
s.bytes().nth(3);
9+
&s.bytes().nth(3);
10+
s[..].bytes().nth(3);
911
}

tests/ui/bytes_nth.stderr

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
error: called `.byte().nth()` on a `str`
2-
--> $DIR/bytes_nth.rs:6:13
1+
error: called `.byte().nth()` on a `String`
2+
--> $DIR/bytes_nth.rs:8:5
33
|
4-
LL | let _ = "Hello".bytes().nth(3);
5-
| ^^^^^^^^^^^^^^^^^^^^^^ help: try calling `.as_bytes().get()`: `"Hello".as_bytes().get(3)`
4+
LL | s.bytes().nth(3);
5+
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
66
|
77
= note: `-D clippy::bytes-nth` implied by `-D warnings`
88

99
error: called `.byte().nth()` on a `String`
10-
--> $DIR/bytes_nth.rs:8:13
10+
--> $DIR/bytes_nth.rs:9:6
11+
|
12+
LL | &s.bytes().nth(3);
13+
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
14+
15+
error: called `.byte().nth()` on a `str`
16+
--> $DIR/bytes_nth.rs:10:5
1117
|
12-
LL | let _ = String::from("Hello").bytes().nth(3);
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try calling `.as_bytes().get()`: `String::from("Hello").as_bytes().get(3)`
18+
LL | s[..].bytes().nth(3);
19+
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`
1420

15-
error: aborting due to 2 previous errors
21+
error: aborting due to 3 previous errors
1622

0 commit comments

Comments
 (0)