diff options
| author | bors <bors@rust-lang.org> | 2024-07-05 02:04:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-05 02:04:06 +0000 |
| commit | 885f97e2cefd1a246f47c6944afef5ffa6958426 (patch) | |
| tree | 9f77d1669f02a31af86c830f94eeb48bb9cc7eec /compiler/rustc_codegen_gcc | |
| parent | 0aac16e5b2b69e42347c9b783e87377b3a2d9608 (diff) | |
| parent | ed9ccf66e9b61406176d57499e91c3bf773e95da (diff) | |
| download | rust-885f97e2cefd1a246f47c6944afef5ffa6958426.tar.gz rust-885f97e2cefd1a246f47c6944afef5ffa6958426.zip | |
Auto merge of #11656 - y21:unnecessary_string_from_utf8, r=Jarcho
[`unnecessary_to_owned`]: catch `to_owned` on byte slice to create temporary `&str` Closes #11648 Detects the pattern `&String::from_utf8(bytes.to_vec()).unwrap()` and suggests `core::str::from_utf8(bytes).unwrap()`, which avoids the unnecessary intermediate allocation. I decided to put this in the existing `unnecessary_to_owned` lint (rather than creating a new lint) for a few reasons: - we get to use some of its logic (for example, recognizing any of the functions in the `to_owned` family, e.g. `to_vec`) - the actual inefficient operation that can be avoided here is the call to `.to_vec()`, so this is in a way similar to the other cases caught by `unnecessary_to_owned`, just through a bunch of type conversions - we can make this more "generic" later and catch other cases, so imo it's best not to tie this lint specifically to the `String` type changelog: [`unnecessary_to_owned`]: catch `&String::from_utf8(bytes.to_vec()).unwrap()` and suggest `core::str::from_utf8(bytes).unwrap()`
Diffstat (limited to 'compiler/rustc_codegen_gcc')
0 files changed, 0 insertions, 0 deletions
