Repository navigation
The alternatives of an or-pattern share their bindings (D221, #823) - #3458
Merged
Merged
Conversation
added 7 commits
November 18, 2026 21:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #823. Delegated (D98; D221 records the brief): it adds no ownership rule. The arm means exactly what the same arm written once per alternative means.
Rule (§9.7, spec v7.67). Every alternative binds the same names, each with one type; the guard and the body see one binding per name, made by the alternative that matched. A missing name, an extra name, or two types is an error that names the alternative.
Sema. The first alternative introduces the bindings; a later one names them again (
check_or_pattern, andscope_put_at's shared path), where it used to be refused as shadowing.MirLower.
lower_or_pattern_bindingsbinds from it in that alternative's own block, into the first alternative's locals.restore_pattern_move_span).Evidence.
--validate-allandaudit:allclean on the test programs; under the debug allocator each value is dropped once and nothing leaks; a failed guard returns the value and the next arm binds it; a mutating call through the shared name writes an observed subject.Not yet. A list pattern that takes elements inside an alternative is refused at lowering (its log is not split by alternative), never lowered wrongly. Alternatives nested in a payload, and
if letwith|, are not in the grammar.Five tests. Battery green on the branch tip;
:release-checksgreen (the guard-restore path every pattern uses was restructured).