Skip to content

Commit a02885e

Browse files
committed
rollup merge of rust-lang#19918: pnkfelix/ast-refactor-make-place-in-exprbox-an-option
This is to allow us to migrate away from UnUniq in a followup commit, and thus unify the code paths related to all forms of `box`.
2 parents b496ada + 7d4e7f0 commit a02885e

File tree

11 files changed

+35
-25
lines changed

11 files changed

+35
-25
lines changed

src/librustc/middle/cfg/construct.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,15 +462,13 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
462462
self.straightline(expr, pred, [r, l].iter().map(|&e| &**e))
463463
}
464464

465+
ast::ExprBox(Some(ref l), ref r) |
465466
ast::ExprIndex(ref l, ref r) |
466467
ast::ExprBinary(_, ref l, ref r) => { // NB: && and || handled earlier
467468
self.straightline(expr, pred, [l, r].iter().map(|&e| &**e))
468469
}
469470

470-
ast::ExprBox(ref p, ref e) => {
471-
self.straightline(expr, pred, [p, e].iter().map(|&e| &**e))
472-
}
473-
471+
ast::ExprBox(None, ref e) |
474472
ast::ExprAddrOf(_, ref e) |
475473
ast::ExprCast(ref e, _) |
476474
ast::ExprUnary(_, ref e) |

src/librustc/middle/expr_use_visitor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,10 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
631631
}
632632

633633
ast::ExprBox(ref place, ref base) => {
634-
self.consume_expr(&**place);
634+
match *place {
635+
Some(ref place) => self.consume_expr(&**place),
636+
None => {}
637+
}
635638
self.consume_expr(&**base);
636639
}
637640

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11991199

12001200
ast::ExprIndex(ref l, ref r) |
12011201
ast::ExprBinary(_, ref l, ref r) |
1202-
ast::ExprBox(ref l, ref r) => {
1202+
ast::ExprBox(Some(ref l), ref r) => {
12031203
let r_succ = self.propagate_through_expr(&**r, succ);
12041204
self.propagate_through_expr(&**l, r_succ)
12051205
}
@@ -1210,6 +1210,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
12101210
self.propagate_through_expr(&**e1, succ)
12111211
}
12121212

1213+
ast::ExprBox(None, ref e) |
12131214
ast::ExprAddrOf(_, ref e) |
12141215
ast::ExprCast(ref e, _) |
12151216
ast::ExprUnary(_, ref e) |

src/librustc/middle/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4320,12 +4320,13 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
43204320

43214321
ast::ExprLit(_) | // Note: LitStr is carved out above
43224322
ast::ExprUnary(..) |
4323+
ast::ExprBox(None, _) |
43234324
ast::ExprAddrOf(..) |
43244325
ast::ExprBinary(..) => {
43254326
RvalueDatumExpr
43264327
}
43274328

