Skip to content

Use multipart suggestion in unnecessary_to_owned #13847

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

Conversation

nanvel
Copy link
Contributor

@nanvel nanvel commented Dec 17, 2024

It is related to #13099

What was done:

  • removed @no-rustfix from tests/ui/unnecessary_to_owned.rs
  • checked for suggestions in src/methods/unnecessary_to_owned.rs (there is already one multipart_suggestion, and I don't see any other)
  • ran cargo uibless

I am new to Rust, and this is my first PR.

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Dec 17, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 17, 2024
@scottgerring
Copy link
Contributor

Hey @nanvel ,

(not the reviewer, but I fixed all the other ones of these).

You need to fix the lint, not the test. The test is intentionally badly structured, and the lint needs to emit a single multipart correction to fix it. Essentially this error here should be collapsed into a multipart:

--> tests/ui/unnecessary_to_owned.rs:223:14
   |
LL |     for t in file_types.to_vec() {
   |              ^^^^^^^^^^^^^^^^^^^
   |
help: use
   |
LL |     for t in file_types {
   |              ~~~~~~~~~~
help: remove any references to the binding
   |
LL -         let path = match get_file_path(&t) {
LL +         let path = match get_file_path(t) {
   |

error: unnecessary use of `to_vec`
  --> tests/ui/unnecessary_to_owned.rs:246:14

The idea is, a lint that has multiple parts that need to be applied at once to be semantically correct needs to be applied as a multipart suggestion. At the moment the lint is providing multiple individual suggestions, the test framework applies them separately - which is why you get multiple output files that are each invalid.

If you look at the linked issue you can check out any of my other PRs to see what I mean!

@nanvel
Copy link
Contributor Author

nanvel commented Dec 17, 2024

@scottgerring thanks for the explanation. I rechecked the code, and it should indeed handle to_vec as well.
Will try to fix tomorrow.

@bors
Copy link
Contributor

bors commented Dec 18, 2024

☔ The latest upstream changes (presumably 9f4941a) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Dec 18, 2024
@rustbot

This comment has been minimized.

@nanvel nanvel force-pushed the issue-13099/use_multipart_suggestion_in_unnecessary_to_owned branch from 532d99b to 4424887 Compare December 18, 2024 10:09
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Dec 18, 2024
@nanvel
Copy link
Contributor Author

nanvel commented Dec 18, 2024

@scottgerring, somehow, now it works, not sure why it was generating two fixed before.

@scottgerring
Copy link
Contributor

Hey @nanvel ,

Cool! I think it is because the issue with this test happened to be the same issue in the unnecessary_iter_cloned lint, which I fixed for that test yesterday (check out around combined to see the "important bit" - what was two suggestions is now one).

Apologies - I didn't realize this was the only bit touching this test too - I would've expected unnecessary_to_owned to need a multipart change, but looking at it it seems that it's already good.

Again, not the reviewer, but TL;DR enabling the test like you've done and checking those bits in I think should be it 🙌 You might want to squash your commits together with a sensible message( I think it's always a merge into master here) and ping the reviewer !

@flip1995 flip1995 changed the title ISSUE-13099 Use multipart suggestion in unnecessary_to_owned Use multipart suggestion in unnecessary_to_owned Dec 18, 2024
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trusting @scottgerring assessment that this enough to fix the issue. You worked the most on this topic. Thanks for investigating!

Please squash your commits and this is ready to get merged. :shipit:

@nanvel nanvel force-pushed the issue-13099/use_multipart_suggestion_in_unnecessary_to_owned branch from 2a9fe62 to cbff019 Compare December 19, 2024 00:28
@nanvel nanvel force-pushed the issue-13099/use_multipart_suggestion_in_unnecessary_to_owned branch from cbff019 to 1e0b59d Compare December 19, 2024 00:29
@nanvel
Copy link
Contributor Author

nanvel commented Dec 19, 2024

@flip1995 commits were squashed.

@Manishearth Manishearth added this pull request to the merge queue Dec 19, 2024
Merged via the queue into rust-lang:master with commit a775a1b Dec 19, 2024
9 checks passed
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.

6 participants