diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-12-08 11:56:16 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-12-08 12:03:48 +0100 |
| commit | 9a269a3aa8fe8140ad3f2fc2cfdfd68d6b40ec86 (patch) | |
| tree | efb59785d520476c50204eadce27bfb9128ca512 /src/test | |
| parent | 8c966b7b18a5529c33dd9766460880bd681ab102 (diff) | |
| download | rust-9a269a3aa8fe8140ad3f2fc2cfdfd68d6b40ec86.tar.gz rust-9a269a3aa8fe8140ad3f2fc2cfdfd68d6b40ec86.zip | |
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
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/nested-patterns.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/test/run-pass/nested-patterns.rs b/src/test/run-pass/nested-patterns.rs new file mode 100644 index 00000000000..79eb1d40e4d --- /dev/null +++ b/src/test/run-pass/nested-patterns.rs @@ -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; +} |