4328-
ast::ExprBox(ref place, _) => {
4329+
ast::ExprBox(Some(ref place), _) => {
43294330
// Special case `Box<T>` for now:
43304331
let definition = match tcx.def_map.borrow().get(&place.id) {
43314332
Some(&def) => def,

src/librustc_trans/trans/debuginfo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3472,7 +3472,8 @@ fn populate_scope_map(cx: &CrateContext,
34723472
walk_expr(cx, &**sub_exp, scope_stack, scope_map),
34733473

34743474
ast::ExprBox(ref place, ref sub_expr) => {
3475-
walk_expr(cx, &**place, scope_stack, scope_map);
3475+
place.as_ref().map(
3476+
|e| walk_expr(cx, &**e, scope_stack, scope_map));
34763477
walk_expr(cx, &**sub_expr, scope_stack, scope_map);
34773478
}
34783479

src/librustc_typeck/check/mod.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,22 +3662,25 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
36623662
let tcx = fcx.ccx.tcx;
36633663
let id = expr.id;
36643664
match expr.node {
3665-
ast::ExprBox(ref place, ref subexpr) => {
3666-
check_expr(fcx, &**place);
3665+
ast::ExprBox(ref opt_place, ref subexpr) => {
3666+
opt_place.as_ref().map(|place|check_expr(fcx, &**place));
36673667
check_expr(fcx, &**subexpr);
36683668

36693669
let mut checked = false;
3670-
if let ast::ExprPath(ref path) = place.node {
3671-
// FIXME(pcwalton): For now we hardcode the two permissible
3672-
// places: the exchange heap and the managed heap.
3673-
let definition = lookup_def(fcx, path.span, place.id);
3674-
let def_id = definition.def_id();
3675-
let referent_ty = fcx.expr_ty(&**subexpr);
3676-
if tcx.lang_items.exchange_heap() == Some(def_id) {
3677-
fcx.write_ty(id, ty::mk_uniq(tcx, referent_ty));
3678-
checked = true
3670+
opt_place.as_ref().map(|place| match place.node {
3671+
ast::ExprPath(ref path) => {
3672+
// FIXME(pcwalton): For now we hardcode the two permissible
3673+
// places: the exchange heap and the managed heap.
3674+
let definition = lookup_def(fcx, path.span, place.id);
3675+
let def_id = definition.def_id();
3676+
let referent_ty = fcx.expr_ty(&**subexpr);
3677+
if tcx.lang_items.exchange_heap() == Some(def_id) {
3678+
fcx.write_ty(id, ty::mk_uniq(tcx, referent_ty));
3679+
checked = true
3680+
}
36793681
}
3680-
}
3682+
_ => {}
3683+
});
36813684

36823685
if !checked {
36833686
span_err!(tcx.sess, expr.span, E0066,

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ pub struct Expr {
696696
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
697697
pub enum Expr_ {
698698
/// First expr is the place; second expr is the value.
699-
ExprBox(P<Expr>, P<Expr>),
699+
ExprBox(Option<P<Expr>>, P<Expr>),
700700
ExprVec(Vec<P<Expr>>),
701701
ExprCall(P<Expr>, Vec<P<Expr>>),
702702
ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>),

src/libsyntax/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
12821282
id: folder.new_id(id),
12831283
node: match node {
12841284
ExprBox(p, e) => {
1285-
ExprBox(folder.fold_expr(p), folder.fold_expr(e))
1285+
ExprBox(p.map(|e|folder.fold_expr(e)), folder.fold_expr(e))
12861286
}
12871287
ExprVec(exprs) => {
12881288
ExprVec(exprs.move_map(|x| folder.fold_expr(x)))

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2888,14 +2888,17 @@ impl<'a> Parser<'a> {
28882888
}
28892889
let subexpression = self.parse_prefix_expr();
28902890
hi = subexpression.span.hi;
2891-
ex = ExprBox(place, subexpression);
2891+
ex = ExprBox(Some(place), subexpression);
28922892
return self.mk_expr(lo, hi, ex);
28932893
}
28942894
}
28952895

28962896
// Otherwise, we use the unique pointer default.
28972897
let subexpression = self.parse_prefix_expr();
28982898
hi = subexpression.span.hi;
2899+
// FIXME (pnkfelix): After working out kinks with box
2900+
// desugaring, should be `ExprBox(None, subexpression)`
2901+
// instead.
28992902
ex = self.mk_unary(UnUniq, subexpression);
29002903
}
29012904
_ => return self.parse_dot_or_call_expr()

src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ impl<'a> State<'a> {
15011501
ast::ExprBox(ref p, ref e) => {
15021502
try!(word(&mut self.s, "box"));
15031503
try!(word(&mut self.s, "("));
1504-
try!(self.print_expr(&**p));
1504+
try!(p.as_ref().map_or(Ok(()), |e|self.print_expr(&**e)));
15051505
try!(self.word_space(")"));
15061506
try!(self.print_expr(&**e));
15071507
}

src/libsyntax/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) {
742742
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
743743
match expression.node {
744744
ExprBox(ref place, ref subexpression) => {
745-
visitor.visit_expr(&**place);
745+
place.as_ref().map(|e|visitor.visit_expr(&**e));
746746
visitor.visit_expr(&**subexpression)
747747
}
748748
ExprVec(ref subexpressions) => {

0 commit comments

Comments
 (0)