rust-clippy/clippy_utils/src
bors 885f97e2ce 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()`
2024-07-05 02:04:06 +00:00
..
ast_utils Merge commit '928e72dd10749875cbd412f74bfbfd7765dbcd8a' into clippyup 2021-02-25 11:25:22 +01:00
mir Auto merge of #12756 - y21:assigning_clones_lifetimes, r=Alexendoo 2024-06-15 18:25:42 +00:00
ty/type_certainty Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
ast_utils.rs Merge remote-tracking branch 'upstream/master' into rustup 2024-06-27 18:49:59 +02:00
attrs.rs Merge commit '9725c4a162502a02c1c67fdca6b797fe09b2b73c' into clippy-subtree-update 2024-04-04 19:52:55 +02:00
check_proc_macro.rs Add more types to is_from_proc_macro 2024-06-16 20:15:09 -04:00
comparisons.rs Merge commit 'd9c24d1b1ee61f276e550b967409c9f155eac4e3' into clippyup 2023-07-17 10:22:32 +02:00
consts.rs Merge remote-tracking branch 'upstream/master' into rustup 2024-06-27 18:49:59 +02:00
diagnostics.rs Remove LintDiagnostic::msg 2024-05-23 04:08:35 +02:00
eager_or_lazy.rs Merge commit '26ac6aab023393c94edf42f38f6ad31196009643' 2024-01-11 17:27:03 +01:00
higher.rs Use symbols when raising range expressions. 2024-06-16 20:24:43 -04:00
hir_utils.rs Add new Span utils to avoid both allocating and 2024-06-21 03:23:06 -04:00
lib.rs Auto merge of #12976 - tesuji:fix-explicit_auto_deref, r=xFrednet 2024-07-03 18:24:23 +00:00
macros.rs Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
numeric_literal.rs Merge commit '37f4c1725d3fd7e9c3ffd8783246bc5589debc53' into clippyup 2023-07-02 14:59:02 +02:00
paths.rs Auto merge of #11656 - y21:unnecessary_string_from_utf8, r=Jarcho 2024-07-05 02:04:06 +00:00
ptr.rs Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
qualify_min_const_fn.rs Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
source.rs Add new Span utils to avoid both allocating and 2024-06-21 03:23:06 -04:00
str_utils.rs Merge commit '09ac14c901abc43bd0d617ae4a44e8a4fed98d9c' into clippyup 2023-11-02 17:35:56 +01:00
sugg.rs Merge commit '2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2' into clippy-subtree-update 2024-05-21 10:39:30 -07:00
sym_helper.rs Merge commit '928e72dd10749875cbd412f74bfbfd7765dbcd8a' into clippyup 2021-02-25 11:25:22 +01:00
ty.rs Fix formatting 2024-07-01 19:10:10 -07:00
usage.rs Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
visitors.rs Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00