Skip to content

Lint adjacent borrowed-slice temps in unnecessary_to_owned#16799

Open
1mpossible-code wants to merge 1 commit intorust-lang:masterfrom
1mpossible-code:master
Open

Lint adjacent borrowed-slice temps in unnecessary_to_owned#16799
1mpossible-code wants to merge 1 commit intorust-lang:masterfrom
1mpossible-code:master

Conversation

@1mpossible-code
Copy link
Copy Markdown

@1mpossible-code 1mpossible-code commented Apr 3, 2026

Closes #16779

  • lint cases where to_vec() / to_owned() is saved into an immutable local and then right away borrowed again as a slice in the next statement or tail expression
  • keep the new logic pretty narrow by only looking at single use adjacent locals with simple borrowed receivers and skipping mutable bindings and loop or multi-call closure cases
  • add UI tests for the reported pattern, the tail-expression form, and negative cases like non-adjacent use, mutation, multiple uses, loops, closures, and earlier false-positive variants

Open to feedback or adjustments if this should be more/less strict

changelog: [unnecessary_to_owned]: lint adjacent local slice reborrows from to_vec() / to_owned()

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 3, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 3, 2026

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doesn't trigger for slice.to_owned/to_vec calls which then passed as a slice

3 participants