Skip to content

Commit 19d5c9e

Browse files
Handle Struct { box i } syntax
Named structs can have `box` patterns that will bind to their fields. This is similar to the behavior of the `ref` and `mut` fields, but is at least a little bit surprising.
1 parent 8454f59 commit 19d5c9e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

crates/ra_parser/src/grammar/patterns.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ fn record_field_pat_list(p: &mut Parser) {
162162
T![..] => p.bump(),
163163
IDENT if p.nth(1) == T![:] => record_field_pat(p),
164164
T!['{'] => error_block(p, "expected ident"),
165+
T![box] => {
166+
box_pat(p);
167+
}
165168
_ => {
166169
bind_pat(p, false);
167170
}
@@ -271,9 +274,6 @@ fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker {
271274
}
272275

273276
// test box_pat
274-
// struct Outer;
275-
// struct Inner;
276-
//
277277
// fn main() {
278278
// let box i = ();
279279
// let box Outer { box i, j: box Inner(box &x) } = ();
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
struct Outer;
2-
struct Inner;
1+
fn main() {
2+
let box i = ();
3+
let box Outer { box i, j: box Inner(box &x) } = ();
4+
let box ref mut i = ();
5+
}

0 commit comments

Comments
 (0)