File tree Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Original file line number Diff line number Diff line change 11// run-rustfix
22
3+ #![allow(clippy::unnecessary_operation)]
34#![warn(clippy::bytes_nth)]
45
56fn 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}
Original file line number Diff line number Diff line change 11// run-rustfix
22
3+ #![ allow( clippy:: unnecessary_operation) ]
34#![ warn( clippy:: bytes_nth) ]
45
56fn 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}
Original file line number Diff line number Diff line change 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
99error: 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
You can’t perform that action at this time.
0 commit comments