Skip to content

Create clippy lint against unexpectedly late drop for temporaries in match scrutinee expressions#94206

Merged
bors merged 2 commits into
rust-lang:masterfrom
PrestonFrom:significant_drop
May 8, 2022
Merged

Create clippy lint against unexpectedly late drop for temporaries in match scrutinee expressions#94206
bors merged 2 commits into
rust-lang:masterfrom
PrestonFrom:significant_drop

Conversation

@PrestonFrom

@PrestonFrom PrestonFrom commented Feb 21, 2022

Copy link
Copy Markdown
Contributor

A new clippy lint for issue 93883 (#93883). Relies on adding a new attribute (clippy::has_significant_drop) to MutexGuard, RwLockReadGuard, and RwLockWriteGuard, which is why this PR is for the rust-lang repo and not the clippy repo.

changelog: new lint [significant_drop_in_scrutinee]

@rust-highfive

Copy link
Copy Markdown
Contributor

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

@rust-highfive

Copy link
Copy Markdown
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 21, 2022
Comment thread library/core/src/marker.rs Outdated
@oli-obk

oli-obk commented Feb 21, 2022

Copy link
Copy Markdown
Contributor

r? @oli-obk

To other reviewers: I'm fully aware that the spans, diagnostic messages, documentation and tests are not in a state yet where the lint is ready for general usage. These will get resolved before asking to move the lint out of the nursery.

@rust-log-analyzer

This comment has been minimized.

@bors

bors commented Feb 26, 2022

Copy link
Copy Markdown
Collaborator

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

@xFrednet

Copy link
Copy Markdown
Contributor

Hey @PrestonFrom, Clippy creates its changelog from the PR description. Could you include a changelog entry to ensure that this new lint is caught when the changelog is written. You can just add the following line:

changelog: new lint [`significant_drop_in_scrutinee`] 

That would be a big help 🙃

@PrestonFrom

Copy link
Copy Markdown
Contributor Author

Yes, I will do that!

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@flip1995 flip1995 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left some review comments, mostly about the code style.

It also seems like that something has gone wrong with the submodule updates. This PR shouldn't update any submodule.

Comment thread src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@PrestonFrom

Copy link
Copy Markdown
Contributor Author

Left some review comments, mostly about the code style.

It also seems like that something has gone wrong with the submodule updates. This PR shouldn't update any submodule.

Thank you for the review comments! I am not sure what happened with the submodules, but I think I have fixed it.

I'm still adding tests, but would appreciate any feed back about the matches in has_significant_drop and has_significant_drop to make sure I'm on the right track.

@rust-log-analyzer

This comment has been minimized.

@flip1995 flip1995 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for addressing all the comments! I left an explanation on how I think the visitor implementation could look like. Getting this right without implementing and testing it is tricky though. So it might take some experimentation from you to get the visitor right. If you get stuck and think that the visitor approach doesn't work at all, please let me know and I will try to give you some more pointers / rethink if a visitor is the right approach.

Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
@PrestonFrom

Copy link
Copy Markdown
Contributor Author

@flip1995 @oli-obk Thank you for all your help so far! I think I have an MVP working with error message that suggests alternatives. I would appreciate another look from you both when you have time.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@flip1995 flip1995 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't review the tests and documentation yet.

Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/significant_drop_in_scrutinee.rs Outdated
@oli-obk oli-obk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2022
@PrestonFrom

Copy link
Copy Markdown
Contributor Author

@flip1995 Sorry for the delay -- I had a bit of trouble figuring out how to get the span/suggestion working with the match, but I think it's working. Please let me know if this approach doesn't actually work though.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@flip1995

flip1995 commented May 7, 2022

Copy link
Copy Markdown
Member

@bors r+

Thanks! Great work!

@oli-obk

oli-obk commented May 7, 2022

Copy link
Copy Markdown
Contributor

@bors r=flip1995

Not sure why the bot ignored you outright

@oli-obk

oli-obk commented May 7, 2022

Copy link
Copy Markdown
Contributor

@bors ping

@flip1995

flip1995 commented May 7, 2022

Copy link
Copy Markdown
Member

This PR doesn't appear in the bors queue for some reason 🤔

@compiler-errors

Copy link
Copy Markdown
Contributor

Lemme try clicking the "synchronize" button? 🤔

@PrestonFrom

Copy link
Copy Markdown
Contributor Author

Oh no! Sorry, I’m away from my computer until tonight. Please let me know if there’s anything I can do to help.

@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r=flip1995

@bors

bors commented May 7, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit d9e963f has been approved by flip1995

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 7, 2022
@compiler-errors

compiler-errors commented May 7, 2022

Copy link
Copy Markdown
Contributor

Yeah, closing and reopening it is a lot simpler than what I did. Sorry haha!

@bors

bors commented May 8, 2022

Copy link
Copy Markdown
Collaborator

⌛ Testing commit d9e963f with merge 4d1076c...

@bors

bors commented May 8, 2022

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: flip1995
Pushing 4d1076c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 8, 2022
@bors bors merged commit 4d1076c into rust-lang:master May 8, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 8, 2022
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (4d1076c): comparison url.

Summary:

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 😿 relevant regression found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 1 0 0 0
mean2 N/A 0.1% N/A N/A N/A
max N/A 0.1% N/A N/A N/A

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@klensy

klensy commented May 8, 2022

Copy link
Copy Markdown
Contributor

Current PR description is wrong, there is no SignificantDrop marker, yes?

@PrestonFrom

Copy link
Copy Markdown
Contributor Author

@klensy Apologies! I missed updating the PR description after the initial code reviews. I just updated it. Thank you for pointing it out!

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

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.