From 80b43de5ab1bb063a1d1eaab64dd0389c4443541 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 2 May 2014 17:21:36 -0700 Subject: [PATCH] libsyntax: Add `box PAT` to the pattern grammar. RFC #14. --- src/libsyntax/parse/parser.rs | 13 +++++++++++++ src/test/run-pass/box-pattern.rs | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/test/run-pass/box-pattern.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5d8443b64d5ef..eefb496c94338 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2867,6 +2867,19 @@ impl<'a> Parser<'a> { // parse ref pat let mutbl = self.parse_mutability(); pat = self.parse_pat_ident(BindByRef(mutbl)); + } else if self.eat_keyword(keywords::Box) { + // `box PAT` + // + // FIXME(#13910): Rename to `PatBox` and extend to full DST + // support. + let sub = self.parse_pat(); + pat = PatUniq(sub); + hi = self.last_span.hi; + return @ast::Pat { + id: ast::DUMMY_NODE_ID, + node: pat, + span: mk_sp(lo, hi) + } } else { let can_be_enum_or_struct = self.look_ahead(1, |t| { match *t { diff --git a/src/test/run-pass/box-pattern.rs b/src/test/run-pass/box-pattern.rs new file mode 100644 index 0000000000000..101d7c19459a9 --- /dev/null +++ b/src/test/run-pass/box-pattern.rs @@ -0,0 +1,20 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let box x = box 3; + match box 3 { + box y => { + assert!(x == y); + println!("{} {}", x, y); + } + } +} +