Skip to content

Commit

Permalink
libsyntax: Add box PAT to the pattern grammar. RFC brson#14.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed May 3, 2014
1 parent b5d6b07 commit 80b43de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions src/test/run-pass/box-pattern.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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);
}
}
}

0 comments on commit 80b43de

Please sign in to comment.