Stop bytes_nth from suggesting code that does not compile
This commit is contained in:
parent
52c8b536c9
commit
7e53e27dfd
4 changed files with 38 additions and 22 deletions
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
fn main() {
|
||||
let s = String::from("String");
|
||||
let _ = s.as_bytes().get(3);
|
||||
let _ = &s.as_bytes().get(3);
|
||||
let _ = s[..].as_bytes().get(3);
|
||||
let _ = s.as_bytes().get(3).copied();
|
||||
let _ = &s.as_bytes()[3];
|
||||
let _ = s[..].as_bytes().get(3).copied();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@
|
|||
fn main() {
|
||||
let s = String::from("String");
|
||||
let _ = s.bytes().nth(3);
|
||||
let _ = &s.bytes().nth(3);
|
||||
let _ = &s.bytes().nth(3).unwrap();
|
||||
let _ = s[..].bytes().nth(3);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@ error: called `.bytes().nth()` on a `String`
|
|||
--> $DIR/bytes_nth.rs:8:13
|
||||
|
|
||||
LL | let _ = s.bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3).copied()`
|
||||
|
|
||||
= note: `-D clippy::bytes-nth` implied by `-D warnings`
|
||||
|
||||
error: called `.bytes().nth()` on a `String`
|
||||
error: called `.bytes().nth().unwrap()` on a `String`
|
||||
--> $DIR/bytes_nth.rs:9:14
|
||||
|
|
||||
LL | let _ = &s.bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
LL | let _ = &s.bytes().nth(3).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.as_bytes()[3]`
|
||||
|
||||
error: called `.bytes().nth()` on a `str`
|
||||
--> $DIR/bytes_nth.rs:10:13
|
||||
|
|
||||
LL | let _ = s[..].bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3).copied()`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue