Take over: New lint bytes count to len#8711
Conversation
|
r? @Manishearth (rust-highfive has picked a reviewer for you, use r? to override) |
| BYTES_COUNT_TO_LEN, | ||
| expr.span, | ||
| "using long and hard to read `.bytes().count()`", | ||
| "consider calling `.len` instead:", |
There was a problem hiding this comment.
"consider calling .len() instead"
(you can skip the ":" here I think, looks like it is already inserted in the warning message automatically? (see tests output)
There was a problem hiding this comment.
yes, that's right.
Thanks!
770726c to
72d24f7
Compare
|
Could you do a rebase, not merge? We follow a no merge-commit policy: https://github.com/rust-lang/rust-clippy/blob/master/doc/basics.md#pr |
Thanks, I missed the description. I will rebase this PR, and fix it. |
72d24f7 to
41c8501
Compare
|
I have corrected my PR and would like to get another review. |
giraffate
left a comment
There was a problem hiding this comment.
Can this review #8375 (comment) be addressed?
|
r? @giraffate |
I have addressed this commit about this comment, but I think we need to add a test that addresses this fix. How do I add a test about this case? |
38bcd8e to
26732f1
Compare
|
Although struct Foo<'a> {
str: &'a str,
}
impl Foo<'_> {
fn bytes(&self) -> std::str::Bytes<'_> {
self.str.bytes()
}
}
fn main() {
let f = Foo { str: "foo" };
let _ = f.bytes().count();
} |
giraffate
left a comment
There was a problem hiding this comment.
Overall looks good. Could you squash commits?
formats code with fixes single match clippy error to replace with if let swaps ident.name.as_str to ident.name == sym for count fn
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
26732f1 to
f19387d
Compare
|
I made two commits with c-rus commit and my commit. |
|
@bors r+ Thanks! |
|
📌 Commit f19387d has been approved by |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Remove `dead_code` paths The following paths are `dead_code` and can be removed: ### `clippy_utils::paths::VEC_RESIZE` * Introduced when `vec_resize_to_zero` lint added in PR #5637 * No longer used after commit 8acc4d2 ### `clippy_utils::paths::SLICE_GET` * Introduced when `get_first` lint added in PR #8882 * No longer used after commit a8d80d5 ### `clippy_utils::paths::STR_BYTES` * Introduced when `bytes_count_to_len` lint added in PR #8711 * No longer used after commit ba6a459 When the lints were moved into the `Methods` lint pass, they switched from using paths to diagnostic items. However, the paths were never removed. This occurred in PR #8957. This relates to issue #5393 changelog: none
take over #8375
close #8083
This PR adds new lint about considering replacing
.bytes().count()with.len().Thank you in advance.
r! @Manishearth
changelog: adds new lint [
bytes_count_to_len] to consider replacing.bytes().count()with.len()