Document which union patterns are unsafe - #2350
Draft
Jules-Bertholet wants to merge 4 commits into
Draft
Jules-Bertholet wants to merge 4 commits into
Jules-Bertholet wants to merge 4 commits into
Conversation
Contributor
|
I think this kind of definition of what patterns "access" a thing could also be useful for implementing a lint for rust-lang/rust#158387 (comment). cc @Nadrieril |
dianne
reviewed
Sep 9, 2026
Jules-Bertholet
force-pushed
the
safe-union-leaf-patterns
branch
from
September 10, 2026 04:32
0736dea to
27d2069
Compare
Nadrieril
reviewed
Sep 21, 2026
| - [Reference patterns](../patterns.md#reference-patterns) | ||
| - [Non-reference patterns](../patterns.md#r-patterns.ident.binding.non-reference) matching reference values | ||
| - [Struct](../patterns.md#struct-patterns) and [tuple struct](../patterns.md#tuple-struct-patterns) patterns which correspond to an enum variant | ||
| - [Path patterns](../patterns.md#path-patterns), if the result of expanding the constant into a pattern contains one of the above, or if the expanded pattern could not have been written directly at the location where it is used due to field privacy or `#[non_exhaustive]`. |
Member
There was a problem hiding this comment.
I'd like to add constant patterns there, because it should be allowed to turn a constant patter nmatch into a call to PartialEq::eq for performance. This conflicts with https://doc.rust-lang.org/reference/patterns.html?highlight=patterns#r-patterns.const.translation a bit so we conceptually are saying "unsafety checking is done before we expand constant patterns"
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.
Documents rust-lang/rust#161771.