Skip to content

Allow partially moved values in match#103208

Merged
bors merged 6 commits intorust-lang:masterfrom
cjgillot:match-fake-read
Oct 27, 2023
Merged

Allow partially moved values in match#103208
bors merged 6 commits intorust-lang:masterfrom
cjgillot:match-fake-read

Conversation

@cjgillot
Copy link
Copy Markdown
Contributor

@cjgillot cjgillot commented Oct 18, 2022

This PR attempts to unify the behaviour between let _ = PLACE, let _: TY = PLACE; and match PLACE { _ => {} }.
The logical conclusion is that the match version should not check for uninitialised places nor check that borrows are still live.

The match PLACE {} case is handled by keeping a FakeRead in the unreachable fallback case to verify that PLACE has a legal value.

Schematically, match PLACE { arms } in surface rust becomes in MIR:

PlaceMention(PLACE)
match PLACE {
  // Decision tree for the explicit arms
  arms,
  // An extra fallback arm
  _ => {
    FakeRead(ForMatchedPlace, PLACE);
    unreachable
  }
}

match *borrow { _ => {} } continues to check that *borrow is live, but does not read the value.
match *borrow {} both checks that *borrow is live, and fake-reads the value.

Continuation of #102256 #104844

Fixes #99180 #53114

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

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-opsem Relevant to the opsem team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MIR building optimizes away some place expressions around "_" patterns even with -Zmir-opt-level=0