Skip to content

Commit e0dc883

Browse files
committed
adding test patterns
1 parent 4d678b4 commit e0dc883

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

tests/ui/bytes_count_to_len.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1+
// run-rustfix
12
#![warn(clippy::bytes_count_to_len)]
3+
use std::fs::File;
4+
use std::io::Read;
25

36
fn main() {
4-
let s1 = String::from("world");
7+
// should fix, because type is String
8+
let _ = String::from("foo").bytes().count();
59

6-
//test warning against a string literal
7-
"hello".bytes().count();
10+
let s1 = String::from("foo");
11+
let _ = s1.bytes().count();
812

9-
//test warning against a string variable
10-
s1.bytes().count();
13+
// should fix, because type is &str
14+
let _ = "foo".bytes().count();
1115

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
1320
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();
1534
}

0 commit comments

Comments
 (0)