Skip to content

Commit 80b43de

Browse files
committed
libsyntax: Add box PAT to the pattern grammar. RFC rust-lang#14.
1 parent b5d6b07 commit 80b43de

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/libsyntax/parse/parser.rs

+13
Original file line numberDiff line numberDiff line change
@@ -2867,6 +2867,19 @@ impl<'a> Parser<'a> {
28672867
// parse ref pat
28682868
let mutbl = self.parse_mutability();
28692869
pat = self.parse_pat_ident(BindByRef(mutbl));
2870+
} else if self.eat_keyword(keywords::Box) {
2871+
// `box PAT`
2872+
//
2873+
// FIXME(#13910): Rename to `PatBox` and extend to full DST
2874+
// support.
2875+
let sub = self.parse_pat();
2876+
pat = PatUniq(sub);
2877+
hi = self.last_span.hi;
2878+
return @ast::Pat {
2879+
id: ast::DUMMY_NODE_ID,
2880+
node: pat,
2881+
span: mk_sp(lo, hi)
2882+
}
28702883
} else {
28712884
let can_be_enum_or_struct = self.look_ahead(1, |t| {
28722885
match *t {

src/test/run-pass/box-pattern.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let box x = box 3;
13+
match box 3 {
14+
box y => {
15+
assert!(x == y);
16+
println!("{} {}", x, y);
17+
}
18+
}
19+
}
20+

0 commit comments

Comments
 (0)