Allow binding of nested patterns
See src/test/run-pass/nested-patterns.rs for some examples. The syntax is
boundvar@subpattern
Which will match the subpattern as usual, but also bind boundvar to the
whole matched value.
Closes #838
This commit is contained in:
parent
8c966b7b18
commit
9a269a3aa8
17 changed files with 132 additions and 79 deletions
12
src/test/run-pass/nested-patterns.rs
Normal file
12
src/test/run-pass/nested-patterns.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fn main() {
|
||||
alt {a: 10, b: @20} {
|
||||
x@{a, b: @20} { assert x.a == 10; assert a == 10; }
|
||||
{b, _} { fail; }
|
||||
}
|
||||
let x@{b, _} = {a: 10, b: {mutable c: 20}};
|
||||
x.b.c = 30;
|
||||
assert b.c == 20;
|
||||
let y@{d, _} = {a: 10, d: {mutable c: 20}};
|
||||
y.d.c = 30;
|
||||
assert d.c == 20;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue