From 9a269a3aa8fe8140ad3f2fc2cfdfd68d6b40ec86 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 8 Dec 2011 11:56:16 +0100 Subject: 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 --- src/comp/syntax/print/pprust.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/comp/syntax/print/pprust.rs') diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 2bb8463e2b9..ff28edd057a 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1062,7 +1062,13 @@ fn print_pat(s: ps, &&pat: @ast::pat) { s.ann.pre(ann_node); alt pat.node { ast::pat_wild. { word(s.s, "_"); } - ast::pat_bind(id) { word(s.s, id); } + ast::pat_bind(id, sub) { + word(s.s, id); + alt sub { + some(p) { word(s.s, "@"); print_pat(s, p); } + _ {} + } + } ast::pat_tag(path, args) { print_path(s, path, true); if vec::len(args) > 0u { -- cgit 1.4.1-3-g733a5