add a new lint bytes_nth
This commit is contained in:
parent
c1ce78f0b2
commit
1c3033d5cf
7 changed files with 102 additions and 0 deletions
9
tests/ui/bytes_nth.fixed
Normal file
9
tests/ui/bytes_nth.fixed
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::bytes_nth)]
|
||||
|
||||
fn main() {
|
||||
let _ = "Hello".as_bytes().get(3);
|
||||
|
||||
let _ = String::from("Hello").as_bytes().get(3);
|
||||
}
|
||||
9
tests/ui/bytes_nth.rs
Normal file
9
tests/ui/bytes_nth.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::bytes_nth)]
|
||||
|
||||
fn main() {
|
||||
let _ = "Hello".bytes().nth(3);
|
||||
|
||||
let _ = String::from("Hello").bytes().nth(3);
|
||||
}
|
||||
16
tests/ui/bytes_nth.stderr
Normal file
16
tests/ui/bytes_nth.stderr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
error: called `.byte().nth()` on a `str`
|
||||
--> $DIR/bytes_nth.rs:6:13
|
||||
|
|
||||
LL | let _ = "Hello".bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try calling `.as_bytes().get()`: `"Hello".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
|
||||
|
|
||||
LL | let _ = String::from("Hello").bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try calling `.as_bytes().get()`: `String::from("Hello").as_bytes().get(3)`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue