Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .as_ref() to suggestion to remove .to_string() #12091

Merged
merged 1 commit into from Jan 5, 2024

Conversation

samueltardieu
Copy link
Contributor

The case of .to_owned().split(…) is treated specially in the unnecessary_to_owned lint. Test cases check that it works both for slices and for strings, but they missed a corner case: x.to_string().split(…) when x implements AsRef<str> but not Deref<Target = str>. In this case, it is wrong to suggest to remove .to_string() without adding .as_ref() instead.

Fix #12068

changelog: [unnecessary_to_owned]: suggest replacing .to_string() by .as_ref()

@rustbot
Copy link
Collaborator

rustbot commented Jan 4, 2024

r? @Alexendoo

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 4, 2024
@Alexendoo
Copy link
Member

Thank you!

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 5, 2024

📌 Commit e758413 has been approved by Alexendoo

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jan 5, 2024

⌛ Testing commit e758413 with merge 2d6c238...

@bors
Copy link
Collaborator

bors commented Jan 5, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Alexendoo
Pushing 2d6c238 to master...

@bors bors merged commit 2d6c238 into rust-lang:master Jan 5, 2024
5 checks passed
@samueltardieu samueltardieu deleted the issue-12068 branch January 7, 2024 10:12
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.

Latest nightly issue
4 participants