-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Initial implementation of or-patterns #61708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# `or_patterns` | ||
|
||
The tracking issue for this feature is: [#54883] | ||
|
||
[#54883]: https://github.com/rust-lang/rust/issues/54883 | ||
|
||
------------------------ | ||
|
||
The `or_pattern` language feature allows `|` to be arbitrarily nested within | ||
a pattern, for example, `Some(A(0) | B(1 | 2))` becomes a valid pattern. | ||
|
||
## Examples | ||
|
||
```rust,ignore | ||
#![feature(or_patterns)] | ||
|
||
pub enum Foo { | ||
Bar, | ||
Baz, | ||
Quux, | ||
} | ||
|
||
pub fn example(maybe_foo: Option<Foo>) { | ||
match maybe_foo { | ||
Some(Foo::Bar | Foo::Baz) => { | ||
println!("The value contained `Bar` or `Baz`"); | ||
} | ||
Some(_) => { | ||
println!("The value did not contain `Bar` or `Baz`"); | ||
} | ||
None => { | ||
println!("The value was `None`"); | ||
} | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | |
candidate.match_pairs.push(MatchPair::new(place, subpattern)); | ||
Ok(()) | ||
} | ||
|
||
PatternKind::Or { .. } => { | ||
Err(match_pair) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for the vector to be length 1 here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the pattern There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We currently don't parse a trailing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, yes, that's true. Can you add a comment above |
||
} | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.