diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 4293b4765e127..3239677fc0cc9 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -80,11 +80,10 @@ use core::raw::{TraitObject}; /// use std::boxed::HEAP; /// /// fn main() { -/// let foo = box(HEAP) 5; +/// let foo: Box = 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")] diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 60aebd9cd4226..cc69d0789f82b 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -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) | diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index f7bfb6e8a4018..c6ff38d0f093d 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -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, diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index a8eb109398a78..9a5b21be72892 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -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"); - } } } } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index b7572d43fbe25..85e51512bca31 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -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; diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 9bb19bb37d8e4..37057f3c17e59 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -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) => { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index c26982ff5ede1..c76cc18395f1c 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -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) } diff --git a/src/librustc_front/fold.rs b/src/librustc_front/fold.rs index 8ef0b5e6648b9..c2ce7cd701d03 100644 --- a/src/librustc_front/fold.rs +++ b/src/librustc_front/fold.rs @@ -1040,8 +1040,8 @@ pub fn noop_fold_expr(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))) diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index 4dfb80cce6da6..0775678930792 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -491,8 +491,6 @@ pub type BinOp = Spanned; #[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), + /// A `box x` expression. + ExprBox(P), /// An array (`[a, b, c, d]`) ExprVec(Vec>), /// A function call diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 4888ff93c997b..4b11e8b91e898 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -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 { 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 { ExprParen(ref ex) => { return lower_expr(ex); } + ExprInPlace(..) | ExprIfLet(..) | ExprWhileLet(..) | ExprForLoop(..) | diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index 6f2ef8e8cbc48..e9508009d9d0c 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -1182,16 +1182,6 @@ impl<'a> State<'a> { Ok(()) } - fn print_expr_box(&mut self, - place: &Option>, - 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]) -> 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[..])); diff --git a/src/librustc_front/util.rs b/src/librustc_front/util.rs index 00abb14d40ff8..4d1a34621d0ef 100644 --- a/src/librustc_front/util.rs +++ b/src/librustc_front/util.rs @@ -128,10 +128,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 => "-", } } diff --git a/src/librustc_front/visit.rs b/src/librustc_front/visit.rs index f2a756ed39021..1453b1b1bc259 100644 --- a/src/librustc_front/visit.rs +++ b/src/librustc_front/visit.rs @@ -722,8 +722,7 @@ pub fn walk_exprs<'v, V: Visitor<'v>>(visitor: &mut V, expressions: &'v [P 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) => { diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 6df32f53d8130..f9f3e3a430811 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -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 } diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index d03028ffea675..0f0303525e37a 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -67,7 +67,7 @@ impl Builder { 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()); diff --git a/src/librustc_mir/hair.rs b/src/librustc_mir/hair.rs index f1450522dd83e..823958fdab40d 100644 --- a/src/librustc_mir/hair.rs +++ b/src/librustc_mir/hair.rs @@ -171,7 +171,7 @@ pub struct Expr { #[derive(Clone, Debug)] pub enum ExprKind { Scope { extent: H::CodeExtent, value: ExprRef }, - Box { place: Option>, value: ExprRef }, + Box { value: ExprRef }, Call { fun: ExprRef, args: Vec> }, Deref { arg: ExprRef }, // NOT overloaded! Binary { op: BinOp, lhs: ExprRef, rhs: ExprRef }, // NOT overloaded! diff --git a/src/librustc_mir/tcx/expr.rs b/src/librustc_mir/tcx/expr.rs index 78f23fcd71ceb..94e8b57a5879e 100644 --- a/src/librustc_mir/tcx/expr.rs +++ b/src/librustc_mir/tcx/expr.rs @@ -140,11 +140,6 @@ impl<'a,'tcx:'a> Mirror> 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> 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> 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) => diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index ccf602126eb2c..f8b8c41a034e6 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -564,10 +564,10 @@ 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::UnNot => llvm::LLVMConstNot(te), - hir::UnNeg if is_float => llvm::LLVMConstFNeg(te), - hir::UnNeg => llvm::LLVMConstNeg(te), + 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), } } }, hir::ExprField(ref base, field) => { diff --git a/src/librustc_trans/trans/debuginfo/create_scope_map.rs b/src/librustc_trans/trans/debuginfo/create_scope_map.rs index 828086800499a..313ff7cd37d60 100644 --- a/src/librustc_trans/trans/debuginfo/create_scope_map.rs +++ b/src/librustc_trans/trans/debuginfo/create_scope_map.rs @@ -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); } diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index f2dcf84d41920..35686ebaa9689 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -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` 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` 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 - } - } } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 47ddbfdb8cc3c..dec2e49272b48 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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 - } - } - _ => {} - }); - - if !checked { - span_err!(tcx.sess, expr.span, E0066, - "only the exchange heap is currently supported"); - fcx.write_ty(id, tcx.types.err); - } + 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 + } + }); + 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 - } - }, - hir::UnNot | hir::UnNeg => { - expected - } - hir::UnDeref => { - 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) { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 62eb6022d0c22..db7d77e5454c2 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -680,8 +680,6 @@ pub type BinOp = Spanned; #[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), /// First expr is the place; second expr is the value. - ExprBox(Option>, P), + ExprInPlace(P, P), /// An array (`[a, b, c, d]`) ExprVec(Vec>), /// A function call diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index d024ff117f579..545c69cafffed 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -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 => "-", } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 6e0fbbec770c6..e14e48c022d1a 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -94,8 +94,8 @@ pub fn expand_expr(e: P, fld: &mut MacroExpander) -> P { }) } - // 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; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index be95b58bf881e..eaf964a3c64f1 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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; \ diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index e97c763ca4cdc..914b08265feeb 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1188,8 +1188,11 @@ pub fn noop_fold_expr(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))) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6220bd6fa6fb1..60e0f2d32a43d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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 () ` to \ - `in { }`)"); - - // 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() } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index df72645f97d9b..6d3f036894f36 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1811,13 +1811,12 @@ impl<'a> State<'a> { Ok(()) } - fn print_expr_box(&mut self, - place: &Option>, - 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[..])); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index f4f4c9dfc24fb..23c02905cf728 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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) => { diff --git a/src/test/auxiliary/issue-2380.rs b/src/test/auxiliary/issue-2380.rs index 96f33f97a6969..cfebc4abaaa61 100644 --- a/src/test/auxiliary/issue-2380.rs +++ b/src/test/auxiliary/issue-2380.rs @@ -22,5 +22,5 @@ pub trait i pub fn f() -> Box+'static> { impl i for () { } - box() () as Box+'static> + box () as Box+'static> } diff --git a/src/test/compile-fail/borrowck-lend-flow-if.rs b/src/test/compile-fail/borrowck-lend-flow-if.rs index a0a6e54e942b0..a6ce36a5507f2 100644 --- a/src/test/compile-fail/borrowck-lend-flow-if.rs +++ b/src/test/compile-fail/borrowck-lend-flow-if.rs @@ -23,8 +23,7 @@ fn for_func(_f: F) where F: FnOnce() -> bool { panic!() } fn produce() -> T { panic!(); } fn inc(v: &mut Box) { - *v = box() (**v + 1); - //~^ WARN deprecated syntax + *v = box (**v + 1); } fn pre_freeze_cond() { diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index 9356eeda60503..f09e7ffd7e4b7 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -22,8 +22,7 @@ fn cond() -> bool { panic!() } fn produce() -> T { panic!(); } fn inc(v: &mut Box) { - *v = box() (**v + 1); - //~^ WARN deprecated syntax + *v = box (**v + 1); } fn loop_overarching_alias_mut() { diff --git a/src/test/compile-fail/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck-lend-flow.rs index c3dcddf858724..1ed779cfaac71 100644 --- a/src/test/compile-fail/borrowck-lend-flow.rs +++ b/src/test/compile-fail/borrowck-lend-flow.rs @@ -23,8 +23,7 @@ fn for_func(_f: F) where F: FnOnce() -> bool { panic!() } fn produce() -> T { panic!(); } fn inc(v: &mut Box) { - *v = box() (**v + 1); - //~^ WARN deprecated syntax + *v = box (**v + 1); } fn pre_freeze() { diff --git a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs index 558475c28d701..a9079cfc27d83 100644 --- a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs @@ -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)) } } diff --git a/src/test/compile-fail/feature-gate-box-expr.rs b/src/test/compile-fail/feature-gate-box-expr.rs index ace1b39966289..f1bb5c0dea21d 100644 --- a/src/test/compile-fail/feature-gate-box-expr.rs +++ b/src/test/compile-fail/feature-gate-box-expr.rs @@ -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); } diff --git a/src/test/compile-fail/feature-gate-placement-expr.rs b/src/test/compile-fail/feature-gate-placement-expr.rs index 7c75605d57d32..47a25bf637c5f 100644 --- a/src/test/compile-fail/feature-gate-placement-expr.rs +++ b/src/test/compile-fail/feature-gate-placement-expr.rs @@ -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); } diff --git a/src/test/compile-fail/issue-14084.rs b/src/test/compile-fail/issue-14084.rs index b33a6767274ea..b2863202ef0cf 100644 --- a/src/test/compile-fail/issue-14084.rs +++ b/src/test/compile-fail/issue-14084.rs @@ -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 } diff --git a/src/test/compile-fail/moves-based-on-type-tuple.rs b/src/test/compile-fail/moves-based-on-type-tuple.rs index e1d462d170002..a4d3e3ee02f57 100644 --- a/src/test/compile-fail/moves-based-on-type-tuple.rs +++ b/src/test/compile-fail/moves-based-on-type-tuple.rs @@ -11,8 +11,7 @@ #![feature(box_syntax)] fn dup(x: Box) -> Box<(Box,Box)> { - box() (x, x) //~ ERROR use of moved value - //~^ WARN deprecated syntax + box (x, x) //~ ERROR use of moved value } fn main() { dup(box 3); diff --git a/src/test/debuginfo/borrowed-tuple.rs b/src/test/debuginfo/borrowed-tuple.rs index 2438879dfb670..e3da3934f6d69 100644 --- a/src/test/debuginfo/borrowed-tuple.rs +++ b/src/test/debuginfo/borrowed-tuple.rs @@ -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 diff --git a/src/test/debuginfo/box.rs b/src/test/debuginfo/box.rs index a731e041d79da..106d0b243eb26 100644 --- a/src/test/debuginfo/box.rs +++ b/src/test/debuginfo/box.rs @@ -37,7 +37,7 @@ fn main() { let a = box 1; - let b = box() (2, 3.5f64); + let b = box (2, 3.5f64); zzz(); // #break } diff --git a/src/test/debuginfo/destructured-fn-argument.rs b/src/test/debuginfo/destructured-fn-argument.rs index a3a48b786163b..954a7abe6323c 100644 --- a/src/test/debuginfo/destructured-fn-argument.rs +++ b/src/test/debuginfo/destructured-fn-argument.rs @@ -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 }); diff --git a/src/test/debuginfo/destructured-local.rs b/src/test/debuginfo/destructured-local.rs index a73b5c8de11a1..a43e4546d4f8f 100644 --- a/src/test/debuginfo/destructured-local.rs +++ b/src/test/debuginfo/destructured-local.rs @@ -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); diff --git a/src/test/parse-fail/parenthesized-box-expr-message.rs b/src/test/parse-fail/parenthesized-box-expr-message.rs deleted file mode 100644 index 3cf3685d5bd04..0000000000000 --- a/src/test/parse-fail/parenthesized-box-expr-message.rs +++ /dev/null @@ -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 or the MIT license -// , 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 `;` -} diff --git a/src/test/run-pass/autoderef-method-on-trait.rs b/src/test/run-pass/autoderef-method-on-trait.rs index 40acb6eb9fe81..5c5364de6a86b 100644 --- a/src/test/run-pass/autoderef-method-on-trait.rs +++ b/src/test/run-pass/autoderef-method-on-trait.rs @@ -21,6 +21,6 @@ impl double for usize { } pub fn main() { - let x: Box<_> = box() (box 3usize as Box); + let x: Box<_> = box (box 3usize as Box); assert_eq!(x.double(), 6); } diff --git a/src/test/run-pass/crate-method-reexport-grrrrrrr.rs b/src/test/run-pass/crate-method-reexport-grrrrrrr.rs index 43507f0cb00bd..028b3f43e2ae8 100644 --- a/src/test/run-pass/crate-method-reexport-grrrrrrr.rs +++ b/src/test/run-pass/crate-method-reexport-grrrrrrr.rs @@ -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()); diff --git a/src/test/run-pass/issue-10767.rs b/src/test/run-pass/issue-10767.rs index 9d680d1962f8f..b5ef6020b57d0 100644 --- a/src/test/run-pass/issue-10767.rs +++ b/src/test/run-pass/issue-10767.rs @@ -16,5 +16,5 @@ pub fn main() { fn f() { }; - let _: Box = box() (f as fn()); + let _: Box = box (f as fn()); } diff --git a/src/test/run-pass/issue-2935.rs b/src/test/run-pass/issue-2935.rs index fd8e1e6b036ba..511344a792f46 100644 --- a/src/test/run-pass/issue-2935.rs +++ b/src/test/run-pass/issue-2935.rs @@ -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); + let z: Box<_> = box (box true as Box); // x.f(); // y.f(); // (*z).f(); diff --git a/src/test/run-pass/new-box-syntax.rs b/src/test/run-pass/new-box-syntax.rs index da57e8682ca60..34687c6ca1de3 100644 --- a/src/test/run-pass/new-box-syntax.rs +++ b/src/test/run-pass/new-box-syntax.rs @@ -31,10 +31,10 @@ struct Structure { } pub fn main() { - let x: Box = box(HEAP) 2; + let x: Box = in HEAP { 2 }; let y: Box = box 2; - let b: Box = box()(1 + 2); - let c = box()(3 + 4); + let b: Box = box (1 + 2); + let c = box (3 + 4); let s: Box = box Structure { x: 3, diff --git a/src/test/run-pass/regions-early-bound-trait-param.rs b/src/test/run-pass/regions-early-bound-trait-param.rs index 72a214f4c9ad0..4ba04aa7091a8 100644 --- a/src/test/run-pass/regions-early-bound-trait-param.rs +++ b/src/test/run-pass/regions-early-bound-trait-param.rs @@ -83,7 +83,7 @@ impl<'s> Trait<'s> for (isize,isize) { impl<'t> MakerTrait for Box+'static> { fn mk() -> Box+'static> { - let tup: Box<(isize, isize)> = box() (4,5); + let tup: Box<(isize, isize)> = box (4,5); tup as Box } } diff --git a/src/test/run-pass/trait-object-generics.rs b/src/test/run-pass/trait-object-generics.rs index 15a8a2e83e340..33bee3ea06f4d 100644 --- a/src/test/run-pass/trait-object-generics.rs +++ b/src/test/run-pass/trait-object-generics.rs @@ -49,6 +49,6 @@ impl Trait for () { } pub fn main() { - let a = box() () as Box>; + let a = box () as Box>; assert_eq!(a.method(Type::Constant((1, 2))), 0); }