]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/bytes_count_to_len.fixed
Rollup merge of #96733 - SparrowLii:place_to_string, r=davidtwco
[rust.git] / src / tools / clippy / tests / ui / bytes_count_to_len.fixed
1 // run-rustfix
2 #![warn(clippy::bytes_count_to_len)]
3 use std::fs::File;
4 use std::io::Read;
5
6 fn main() {
7     // should fix, because type is String
8     let _ = String::from("foo").len();
9
10     let s1 = String::from("foo");
11     let _ = s1.len();
12
13     // should fix, because type is &str
14     let _ = "foo".len();
15
16     let s2 = "foo";
17     let _ = s2.len();
18
19     // make sure using count() normally doesn't trigger warning
20     let vector = [0, 1, 2];
21     let _ = vector.iter().count();
22
23     // The type is slice, so should not fix
24     let _ = &[1, 2, 3].bytes().count();
25
26     let bytes: &[u8] = &[1, 2, 3];
27     bytes.bytes().count();
28
29     // The type is File, so should not fix
30     let _ = File::open("foobar").unwrap().bytes().count();
31
32     let f = File::open("foobar").unwrap();
33     let _ = f.bytes().count();
34 }