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

@ -80,11 +80,10 @@ use core::raw::{TraitObject};
/// use std::boxed::HEAP;
///
/// fn main() {
/// let foo = box(HEAP) 5;
/// let foo: Box<i32> = in HEAP { 5 };
/// let foo = box 5;
/// }
/// ```
#[lang = "exchange_heap"]
#[unstable(feature = "box_heap",
reason = "may be renamed; uncertain about custom allocator design",
issue = "27779")]

View file

@ -344,13 +344,12 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.straightline(expr, pred, [r, l].iter().map(|&e| &**e))
}
hir::ExprBox(Some(ref l), ref r) |
hir::ExprIndex(ref l, ref r) |
hir::ExprBinary(_, ref l, ref r) => { // NB: && and || handled earlier
self.straightline(expr, pred, [l, r].iter().map(|&e| &**e))
}
hir::ExprBox(None, ref e) |
hir::ExprBox(ref e) |
hir::ExprAddrOf(_, ref e) |
hir::ExprCast(ref e, _) |
hir::ExprUnary(_, ref e) |

View file

@ -568,8 +568,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
"user-defined operators are not allowed in {}s", v.msg());
}
}
hir::ExprBox(..) |
hir::ExprUnary(hir::UnUniq, _) => {
hir::ExprBox(_) => {
v.add_qualif(ConstQualif::NOT_CONST);
if v.mode != Mode::Var {
span_err!(v.tcx.sess, e.span, E0010,

View file

@ -280,13 +280,11 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
typer: &'t infer::InferCtxt<'a, 'tcx>)
-> ExprUseVisitor<'d,'t,'a,'tcx>
{
let result = ExprUseVisitor {
ExprUseVisitor {
typer: typer,
mc: mc::MemCategorizationContext::new(typer),
delegate: delegate,
};
result
}
}
pub fn walk_fn(&mut self,
@ -544,17 +542,8 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
self.walk_captures(expr)
}
hir::ExprBox(ref place, ref base) => {
match *place {
Some(ref place) => self.consume_expr(&**place),
None => {}
}
hir::ExprBox(ref base) => {
self.consume_expr(&**base);
if place.is_some() {
self.tcx().sess.span_bug(
expr.span,
"box with explicit place remains after expansion");
}
}
}
}

View file

@ -341,7 +341,6 @@ lets_do_this! {
EhUnwindResumeLangItem, "eh_unwind_resume", eh_unwind_resume;
MSVCTryFilterLangItem, "msvc_try_filter", msvc_try_filter;
ExchangeHeapLangItem, "exchange_heap", exchange_heap;
OwnedBoxLangItem, "owned_box", owned_box;
PhantomDataItem, "phantom_data", phantom_data;

View file

@ -1147,8 +1147,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
hir::ExprIndex(ref l, ref r) |
hir::ExprBinary(_, ref l, ref r) |
hir::ExprBox(Some(ref l), ref r) => {
hir::ExprBinary(_, ref l, ref r) => {
let r_succ = self.propagate_through_expr(&**r, succ);
self.propagate_through_expr(&**l, r_succ)
}
@ -1158,7 +1157,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
e1.as_ref().map_or(succ, |e| self.propagate_through_expr(&**e, succ))
}
hir::ExprBox(None, ref e) |
hir::ExprBox(ref e) |
hir::ExprAddrOf(_, ref e) |
hir::ExprCast(ref e, _) |
hir::ExprUnary(_, ref e) => {

View file

@ -994,9 +994,6 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, local: &hir::Local) {
visitor, &**subexpr, blk_id);
}
}
hir::ExprUnary(hir::UnUniq, ref subexpr) => {
record_rvalue_scope_if_borrow_expr(visitor, &**subexpr, blk_id);
}
hir::ExprCast(ref subexpr, _) => {
record_rvalue_scope_if_borrow_expr(visitor, &**subexpr, blk_id)
}

View file

@ -1040,8 +1040,8 @@ 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))
}
ExprVec(exprs) => {
ExprVec(exprs.move_map(|x| folder.fold_expr(x)))

View file

@ -491,8 +491,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
@ -595,8 +593,8 @@ impl fmt::Debug for Expr {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Expr_ {
/// First expr is the place; second expr is the value.
ExprBox(Option<P<Expr>>, P<Expr>),
/// A `box x` expression.
ExprBox(P<Expr>),
/// An array (`[a, b, c, d]`)
ExprVec(Vec<P<Expr>>),
/// A function call

View file

@ -605,7 +605,6 @@ pub fn lower_constness(c: Constness) -> hir::Constness {
pub fn lower_unop(u: UnOp) -> hir::UnOp {
match u {
UnUniq => hir::UnUniq,
UnDeref => hir::UnDeref,
UnNot => hir::UnNot,
UnNeg => hir::UnNeg,
@ -694,8 +693,8 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
P(hir::Expr {
id: e.id,
node: match e.node {
ExprBox(ref p, ref e) => {
hir::ExprBox(p.as_ref().map(|e| lower_expr(e)), lower_expr(e))
ExprBox(ref e) => {
hir::ExprBox(lower_expr(e))
}
ExprVec(ref exprs) => {
hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect())
@ -818,6 +817,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
ExprParen(ref ex) => {
return lower_expr(ex);
}
ExprInPlace(..) |
ExprIfLet(..) |
ExprWhileLet(..) |
ExprForLoop(..) |

View file

@ -1182,16 +1182,6 @@ impl<'a> State<'a> {
Ok(())
}
fn print_expr_box(&mut self,
place: &Option<P<hir::Expr>>,
expr: &hir::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(")"));
self.print_expr(expr)
}
fn print_expr_vec(&mut self, exprs: &[P<hir::Expr>]) -> io::Result<()> {
try!(self.ibox(indent_unit));
try!(word(&mut self.s, "["));
@ -1311,8 +1301,9 @@ impl<'a> State<'a> {
try!(self.ibox(indent_unit));
try!(self.ann.pre(self, NodeExpr(expr)));
match expr.node {
hir::ExprBox(ref place, ref expr) => {
try!(self.print_expr_box(place, &**expr));
hir::ExprBox(ref expr) => {
try!(self.word_space("box"));
try!(self.print_expr(expr));
}
hir::ExprVec(ref exprs) => {
try!(self.print_expr_vec(&exprs[..]));

View file

@ -128,7 +128,6 @@ 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 => "-",

View file

@ -722,8 +722,7 @@ pub fn walk_exprs<'v, V: Visitor<'v>>(visitor: &mut V, expressions: &'v [P<Expr>
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)
}
ExprVec(ref subexpressions) => {

View file

@ -442,7 +442,7 @@ impl LintPass for UnusedAllocation {
impl LateLintPass for UnusedAllocation {
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
match e.node {
hir::ExprUnary(hir::UnUniq, _) => (),
hir::ExprBox(_) => {}
_ => return
}

View file

@ -67,7 +67,7 @@ impl<H:Hair> Builder<H> {
let arg = unpack!(block = this.as_operand(block, arg));
block.and(Rvalue::UnaryOp(op, arg))
}
ExprKind::Box { place: _, value } => {
ExprKind::Box { value } => {
let value = this.hir.mirror(value);
let value_ty = value.ty.clone();
let result = this.temp(value_ty.clone());

View file

@ -171,7 +171,7 @@ pub struct Expr<H:Hair> {
#[derive(Clone, Debug)]
pub enum ExprKind<H:Hair> {
Scope { extent: H::CodeExtent, value: ExprRef<H> },
Box { place: Option<ExprRef<H>>, value: ExprRef<H> },
Box { value: ExprRef<H> },
Call { fun: ExprRef<H>, args: Vec<ExprRef<H>> },
Deref { arg: ExprRef<H> }, // NOT overloaded!
Binary { op: BinOp, lhs: ExprRef<H>, rhs: ExprRef<H> }, // NOT overloaded!

View file

@ -140,11 +140,6 @@ impl<'a,'tcx:'a> Mirror<Cx<'a,'tcx>> for &'tcx hir::Expr {
}
}
hir::ExprUnary(hir::UnOp::UnUniq, ref arg) => {
assert!(!cx.tcx.is_method_call(self.id));
ExprKind::Box { place: None, value: arg.to_ref() }
}
hir::ExprUnary(op, ref arg) => {
if cx.tcx.is_method_call(self.id) {
overloaded_operator(cx, self, ty::MethodCall::expr(self.id),
@ -154,10 +149,10 @@ impl<'a,'tcx:'a> Mirror<Cx<'a,'tcx>> for &'tcx hir::Expr {
let op = match op {
hir::UnOp::UnNot => UnOp::Not,
hir::UnOp::UnNeg => UnOp::Neg,
hir::UnOp::UnUniq | hir::UnOp::UnDeref => {
hir::UnOp::UnDeref => {
cx.tcx.sess.span_bug(
self.span,
&format!("operator should have been handled elsewhere {:?}", op));
"UnDeref should have been handled elsewhere");
}
};
ExprKind::Unary { op: op, arg: arg.to_ref() }
@ -296,8 +291,8 @@ impl<'a,'tcx:'a> Mirror<Cx<'a,'tcx>> for &'tcx hir::Expr {
name: Field::Indexed(ident.node) },
hir::ExprCast(ref source, _) =>
ExprKind::Cast { source: source.to_ref() },
hir::ExprBox(ref place, ref value) =>
ExprKind::Box { place: place.to_ref(), value: value.to_ref() },
hir::ExprBox(ref value) =>
ExprKind::Box { value: value.to_ref() },
hir::ExprVec(ref fields) =>
ExprKind::Vec { fields: fields.to_ref() },
hir::ExprTup(ref fields) =>

View file

@ -564,7 +564,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let is_float = ty.is_fp();
unsafe { match u {
hir::UnUniq | hir::UnDeref => const_deref(cx, te, ty).0,
hir::UnDeref => const_deref(cx, te, ty).0,
hir::UnNot => llvm::LLVMConstNot(te),
hir::UnNeg if is_float => llvm::LLVMConstFNeg(te),
hir::UnNeg => llvm::LLVMConstNeg(te),

View file

@ -325,9 +325,7 @@ fn walk_expr(cx: &CrateContext,
hir::ExprTupField(ref sub_exp, _) =>
walk_expr(cx, &**sub_exp, scope_stack, scope_map),
hir::ExprBox(ref place, ref sub_expr) => {
place.as_ref().map(
|e| walk_expr(cx, &**e, scope_stack, scope_map));
hir::ExprBox(ref sub_expr) => {
walk_expr(cx, &**sub_expr, scope_stack, scope_map);
}

View file

@ -673,7 +673,7 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
hir::ExprIndex(ref base, ref idx) => {
trans_index(bcx, expr, &**base, &**idx, MethodCall::expr(expr.id))
}
hir::ExprBox(_, ref contents) => {
hir::ExprBox(ref contents) => {
// Special case for `Box<T>`
let box_ty = expr_ty(bcx, expr);
let contents_ty = expr_ty(bcx, &**contents);
@ -1649,9 +1649,6 @@ fn trans_unary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
};
immediate_rvalue_bcx(bcx, llneg, un_ty).to_expr_datumblock()
}
hir::UnUniq => {
trans_uniq_expr(bcx, expr, un_ty, sub_expr, expr_ty(bcx, sub_expr))
}
hir::UnDeref => {
let datum = unpack_datum!(bcx, trans(bcx, sub_expr));
deref_once(bcx, expr, datum, method_call)
@ -2769,24 +2766,11 @@ fn expr_kind(tcx: &ty::ctxt, expr: &hir::Expr) -> ExprKind {
hir::ExprLit(_) | // Note: LitStr is carved out above
hir::ExprUnary(..) |
hir::ExprBox(None, _) |
hir::ExprBox(_) |
hir::ExprAddrOf(..) |
hir::ExprBinary(..) |
hir::ExprCast(..) => {
ExprKind::RvalueDatum
}
hir::ExprBox(Some(ref place), _) => {
// Special case `Box<T>` for now:
let def_id = match tcx.def_map.borrow().get(&place.id) {
Some(def) => def.def_id(),
None => panic!("no def for place"),
};
if tcx.lang_items.exchange_heap() == Some(def_id) {
ExprKind::RvalueDatum
} else {
ExprKind::RvalueDps
}
}
}
}

View file

@ -3212,31 +3212,16 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
let tcx = fcx.ccx.tcx;
let id = expr.id;
match expr.node {
hir::ExprBox(ref opt_place, ref subexpr) => {
opt_place.as_ref().map(|place|check_expr(fcx, &**place));
check_expr(fcx, &**subexpr);
let mut checked = false;
opt_place.as_ref().map(|place| match place.node {
hir::ExprPath(None, ref path) => {
// FIXME(pcwalton): For now we hardcode the only permissible
// place: the exchange heap.
let definition = lookup_full_def(tcx, path.span, place.id);
let def_id = definition.def_id();
let referent_ty = fcx.expr_ty(&**subexpr);
if tcx.lang_items.exchange_heap() == Some(def_id) {
fcx.write_ty(id, tcx.mk_box(referent_ty));
checked = true
hir::ExprBox(ref subexpr) => {
let expected_inner = expected.to_option(fcx).map_or(NoExpectation, |ty| {
match ty.sty {
ty::TyBox(ty) => Expectation::rvalue_hint(tcx, ty),
_ => NoExpectation
}
}
_ => {}
});
if !checked {
span_err!(tcx.sess, expr.span, E0066,
"only the exchange heap is currently supported");
fcx.write_ty(id, tcx.types.err);
}
check_expr_with_expectation(fcx, subexpr, expected_inner);
let referent_ty = fcx.expr_ty(&**subexpr);
fcx.write_ty(id, tcx.mk_box(referent_ty));
}
hir::ExprLit(ref lit) => {
@ -3250,24 +3235,14 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
op::check_binop_assign(fcx, expr, op, lhs, rhs);
}
hir::ExprUnary(unop, ref oprnd) => {
let expected_inner = expected.to_option(fcx).map_or(NoExpectation, |ty| {
match unop {
hir::UnUniq => match ty.sty {
ty::TyBox(ty) => {
Expectation::rvalue_hint(tcx, ty)
}
_ => {
NoExpectation
}
},
let expected_inner = match unop {
hir::UnNot | hir::UnNeg => {
expected
}
hir::UnDeref => {
NoExpectation
}
}
});
};
let lvalue_pref = match unop {
hir::UnDeref => lvalue_pref,
_ => NoPreference
@ -3278,9 +3253,6 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
if !oprnd_t.references_error() {
match unop {
hir::UnUniq => {
oprnd_t = tcx.mk_box(oprnd_t);
}
hir::UnDeref => {
oprnd_t = structurally_resolved_type(fcx, expr.span, oprnd_t);
oprnd_t = match oprnd_t.builtin_deref(true, NoPreference) {

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,7 +101,6 @@ 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 => "-",

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);
token::Ident(..) if self.token.is_keyword(keywords::In) => {
try!(self.bump());
if is_in {
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();
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(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 = 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>>,
fn print_expr_in_place(&mut self,
place: &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(")"));
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) => {

View file

@ -22,5 +22,5 @@ pub trait i<T>
pub fn f<T>() -> Box<i<T>+'static> {
impl<T> i<T> for () { }
box() () as Box<i<T>+'static>
box () as Box<i<T>+'static>
}

View file

@ -23,8 +23,7 @@ fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
fn produce<T>() -> T { panic!(); }
fn inc(v: &mut Box<isize>) {
*v = box() (**v + 1);
//~^ WARN deprecated syntax
*v = box (**v + 1);
}
fn pre_freeze_cond() {

View file

@ -22,8 +22,7 @@ fn cond() -> bool { panic!() }
fn produce<T>() -> T { panic!(); }
fn inc(v: &mut Box<isize>) {
*v = box() (**v + 1);
//~^ WARN deprecated syntax
*v = box (**v + 1);
}
fn loop_overarching_alias_mut() {

View file

@ -23,8 +23,7 @@ fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
fn produce<T>() -> T { panic!(); }
fn inc(v: &mut Box<isize>) {
*v = box() (**v + 1);
//~^ WARN deprecated syntax
*v = box (**v + 1);
}
fn pre_freeze() {

View file

@ -22,8 +22,7 @@ impl Add for foo {
fn add(self, f: foo) -> foo {
let foo(box i) = self;
let foo(box j) = f;
foo(box() (i + j))
//~^ WARN deprecated syntax
foo(box (i + j))
}
}

View file

@ -19,8 +19,4 @@
fn main() {
let x = box 'c'; //~ ERROR box expression syntax is experimental
println!("x: {}", x);
let x = box () 'c'; //~ ERROR box expression syntax is experimental
//~^ WARN deprecated syntax
println!("x: {}", x);
}

View file

@ -19,10 +19,6 @@
fn main() {
use std::boxed::HEAP;
let x = box (HEAP) 'c'; //~ ERROR placement-in expression syntax is experimental
//~^ WARN deprecated syntax
println!("x: {}", x);
let x = in HEAP { 'c' }; //~ ERROR placement-in expression syntax is experimental
println!("x: {}", x);
}

View file

@ -12,8 +12,7 @@
#![feature(placement_in_syntax)]
fn main() {
box ( () ) 0;
in () { 0 };
//~^ ERROR: the trait `core::ops::Placer<_>` is not implemented
//~| ERROR: the trait `core::ops::Placer<_>` is not implemented
//~| WARN deprecated syntax
}

View file

@ -11,8 +11,7 @@
#![feature(box_syntax)]
fn dup(x: Box<isize>) -> Box<(Box<isize>,Box<isize>)> {
box() (x, x) //~ ERROR use of moved value
//~^ WARN deprecated syntax
box (x, x) //~ ERROR use of moved value
}
fn main() {
dup(box 3);

View file

@ -50,7 +50,7 @@ fn main() {
let stack_val_ref: &(i16, f32) = &stack_val;
let ref_to_unnamed: &(i16, f32) = &(-15, -20f32);
let unique_val: Box<(i16, f32)> = box() (-17, -22f32);
let unique_val: Box<(i16, f32)> = box (-17, -22f32);
let unique_val_ref: &(i16, f32) = &*unique_val;
zzz(); // #break

View file

@ -37,7 +37,7 @@
fn main() {
let a = box 1;
let b = box() (2, 3.5f64);
let b = box (2, 3.5f64);
zzz(); // #break
}

View file

@ -433,7 +433,7 @@ fn main() {
managed_box(&(34, 35));
borrowed_pointer(&(36, 37));
contained_borrowed_pointer((&38, 39));
unique_pointer(box() (40, 41, 42));
unique_pointer(box (40, 41, 42));
ref_binding((43, 44, 45));
ref_binding_in_tuple((46, (47, 48)));
ref_binding_in_struct(Struct { a: 49, b: 50 });

View file

@ -304,7 +304,7 @@ fn main() {
let (&cc, _) = (&38, 39);
// unique pointer
let box dd = box() (40, 41, 42);
let box dd = box (40, 41, 42);
// ref binding
let ref ee = (43, 44, 45);

View file

@ -1,19 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -Z parse-only
fn main() {
box (1 + 1)
//~^ HELP try using `box ()` instead:
//~| SUGGESTION box () (1 + 1)
//~| WARN deprecated syntax
; //~ ERROR expected expression, found `;`
}

View file

@ -21,6 +21,6 @@ impl double for usize {
}
pub fn main() {
let x: Box<_> = box() (box 3usize as Box<double>);
let x: Box<_> = box (box 3usize as Box<double>);
assert_eq!(x.double(), 6);
}

View file

@ -24,7 +24,7 @@ extern crate crate_method_reexport_grrrrrrr2;
pub fn main() {
use crate_method_reexport_grrrrrrr2::rust::add;
use crate_method_reexport_grrrrrrr2::rust::cx;
let x: Box<_> = box () ();
let x: Box<_> = box ();
x.cx();
let y = ();
y.add("hi".to_string());

View file

@ -16,5 +16,5 @@
pub fn main() {
fn f() {
};
let _: Box<fn()> = box() (f as fn());
let _: Box<fn()> = box (f as fn());
}

View file

@ -28,7 +28,7 @@ pub fn main() {
// let y = box ({a: 4});
// let z = box ({a: 4} as it);
// let z = box ({a: true} as it);
let z: Box<_> = box () (box true as Box<it>);
let z: Box<_> = box (box true as Box<it>);
// x.f();
// y.f();
// (*z).f();

View file

@ -31,10 +31,10 @@ struct Structure {
}
pub fn main() {
let x: Box<isize> = box(HEAP) 2;
let x: Box<isize> = in HEAP { 2 };
let y: Box<isize> = box 2;
let b: Box<isize> = box()(1 + 2);
let c = box()(3 + 4);
let b: Box<isize> = box (1 + 2);
let c = box (3 + 4);
let s: Box<Structure> = box Structure {
x: 3,

View file

@ -83,7 +83,7 @@ impl<'s> Trait<'s> for (isize,isize) {
impl<'t> MakerTrait for Box<Trait<'t>+'static> {
fn mk() -> Box<Trait<'t>+'static> {
let tup: Box<(isize, isize)> = box() (4,5);
let tup: Box<(isize, isize)> = box (4,5);
tup as Box<Trait>
}
}

View file

@ -49,6 +49,6 @@ impl<V> Trait<u8,V> for () {
}
pub fn main() {
let a = box() () as Box<Trait<u8, u8>>;
let a = box () as Box<Trait<u8, u8>>;
assert_eq!(a.method(Type::Constant((1, 2))), 0);
}