@@ -2612,18 +2612,43 @@ impl<'a> Parser<'a> {
2612
2612
ex = ExprAddrOf ( m, e) ;
2613
2613
}
2614
2614
token:: Ident ( _, _) => {
2615
- if !self . check_keyword ( keywords:: Box ) {
2615
+ if !self . check_keyword ( keywords:: Box ) && ! self . check_keyword ( keywords :: In ) {
2616
2616
return self . parse_dot_or_call_expr ( ) ;
2617
2617
}
2618
2618
2619
2619
let lo = self . span . lo ;
2620
- let box_hi = self . span . hi ;
2620
+ let keyword_hi = self . span . hi ;
2621
2621
2622
+ let is_in = self . token . is_keyword ( keywords:: In ) ;
2622
2623
try!( self . bump ( ) ) ;
2623
2624
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
+
2625
2640
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)
2627
2652
if !try!( self . eat ( & token:: CloseDelim ( token:: Paren ) ) ) {
2628
2653
let place = try!( self . parse_expr_nopanic ( ) ) ;
2629
2654
try!( self . expect ( & token:: CloseDelim ( token:: Paren ) ) ) ;
@@ -2634,10 +2659,9 @@ impl<'a> Parser<'a> {
2634
2659
self . span_err ( span,
2635
2660
& format ! ( "expected expression, found `{}`" ,
2636
2661
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) ;
2641
2665
self . abort_if_errors ( ) ;
2642
2666
}
2643
2667
let subexpression = try!( self . parse_prefix_expr ( ) ) ;
@@ -2650,6 +2674,7 @@ impl<'a> Parser<'a> {
2650
2674
// Otherwise, we use the unique pointer default.
2651
2675
let subexpression = try!( self . parse_prefix_expr ( ) ) ;
2652
2676
hi = subexpression. span . hi ;
2677
+
2653
2678
// FIXME (pnkfelix): After working out kinks with box
2654
2679
// desugaring, should be `ExprBox(None, subexpression)`
2655
2680
// instead.
0 commit comments