mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 14:38:46 +00:00
add some test cases
This commit is contained in:
parent
932cc085e6
commit
5996ae1cfc
3 changed files with 24 additions and 14 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 | 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: called `.byte().nth()` on a `str`
|
||||
--> $DIR/bytes_nth.rs:10:5
|
||||
|
|
||||
LL | s[..].bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue