1
Fork 0

Remove the deprecated box(PLACE) syntax.

This commit is contained in:
Eduard Burtescu 2015-09-24 18:00:08 +03:00
parent 07ca1ab1ec
commit f293ea28b4
50 changed files with 117 additions and 282 deletions

View file

@ -22,7 +22,7 @@ use ast::{Decl, DeclItem, DeclLocal, DefaultBlock, DefaultReturn};
use ast::{UnDeref, BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf};
use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain};
use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox};
use ast::{ExprBreak, ExprCall, ExprCast};
use ast::{ExprBreak, ExprCall, ExprCast, ExprInPlace};
use ast::{ExprField, ExprTupField, ExprClosure, ExprIf, ExprIfLet, ExprIndex};
use ast::{ExprLit, ExprLoop, ExprMac, ExprRange};
use ast::{ExprMethodCall, ExprParen, ExprPath};
@ -54,7 +54,7 @@ use ast::{TupleVariantKind, Ty, Ty_, TypeBinding};
use ast::{TyMac};
use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer};
use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr};
use ast::{TyRptr, TyTup, TyU32, TyVec, UnUniq};
use ast::{TyRptr, TyTup, TyU32, TyVec};
use ast::{TypeImplItem, TypeTraitItem};
use ast::{UnnamedField, UnsafeBlock};
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
@ -2617,76 +2617,19 @@ impl<'a> Parser<'a> {
hi = e.span.hi;
ex = ExprAddrOf(m, e);
}
token::Ident(_, _) => {
if !self.check_keyword(keywords::Box) && !self.check_keyword(keywords::In) {
return self.parse_dot_or_call_expr();
}
let lo = self.span.lo;
let keyword_hi = self.span.hi;
let is_in = self.token.is_keyword(keywords::In);
try!(self.bump());
if is_in {
token::Ident(..) if self.token.is_keyword(keywords::In) => {
try!(self.bump());
let place = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL));
let blk = try!(self.parse_block());
hi = blk.span.hi;
let blk_expr = self.mk_expr(blk.span.lo, blk.span.hi, ExprBlock(blk));
ex = ExprBox(Some(place), blk_expr);
return Ok(self.mk_expr(lo, hi, ex));
}
// FIXME (#22181) Remove `box (PLACE) EXPR` support
// entirely after next release (enabling `(box (EXPR))`),
// since it will be replaced by `in PLACE { EXPR }`, ...
//
// ... but for now: check for a place: `box(PLACE) EXPR`.
if try!(self.eat(&token::OpenDelim(token::Paren))) {
let box_span = mk_sp(lo, self.last_span.hi);
self.span_warn(box_span,
"deprecated syntax; use the `in` keyword now \
(e.g. change `box (<expr>) <expr>` to \
`in <expr> { <expr> }`)");
// Continue supporting `box () EXPR` (temporarily)
if !try!(self.eat(&token::CloseDelim(token::Paren))) {
let place = try!(self.parse_expr_nopanic());
try!(self.expect(&token::CloseDelim(token::Paren)));
// Give a suggestion to use `box()` when a parenthesised expression is used
if !self.token.can_begin_expr() {
let span = self.span;
let this_token_to_string = self.this_token_to_string();
self.span_err(span,
&format!("expected expression, found `{}`",
this_token_to_string));
// Spanning just keyword avoids constructing
// printout of arg expression (which starts
// with parenthesis, as established above).
let box_span = mk_sp(lo, keyword_hi);
self.span_suggestion(box_span,
"try using `box ()` instead:",
format!("box ()"));
self.abort_if_errors();
}
let subexpression = try!(self.parse_prefix_expr());
hi = subexpression.span.hi;
ex = ExprBox(Some(place), subexpression);
return Ok(self.mk_expr(lo, hi, ex));
}
}
// Otherwise, we use the unique pointer default.
let subexpression = try!(self.parse_prefix_expr());
hi = subexpression.span.hi;
// FIXME (pnkfelix): After working out kinks with box
// desugaring, should be `ExprBox(None, subexpression)`
// instead.
ex = self.mk_unary(UnUniq, subexpression);
ex = ExprInPlace(place, blk_expr);
}
token::Ident(..) if self.token.is_keyword(keywords::Box) => {
try!(self.bump());
let subexpression = try!(self.parse_prefix_expr());
hi = subexpression.span.hi;
ex = ExprBox(subexpression);
}
_ => return self.parse_dot_or_call_expr()
}