Skip to content

Commit 3e7aed4

Browse files
committed
---
yaml --- r: 224154 b: refs/heads/beta c: 9f6f35b h: refs/heads/master v: v3
1 parent 0127f9b commit 3e7aed4

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: e0b44797ce644210af0fd1596d1aa2e5338c976b
26+
refs/heads/beta: 9f6f35bef4986e02f811a1fb7c3da212241784a8
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 938f5d7af401e2d8238522fed4a612943b6e77fd
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/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)