Skip to content

Commit 109ca86

Browse files
committed
cargo dev bless
1 parent e0dc883 commit 109ca86

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

tests/ui/bytes_count_to_len.fixed

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
// 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();
34+
}

tests/ui/bytes_count_to_len.stderr

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
error: using long and hard to read `.bytes().count()`
2-
--> $DIR/bytes_count_to_len.rs:7:5
2+
--> $DIR/bytes_count_to_len.rs:8:13
33
|
4-
LL | "hello".bytes().count();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | let _ = String::from("foo").bytes().count();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len` instead:: `String::from("foo").len()`
66
|
77
= note: `-D clippy::bytes-count-to-len` implied by `-D warnings`
8-
= note: `.len()` achieves same functionality
98

109
error: using long and hard to read `.bytes().count()`
11-
--> $DIR/bytes_count_to_len.rs:10:5
10+
--> $DIR/bytes_count_to_len.rs:11:13
1211
|
13-
LL | s1.bytes().count();
14-
| ^^^^^^^^^^^^^^^^^^
12+
LL | let _ = s1.bytes().count();
13+
| ^^^^^^^^^^^^^^^^^^ help: consider calling `.len` instead:: `s1.len()`
14+
15+
error: using long and hard to read `.bytes().count()`
16+
--> $DIR/bytes_count_to_len.rs:14:13
17+
|
18+
LL | let _ = "foo".bytes().count();
19+
| ^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len` instead:: `"foo".len()`
20+
21+
error: using long and hard to read `.bytes().count()`
22+
--> $DIR/bytes_count_to_len.rs:17:13
1523
|
16-
= note: `.len()` achieves same functionality
24+
LL | let _ = s2.bytes().count();
25+
| ^^^^^^^^^^^^^^^^^^ help: consider calling `.len` instead:: `s2.len()`
1726

18-
error: aborting due to 2 previous errors
27+
error: aborting due to 4 previous errors
1928

0 commit comments

Comments
 (0)