-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding test patterns cargo dev bless fix comment add ; delete : fix suggestion code and update stderr in tests. use match_def_path when checking method name
- Loading branch information
Showing
5 changed files
with
109 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// run-rustfix | ||
#![warn(clippy::bytes_count_to_len)] | ||
use std::fs::File; | ||
use std::io::Read; | ||
|
||
fn main() { | ||
// should fix, because type is String | ||
let _ = String::from("foo").len(); | ||
|
||
let s1 = String::from("foo"); | ||
let _ = s1.len(); | ||
|
||
// should fix, because type is &str | ||
let _ = "foo".len(); | ||
|
||
let s2 = "foo"; | ||
let _ = s2.len(); | ||
|
||
// make sure using count() normally doesn't trigger warning | ||
let vector = [0, 1, 2]; | ||
let _ = vector.iter().count(); | ||
|
||
// The type is slice, so should not fix | ||
let _ = &[1, 2, 3].bytes().count(); | ||
|
||
let bytes: &[u8] = &[1, 2, 3]; | ||
bytes.bytes().count(); | ||
|
||
// The type is File, so should not fix | ||
let _ = File::open("foobar").unwrap().bytes().count(); | ||
|
||
let f = File::open("foobar").unwrap(); | ||
let _ = f.bytes().count(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
// run-rustfix | ||
#![warn(clippy::bytes_count_to_len)] | ||
use std::fs::File; | ||
use std::io::Read; | ||
|
||
fn main() { | ||
let s1 = String::from("world"); | ||
// should fix, because type is String | ||
let _ = String::from("foo").bytes().count(); | ||
|
||
//test warning against a string literal | ||
"hello".bytes().count(); | ||
let s1 = String::from("foo"); | ||
let _ = s1.bytes().count(); | ||
|
||
//test warning against a string variable | ||
s1.bytes().count(); | ||
// should fix, because type is &str | ||
let _ = "foo".bytes().count(); | ||
|
||
//make sure using count() normally doesn't trigger warning | ||
let s2 = "foo"; | ||
let _ = s2.bytes().count(); | ||
|
||
// make sure using count() normally doesn't trigger warning | ||
let vector = [0, 1, 2]; | ||
let size = vector.iter().count(); | ||
let _ = vector.iter().count(); | ||
|
||
// The type is slice, so should not fix | ||
let _ = &[1, 2, 3].bytes().count(); | ||
|
||
let bytes: &[u8] = &[1, 2, 3]; | ||
bytes.bytes().count(); | ||
|
||
// The type is File, so should not fix | ||
let _ = File::open("foobar").unwrap().bytes().count(); | ||
|
||
let f = File::open("foobar").unwrap(); | ||
let _ = f.bytes().count(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
error: using long and hard to read `.bytes().count()` | ||
--> $DIR/bytes_count_to_len.rs:7:5 | ||
--> $DIR/bytes_count_to_len.rs:8:13 | ||
| | ||
LL | "hello".bytes().count(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | let _ = String::from("foo").bytes().count(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `String::from("foo").len()` | ||
| | ||
= note: `-D clippy::bytes-count-to-len` implied by `-D warnings` | ||
= note: `.len()` achieves same functionality | ||
|
||
error: using long and hard to read `.bytes().count()` | ||
--> $DIR/bytes_count_to_len.rs:10:5 | ||
--> $DIR/bytes_count_to_len.rs:11:13 | ||
| | ||
LL | s1.bytes().count(); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
LL | let _ = s1.bytes().count(); | ||
| ^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `s1.len()` | ||
|
||
error: using long and hard to read `.bytes().count()` | ||
--> $DIR/bytes_count_to_len.rs:14:13 | ||
| | ||
LL | let _ = "foo".bytes().count(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `"foo".len()` | ||
|
||
error: using long and hard to read `.bytes().count()` | ||
--> $DIR/bytes_count_to_len.rs:17:13 | ||
| | ||
= note: `.len()` achieves same functionality | ||
LL | let _ = s2.bytes().count(); | ||
| ^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `s2.len()` | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 4 previous errors | ||
|