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

@@ -680,8 +680,6 @@ pub type BinOp = Spanned<BinOp_>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum UnOp {
/// The `box` operator
UnUniq,
/// The `*` operator for dereferencing
UnDeref,
/// The `!` operator for logical inversion
@@ -799,8 +797,10 @@ impl fmt::Debug for Expr {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Expr_ {
/// A `box x` expression.
ExprBox(P<Expr>),
/// First expr is the place; second expr is the value.
ExprBox(Option<P<Expr>>, P<Expr>),
ExprInPlace(P<Expr>, P<Expr>),
/// An array (`[a, b, c, d]`)
ExprVec(Vec<P<Expr>>),
/// A function call

View File

@@ -101,10 +101,9 @@ pub fn is_by_value_unop(u: UnOp) -> bool {
pub fn unop_to_string(op: UnOp) -> &'static str {
match op {
UnUniq => "box() ",
UnDeref => "*",
UnNot => "!",
UnNeg => "-",
UnDeref => "*",
UnNot => "!",
UnNeg => "-",
}
}

View File

@@ -94,8 +94,8 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
})
}
// Desugar ExprBox: `in (PLACE) EXPR`
ast::ExprBox(Some(placer), value_expr) => {
// Desugar ExprInPlace: `in PLACE { EXPR }`
ast::ExprInPlace(placer, value_expr) => {
// to:
//
// let p = PLACE;

View File

@@ -707,11 +707,11 @@ impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> {
// But we keep these checks as a pre-expansion check to catch
// uses in e.g. conditionalized code.
if let ast::ExprBox(None, _) = e.node {
if let ast::ExprBox(_) = e.node {
self.context.gate_feature("box_syntax", e.span, EXPLAIN_BOX_SYNTAX);
}
if let ast::ExprBox(Some(_), _) = e.node {
if let ast::ExprInPlace(..) = e.node {
self.context.gate_feature("placement_in_syntax", e.span, EXPLAIN_PLACEMENT_IN);
}
@@ -860,7 +860,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
fn visit_expr(&mut self, e: &ast::Expr) {
match e.node {
ast::ExprBox(..) | ast::ExprUnary(ast::UnOp::UnUniq, _) => {
ast::ExprBox(_) => {
self.gate_feature("box_syntax",
e.span,
"box expression syntax is experimental; \

View File

@@ -1188,8 +1188,11 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
Expr {
id: folder.new_id(id),
node: match node {
ExprBox(p, e) => {
ExprBox(p.map(|e|folder.fold_expr(e)), folder.fold_expr(e))
ExprBox(e) => {
ExprBox(folder.fold_expr(e))
}
ExprInPlace(p, e) => {
ExprInPlace(folder.fold_expr(p), folder.fold_expr(e))
}
ExprVec(exprs) => {
ExprVec(exprs.move_map(|x| folder.fold_expr(x)))

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()
}

View File

@@ -1811,13 +1811,12 @@ impl<'a> State<'a> {
Ok(())
}
fn print_expr_box(&mut self,
place: &Option<P<ast::Expr>>,
expr: &ast::Expr) -> io::Result<()> {
try!(word(&mut self.s, "box"));
try!(word(&mut self.s, "("));
try!(place.as_ref().map_or(Ok(()), |e|self.print_expr(&**e)));
try!(self.word_space(")"));
fn print_expr_in_place(&mut self,
place: &ast::Expr,
expr: &ast::Expr) -> io::Result<()> {
try!(self.word_space("in"));
try!(self.print_expr(place));
try!(space(&mut self.s));
self.print_expr(expr)
}
@@ -1948,8 +1947,12 @@ impl<'a> State<'a> {
try!(self.ibox(indent_unit));
try!(self.ann.pre(self, NodeExpr(expr)));
match expr.node {
ast::ExprBox(ref place, ref expr) => {
try!(self.print_expr_box(place, &**expr));
ast::ExprBox(ref expr) => {
try!(self.word_space("box"));
try!(self.print_expr(expr));
}
ast::ExprInPlace(ref place, ref expr) => {
try!(self.print_expr_in_place(place, expr));
}
ast::ExprVec(ref exprs) => {
try!(self.print_expr_vec(&exprs[..]));

View File

@@ -735,8 +735,11 @@ pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) {
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
match expression.node {
ExprBox(ref place, ref subexpression) => {
place.as_ref().map(|e|visitor.visit_expr(&**e));
ExprBox(ref subexpression) => {
visitor.visit_expr(&**subexpression)
}
ExprInPlace(ref place, ref subexpression) => {
visitor.visit_expr(&**place);
visitor.visit_expr(&**subexpression)
}
ExprVec(ref subexpressions) => {