Skip to content

Commit 7820728

Browse files
committed
---
yaml --- r: 228666 b: refs/heads/try c: 9f6f35b h: refs/heads/master v: v3
1 parent ebe3a31 commit 7820728

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: e0b44797ce644210af0fd1596d1aa2e5338c976b
4+
refs/heads/try: 9f6f35bef4986e02f811a1fb7c3da212241784a8
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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