expand inner or
pattern
This commit is contained in:
parent
3a8b0144c8
commit
90abfe9ce2
@ -453,7 +453,17 @@ pub(super) fn column_count(&self) -> Option<usize> {
|
||||
/// expands it.
|
||||
fn push(&mut self, row: PatStack<'p, 'tcx>) {
|
||||
if !row.is_empty() && row.head().is_or_pat() {
|
||||
self.patterns.extend(row.expand_or_pat());
|
||||
let pats = row.expand_or_pat();
|
||||
let mut no_inner_or = true;
|
||||
for pat in pats {
|
||||
if !pat.is_empty() && pat.head().is_or_pat() {
|
||||
self.patterns.extend(pat.expand_or_pat());
|
||||
no_inner_or = false;
|
||||
}
|
||||
}
|
||||
if no_inner_or {
|
||||
self.patterns.extend(row.expand_or_pat());
|
||||
}
|
||||
} else {
|
||||
self.patterns.push(row);
|
||||
}
|
||||
|
13
src/test/ui/or-patterns/inner-or-pat-2.rs
Normal file
13
src/test/ui/or-patterns/inner-or-pat-2.rs
Normal file
@ -0,0 +1,13 @@
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_parens)]
|
||||
fn main() {
|
||||
let x = "foo";
|
||||
match x {
|
||||
x @ ((("h" | "ho" | "yo" | ("dude" | "w")) | () | "nop") | ("hey" | "gg")) |
|
||||
//~^ ERROR mismatched types
|
||||
x @ ("black" | "pink") |
|
||||
x @ ("red" | "blue") => {
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
11
src/test/ui/or-patterns/inner-or-pat-2.stderr
Normal file
11
src/test/ui/or-patterns/inner-or-pat-2.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/inner-or-pat-2.rs:6:54
|
||||
|
|
||||
LL | match x {
|
||||
| - this expression has type `&str`
|
||||
LL | x @ ((("h" | "ho" | "yo" | ("dude" | "w")) | () | "nop") | ("hey" | "gg")) |
|
||||
| ^^ expected `str`, found `()`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
15
src/test/ui/or-patterns/inner-or-pat-3.rs
Normal file
15
src/test/ui/or-patterns/inner-or-pat-3.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// run-pass
|
||||
|
||||
#[allow(unreachable_patterns)]
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_parens)]
|
||||
fn main() {
|
||||
let x = "foo";
|
||||
|
||||
match x {
|
||||
x @ ("foo" | "bar") |
|
||||
(x @ "red" | (x @ "blue" | x @ "red")) => {
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
13
src/test/ui/or-patterns/inner-or-pat-4.rs
Normal file
13
src/test/ui/or-patterns/inner-or-pat-4.rs
Normal file
@ -0,0 +1,13 @@
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_parens)]
|
||||
fn main() {
|
||||
let x = "foo";
|
||||
|
||||
match x {
|
||||
x @ ("foo" | "bar") |
|
||||
(x @ "red" | (x @ "blue" | "red")) => {
|
||||
//~^ variable `x` is not bound in all patterns
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
11
src/test/ui/or-patterns/inner-or-pat-4.stderr
Normal file
11
src/test/ui/or-patterns/inner-or-pat-4.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0408]: variable `x` is not bound in all patterns
|
||||
--> $DIR/inner-or-pat-4.rs:8:37
|
||||
|
|
||||
LL | (x @ "red" | (x @ "blue" | "red")) => {
|
||||
| - ^^^^^ pattern doesn't bind `x`
|
||||
| |
|
||||
| variable not in all patterns
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0408`.
|
14
src/test/ui/or-patterns/inner-or-pat.rs
Normal file
14
src/test/ui/or-patterns/inner-or-pat.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// run-pass
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_parens)]
|
||||
fn main() {
|
||||
let x = "foo";
|
||||
match x {
|
||||
x @ ((("h" | "ho" | "yo" | ("dude" | "w")) | "no" | "nop") | ("hey" | "gg")) |
|
||||
x @ ("black" | "pink") |
|
||||
x @ ("red" | "blue") => {
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user