-
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.
I ran Clippy on some projects after upgrading to 1.84, which found a [needless use of `as_bytes()`](#13437). It made me notice that the code was also using `bytes()` needlessly in other places. This PR improves on the `as_bytes()` lint to also lint `bytes()`. ---- changelog: none
- Loading branch information
Showing
5 changed files
with
113 additions
and
19 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
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 |
---|---|---|
@@ -1,29 +1,53 @@ | ||
error: needless call to `as_bytes()` | ||
--> tests/ui/needless_as_bytes.rs:13:8 | ||
error: needless call to `as_bytes` | ||
--> tests/ui/needless_as_bytes.rs:17:8 | ||
| | ||
LL | if "some string".as_bytes().is_empty() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `"some string".is_empty()` | ||
| | ||
= note: `-D clippy::needless-as-bytes` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::needless_as_bytes)]` | ||
|
||
error: needless call to `as_bytes()` | ||
--> tests/ui/needless_as_bytes.rs:15:30 | ||
error: needless call to `as_bytes` | ||
--> tests/ui/needless_as_bytes.rs:19:30 | ||
| | ||
LL | println!("len = {}", "some string".as_bytes().len()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `"some string".len()` | ||
|
||
error: needless call to `as_bytes()` | ||
--> tests/ui/needless_as_bytes.rs:20:8 | ||
error: needless call to `bytes` | ||
--> tests/ui/needless_as_bytes.rs:22:8 | ||
| | ||
LL | if "some string".bytes().is_empty() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `"some string".is_empty()` | ||
|
||
error: needless call to `bytes` | ||
--> tests/ui/needless_as_bytes.rs:24:30 | ||
| | ||
LL | println!("len = {}", "some string".bytes().len()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `"some string".len()` | ||
|
||
error: needless call to `as_bytes` | ||
--> tests/ui/needless_as_bytes.rs:29:8 | ||
| | ||
LL | if s.as_bytes().is_empty() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `s.is_empty()` | ||
|
||
error: needless call to `as_bytes()` | ||
--> tests/ui/needless_as_bytes.rs:22:30 | ||
error: needless call to `as_bytes` | ||
--> tests/ui/needless_as_bytes.rs:31:30 | ||
| | ||
LL | println!("len = {}", s.as_bytes().len()); | ||
| ^^^^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `s.len()` | ||
|
||
error: aborting due to 4 previous errors | ||
error: needless call to `bytes` | ||
--> tests/ui/needless_as_bytes.rs:34:8 | ||
| | ||
LL | if s.bytes().is_empty() { | ||
| ^^^^^^^^^^^^^^^^^^^^ help: `is_empty()` can be called directly on strings: `s.is_empty()` | ||
|
||
error: needless call to `bytes` | ||
--> tests/ui/needless_as_bytes.rs:36:30 | ||
| | ||
LL | println!("len = {}", s.bytes().len()); | ||
| ^^^^^^^^^^^^^^^ help: `len()` can be called directly on strings: `s.len()` | ||
|
||
error: aborting due to 8 previous errors | ||
|