Skip to content

deduplicate super let bindings that have the scope of an if let guard's scrutinee - #165363

Open
dianne wants to merge 1 commit into
rust-lang:mainfrom
dianne:dedup-let-bindings-in-guard-scope
Open

dianne wants to merge 1 commit into
rust-lang:mainfrom
dianne:dedup-let-bindings-in-guard-scope

Conversation

@dianne

@dianne dianne commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Match guard lowering assumes all the locals in an if let guard's top-level scope are de-duplicated across instances of the guard, so that only one instance of each has to be dropped when leaving the arm body. We already do this for temporaries created by Builder::as_temp, but super let bindings can also end up there since they're scoped like temporaries; let's deduplicate them too.

Fixes #165322: we were creating a separate instance of each such super let binding for each time the guard was lowered, but only one of them was dropped in the match body.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 2, 2026
@dianne
dianne force-pushed the dedup-let-bindings-in-guard-scope branch from bd1a065 to 920b5af Compare November 2, 2026 17:18
@dianne

dianne commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

r? mir

@dianne
dianne marked this pull request as ready for review November 2, 2026 17:29
@rustbot

rustbot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in match lowering

cc @Nadrieril

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 2, 2026
@theemathas

Copy link
Copy Markdown
Contributor

Does this need a crater run? If so, a check run or a test run?

@dianne

dianne commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

@theemathas strictly speaking, it affects dynamic semantics, so yeah it should have a test run. practically, I find it unlikely that we'd actually get a test failure from it. assuming that this indeed only affects dynamic semantics1, we'd need:

  • pin!2 in an if let guard scrutinee over an or-pattern
  • there aren't any temporary scopes between the pin! and the top level of the guard's scrutinee expression, so that the scope of the pinned temporary goes to the end of the match arm
  • whether we do or don't drop the temporary must produce a change in behavior that affects test results, e.g. via OOM or expecting the destructor to modify some shared state

so if there's any planned build-and-test crater rollups, my preference would be to include this there to deduplicate some of the work triaging spurious failures

Footnotes

  1. I expect borrowck is unaffected since we currently do still emit a drop for the super let binding created for the instance of the guard corresponding to matching the first or-alternatives in the arm's pattern. as far as I know, currently, if it's possible for borrowck to reach the arm body from any choice of or-pattern alternatives, it should be possible from that one, so the instance of the binding that actually gets dropped will be live in the arm body. the only thing I've thought of so far that could make that false is guard patterns, but those aren't even in nightly yet. of course, it's possible I've made a mistake ^^ ↩

  2. we wouldn't get a testable change in behavior from format_args! since its super let bindings don't need to be dropped. they're all Copy, I think ↩

@theemathas

Copy link
Copy Markdown
Contributor

I don't think we're doing any build-and-test crater runs in the near future other than the beta crater run for 1.101.

@bors try

rust-bors Bot pushed a commit that referenced this pull request Nov 3, 2026
…try>

deduplicate `super let` bindings that have the scope of an `if let` guard's scrutinee
@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 6c535e6 (6c535e6ae23c762e1629b72937e2ba0db6f72e32)
Base parent: 1c3a650 (1c3a6506966e21845b31de0b075d2527660db132)

@theemathas

Copy link
Copy Markdown
Contributor

@craterbot run mode=build-and-test

@craterbot

This comment was marked as resolved.

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 3, 2026
@craterbot

This comment was marked as resolved.

@craterbot

This comment was marked as resolved.

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Nov 14, 2026
@dianne

This comment was marked as resolved.

@craterbot

This comment was marked as resolved.

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 14, 2026
@craterbot

This comment was marked as resolved.

@craterbot

Copy link
Copy Markdown
Collaborator

🎉 Experiment pr-165363-1 is completed!
📊 69 regressed and 85 fixed (247422 total)
📊 88597 spurious results on the retry-regressed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-165363-1/retry-regressed-list.txt ↩

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Nov 23, 2026
@dianne

dianne commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-165363-2 created and queued.
🤖 Automatically detected try build 6c535e6
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 23, 2026

This branch has not been deployed

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

Labels

S-waiting-on-crater Status: Waiting on a crater run to be completed. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pin! in an if let guard of an or-pattern arm never drops the value pinned for the second alternative, which breaks Pin's drop guarantee

5 participants