Skip to content

Commit 9f6f35b

Browse files
committed
Added support for parsing in PLACE { BLOCK_CONTENT }.
1 parent e0b4479 commit 9f6f35b

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,18 +2612,43 @@ impl<'a> Parser<'a> {
26122612
ex = ExprAddrOf(m, e);
26132613
}
26142614
token::Ident(_, _) => {
2615-
if !self.check_keyword(keywords::Box) {
2615+
if !self.check_keyword(keywords::Box) && !self.check_keyword(keywords::In) {
26162616
return self.parse_dot_or_call_expr();
26172617
}
26182618

26192619
let lo = self.span.lo;
2620-
let box_hi = self.span.hi;
2620+
let keyword_hi = self.span.hi;
26212621

2622+
let is_in = self.token.is_keyword(keywords::In);
26222623
try!(self.bump());
26232624

2624-
// Check for a place: `box(PLACE) EXPR`.
2625+
if is_in {
2626+
let place = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL));
2627+
let blk = try!(self.parse_block());
2628+
hi = blk.span.hi;
2629+
let blk_expr = self.mk_expr(blk.span.lo, blk.span.hi, ExprBlock(blk));
2630+
ex = ExprBox(Some(place), blk_expr);
2631+
return Ok(self.mk_expr(lo, hi, ex));
2632+
}
2633+
2634+
// FIXME (#22181) Remove `box (PLACE) EXPR` support
2635+
// entirely after next release (enabling `(box (EXPR))`),
2636+
// since it will be replaced by `in PLACE { EXPR }`, ...
2637+
//
2638+
// ... but for now: check for a place: `box(PLACE) EXPR`.
2639+
26252640
if try!(self.eat(&token::OpenDelim(token::Paren)) ){
2626-
// Support `box() EXPR` as the default.
2641+
// SNAP ba0e1cd
2642+
// Enable this warning after snapshot ...
2643+
//
2644+
// let box_span = mk_sp(lo, self.last_span.hi);
2645+
// self.span_warn(
2646+
// box_span,
2647+
// "deprecated syntax; use the `in` keyword now \
2648+
// (e.g. change `box (<expr>) <expr>` to \
2649+
// `in <expr> { <expr> }`)");
2650+
2651+
// Continue supporting `box () EXPR` (temporarily)
26272652
if !try!(self.eat(&token::CloseDelim(token::Paren)) ){
26282653
let place = try!(self.parse_expr_nopanic());
26292654
try!(self.expect(&token::CloseDelim(token::Paren)));
@@ -2634,10 +2659,9 @@ impl<'a> Parser<'a> {
26342659
self.span_err(span,
26352660
&format!("expected expression, found `{}`",
26362661
this_token_to_string));
2637-
let box_span = mk_sp(lo, box_hi);
2638-
self.span_suggestion(box_span,
2639-
"try using `box()` instead:",
2640-
"box()".to_string());
2662+
let box_span = mk_sp(lo, keyword_hi);
2663+
let new_expr = format!("box () {}", pprust::expr_to_string(&place));
2664+
self.span_suggestion(box_span, "try using `box ()` instead:", new_expr);
26412665
self.abort_if_errors();
26422666
}
26432667
let subexpression = try!(self.parse_prefix_expr());
@@ -2650,6 +2674,7 @@ impl<'a> Parser<'a> {
26502674
// Otherwise, we use the unique pointer default.
26512675
let subexpression = try!(self.parse_prefix_expr());
26522676
hi = subexpression.span.hi;
2677+
26532678
// FIXME (pnkfelix): After working out kinks with box
26542679
// desugaring, should be `ExprBox(None, subexpression)`
26552680
// instead.

0 commit comments

Comments
 (0)