-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Further enhance needless_borrow
, mildly refactor redundant_clone
#9386
Further enhance needless_borrow
, mildly refactor redundant_clone
#9386
Conversation
Just did a quick check. Does the extension to |
I just add a closure-related test. Please let me know if it doesn't address your specific concern. |
The use of As this suggestion changes the drop order it would be better to limit this to types without a significant drop function. You can use |
This has revealed a bug. Please give me a day or so to look into it. |
Any idea what I might have done to cause this? https://github.com/rust-lang/rust-clippy/runs/8089040744?check_suite_focus=true#step:7:1473 |
You can try rebasing and see if that helps. Is it working locally? |
I think I figured it out. Sorry for the noise. Today's changes move the The bug I mentioned is resolved, and the PR should be ready for review (again). |
☔ The latest upstream changes (presumably #9400) made this pull request unmergeable. Please resolve the merge conflicts. |
Okay to rebase? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things here:
- This can calculate possible borrowers multiple times per function. It also fully recalculates the liveness bitset each time as well. What's the perf impact from this?
- Some suggestions from this are arguably downgrades (see later comment for example).
Given the second point it might be better to only lint on temporaries.
This strategy feels a little extreme to me. For example, it would seem to eliminate a large number of valid suggestions from 29a7057. To address the first bullet, we could compute the possible borrowers once (lazily) in a To address the second bullet, may I suggest the following alternative? For each body, build a map from def ids to substitutions used in calls to that def id. (This could also be done lazily.) Then, suggest to remove a Whichever way we go, can we make the current, unhindered strategy something that could be optionally enabled? |
Most of the changes are on temporaries (52/74) by a quick count. Could limit locals to those which are used only once, which would lint almost all cases. The main point is to avoid changing something like: let x = ...;
use_x(&x);
...
use_x_again(&x);
That would unconditionally add another traversal over every function. which would probably be worse on average. Ideally we could store this in the lint pass, but that's not possible. |
I thought what I was proposing would conditionally add another traversal (i.e., if all of the conditions were met so that the possible borrowers were needed to proceed). Why would it be unconditional?
That sounds reasonable to me. Okay to turn this off with an option, though? |
You suggested to switching the lint to use |
OK. I see what you are saying. Then what if we essentially queued the arguments to Admittedly, one thing I am not clear on is whether returning an rust-clippy/clippy_lints/src/dereference.rs Lines 364 to 365 in 5860abf
|
I think you can make that work by storing the expression's I'll check to see if we can change rustc to allow storing Posted on zulip: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Allowing.20non.20.60'static.60.20lint.20passes/near/297154930 |
Thanks! Did you already start those changes? If not, I could make them. Please just let me know. |
Implemented in rust-lang/rust#101501. Hopefully that will be synced to clippy this week. |
Thanks, @Jarcho! |
That is correct. Two weeks till the next sync. |
5860abf
to
dc4acf6
Compare
I think this is ready for review again, @Jarcho. (Rebasing was a bit of bear, so hopefully I did not screw it up.) |
☔ The latest upstream changes (presumably #9510) made this pull request unmergeable. Please resolve the merge conflicts. |
5ad9b72
to
252f598
Compare
I think the three most recent comments have been addressed. |
☔ The latest upstream changes (presumably #9547) made this pull request unmergeable. Please resolve the merge conflicts. |
I think the only thing remaining is the previous point about changing |
Meaning don't suggest that, right? It's possible there's a problem, but I think I addressed that, actually, e.g.:
|
So it is. I was going by the change in You can rebase and squash. |
It should have occurred to me to fix that. I will fix that and any other similar changes before rebasing. |
252f598
to
9cc8da2
Compare
The most recent push squashes all of the commits except for the "Fix adjacent code" ones. The current "Fix adjacent code" commit is the result of rerunning the lint. Sadly, the introduction of I think there may be ways |
Everything looks good. If you can catch more single use cases that would be great. Thank you. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Thank you as well! Especially for rust-lang/rust#101501. 🙏 Cheers. |
Fix bug introduced by #9386 #9386 introduced a potential out-of-bounds array access. Specifically, a location returned by `local_assignments` could have [`location.statement_index` equal to `mir.basic_blocks[location.block].statements.len()`](https://github.com/rust-lang/rust-clippy/blob/b8a9a507bf9e3149d287841454842116c72d66c4/clippy_utils/src/mir/mod.rs#L129), in which case the location would refer to the block terminator: https://github.com/rust-lang/rust-clippy/blob/b8a9a507bf9e3149d287841454842116c72d66c4/clippy_lints/src/dereference.rs#L1204-L1206 I suspect the bug is not triggerable now, because of checks leading up to where it occurs. But a future code change could make it triggerable. Hence, it should be fixed. r? `@Jarcho` changelog: none
This PR does the following:
redundant_clone
into a newclippy_utils
module calledmir
, and wraps that code in a function calleddropped_without_further_use
.needless_borrow
to consider trait implementations #9136 by also suggesting to remove borrows from values dropped without further use. The changes involve the just mentioned function.redundant_clone
into modules.Strictly speaking, the last bullet is independent of the others.
redundant_clone
is somewhat hairy, IMO. Separating it into modules makes it slightly less so, by helping to delineate what depends upon what.I've tried to break everything up into digestible commits.
r? @Jarcho
(@Jarcho I hope you don't mind.)
changelog: continuation of #9136