|
| 1 | +// run-rustfix |
1 | 2 | #![warn(clippy::bytes_count_to_len)]
|
| 3 | +use std::fs::File; |
| 4 | +use std::io::Read; |
2 | 5 |
|
3 | 6 | fn main() {
|
4 |
| - let s1 = String::from("world"); |
| 7 | + // should fix, because type is String |
| 8 | + let _ = String::from("foo").bytes().count(); |
5 | 9 |
|
6 |
| - //test warning against a string literal |
7 |
| - "hello".bytes().count(); |
| 10 | + let s1 = String::from("foo"); |
| 11 | + let _ = s1.bytes().count(); |
8 | 12 |
|
9 |
| - //test warning against a string variable |
10 |
| - s1.bytes().count(); |
| 13 | + // should fix, because type is &str |
| 14 | + let _ = "foo".bytes().count(); |
11 | 15 |
|
12 |
| - //make sure using count() normally doesn't trigger warning |
| 16 | + let s2 = "foo"; |
| 17 | + let _ = s2.bytes().count(); |
| 18 | + |
| 19 | + // make sure using count() normally doesn't trigger warning |
13 | 20 | let vector = [0, 1, 2];
|
14 |
| - let size = vector.iter().count(); |
| 21 | + let _ = vector.iter().count(); |
| 22 | + |
| 23 | + // should not fix, because type is slice. |
| 24 | + let _ = &[1, 2, 3].bytes().count(); |
| 25 | + |
| 26 | + let bytes: &[u8] = &[1, 2, 3]; |
| 27 | + bytes.bytes().count(); |
| 28 | + |
| 29 | + // should not fix, because type is File. |
| 30 | + let _ = File::open("foobar").unwrap().bytes().count(); |
| 31 | + |
| 32 | + let f = File::open("foobar").unwrap(); |
| 33 | + let _ = f.bytes().count(); |
15 | 34 | }
|
0 commit comments