Skip to content

Commit

Permalink
add some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
TaKO8Ki committed Feb 10, 2021
1 parent 932cc08 commit 5996ae1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
8 changes: 5 additions & 3 deletions tests/ui/bytes_nth.fixed
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// run-rustfix

#![allow(clippy::unnecessary_operation)]
#![warn(clippy::bytes_nth)]

fn main() {
let _ = "Hello".as_bytes().get(3);

let _ = String::from("Hello").as_bytes().get(3);
let s = String::from("String");
s.as_bytes().get(3);
&s.as_bytes().get(3);
s[..].as_bytes().get(3);
}
8 changes: 5 additions & 3 deletions tests/ui/bytes_nth.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// run-rustfix

#![allow(clippy::unnecessary_operation)]
#![warn(clippy::bytes_nth)]

fn main() {
let _ = "Hello".bytes().nth(3);

let _ = String::from("Hello").bytes().nth(3);
let s = String::from("String");
s.bytes().nth(3);
&s.bytes().nth(3);
s[..].bytes().nth(3);
}
22 changes: 14 additions & 8 deletions tests/ui/bytes_nth.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
error: called `.byte().nth()` on a `str`
--> $DIR/bytes_nth.rs:6:13
error: called `.byte().nth()` on a `String`
--> $DIR/bytes_nth.rs:8:5
|
LL | let _ = "Hello".bytes().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try calling `.as_bytes().get()`: `"Hello".as_bytes().get(3)`
LL | s.bytes().nth(3);
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
= note: `-D clippy::bytes-nth` implied by `-D warnings`

error: called `.byte().nth()` on a `String`
--> $DIR/bytes_nth.rs:8:13
--> $DIR/bytes_nth.rs:9:6
|
LL | &s.bytes().nth(3);
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`

error: called `.byte().nth()` on a `str`
--> $DIR/bytes_nth.rs:10:5
|
LL | let _ = String::from("Hello").bytes().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try calling `.as_bytes().get()`: `String::from("Hello").as_bytes().get(3)`
LL | s[..].bytes().nth(3);
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

0 comments on commit 5996ae1

Please sign in to comment.