Rescope temp lifetime in if-let into IfElse with migration lint#107251
Rescope temp lifetime in if-let into IfElse with migration lint#107251bors merged 4 commits intorust-lang:masterfrom
Conversation
|
r? @oli-obk (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
cc @est31 I have tested this branch on several of my repositories that I am working on and nothing obvious has broken. Shall we have a crater run? |
|
@bors try |
|
⌛ Trying commit 003f3cd8d3cecb9b20f5105400499741c936e92a with merge ece70b22820429ebf0c6d388c32356a14c58fc2f... |
|
☀️ Try build successful - checks-actions |
003f3cd to
dbbdd0c
Compare
|
I have updated the failing tests to show the effect of this change. |
This comment has been minimized.
This comment has been minimized.
dbbdd0c to
e2db1e6
Compare
This comment has been minimized.
This comment has been minimized.
e2db1e6 to
92550dd
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
@craterbot run mode=build-and-test |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
|
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #130165) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@rustbot ready cc @jieyouxu
|
|
cc #129466 (comment) for the top-1000 crater run. |
tests/ui/drop/lint-if-let-rescope-gated.with_feature_gate.stderr
Outdated
Show resolved
Hide resolved
|
Something I noticed is that having to handle when or when not to add parenthesis makes the logic very, very complicated. Could we just unconditionally add parentheses? Or will that cause issues with rustfix? also cc @traviscross FYI for T-lang, due to limitations of mutually overlapping suggestions we cannot make the suggestions Note that after the diagnostics here is fixed, we probably want to check the impact in a full crater run, previous crater run was for top-1000 only. |
|
@rustbot ready
|
jieyouxu
left a comment
There was a problem hiding this comment.
Thanks, this looks reasonable to me now.
|
Since this migration lint is still feature-gated, I'm okay with merging the implementation first and not block this on a crater run. @bors r+ rollup=never (this is quite complicated and tricky) |
|
💔 Test failed - checks-actions |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (a5efa01): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary -1.6%, secondary -3.2%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary -7.5%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 757.342s -> 759.189s (0.24%) |
Tracking issue #124085
This PR shortens the temporary lifetime to cover only the pattern matching and consequent branch of a
if let.At the expression location, means that the lifetime is shortened from previously the deepest enclosing block or statement in Edition 2021. This warrants an Edition change.
Coming with the Edition change, this patch also implements an edition lint to warn about the change and a safe rewrite suggestion to preserve the 2021 semantics in most cases.
The state of lint
The
rustc_lintworks as follows. It checks aifHIR expression and collect a consecutive run ofelse ifcascade as far as it can see. Whenever a significant dropper is found in the scrutinee in any one of the conditional, it emits a lint. A series and rewrite suggestion is emitted at the end of the probe so that it does not get too verbose and most importantly generates a non-self-intersecting set of spans for a valid rewrite.The reason that we are doing this suggestion-coalescing gymnastic for now is because of the current limitation of
rustfix, details of which can be found #53934. My personal view on the matter is that holistic solution is really necessary for a more elegant solution here. I believe that we will make more progress if we push through #53934.The exact reason that the same suggestion as what you get from
rustc_lintis not automatically machine applicable from the borrow checker as what you get fromrustc_lintis due to the possible intersection between spans. We apologize for the inconvenience.Related to #103108.
Related crater runs: #129466.