Skip to content

Commit

Permalink
Removing support for the do syntax from libsyntax and librustc.
Browse files Browse the repository at this point in the history
Fixes #10815.
  • Loading branch information
bytbox committed Jan 29, 2014
1 parent 221670b commit a6867e2
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 212 deletions.
1 change: 0 additions & 1 deletion src/librustc/middle/cfg/construct.rs
Expand Up @@ -398,7 +398,6 @@ impl CFGBuilder {
}

ast::ExprAddrOf(_, e) |
ast::ExprDoBody(e) |
ast::ExprCast(e, _) |
ast::ExprUnary(_, _, e) |
ast::ExprParen(e) |
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/dataflow.rs
Expand Up @@ -706,7 +706,6 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
ast::ExprPath(..) => {}

ast::ExprAddrOf(_, e) |
ast::ExprDoBody(e) |
ast::ExprCast(e, _) |
ast::ExprUnary(_, _, e) |
ast::ExprParen(e) |
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/liveness.rs
Expand Up @@ -538,7 +538,7 @@ fn visit_expr(v: &mut LivenessVisitor, expr: &Expr, this: @IrMaps) {
ExprIndex(..) | ExprField(..) | ExprVstore(..) | ExprVec(..) |
ExprCall(..) | ExprMethodCall(..) | ExprTup(..) | ExprLogLevel |
ExprBinary(..) | ExprAddrOf(..) |
ExprDoBody(..) | ExprCast(..) | ExprUnary(..) | ExprBreak(_) |
ExprCast(..) | ExprUnary(..) | ExprBreak(_) |
ExprAgain(_) | ExprLit(_) | ExprRet(..) | ExprBlock(..) |
ExprAssign(..) | ExprAssignOp(..) | ExprMac(..) |
ExprStruct(..) | ExprRepeat(..) | ExprParen(..) |
Expand Down Expand Up @@ -1245,7 +1245,6 @@ impl Liveness {
}

ExprAddrOf(_, e) |
ExprDoBody(e) |
ExprCast(e, _) |
ExprUnary(_, _, e) |
ExprParen(e) => {
Expand Down Expand Up @@ -1529,7 +1528,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
ExprCall(..) | ExprMethodCall(..) | ExprIf(..) | ExprMatch(..) |
ExprWhile(..) | ExprLoop(..) | ExprIndex(..) | ExprField(..) |
ExprVstore(..) | ExprVec(..) | ExprTup(..) | ExprLogLevel |
ExprBinary(..) | ExprDoBody(..) |
ExprBinary(..) |
ExprCast(..) | ExprUnary(..) | ExprRet(..) | ExprBreak(..) |
ExprAgain(..) | ExprLit(_) | ExprBlock(..) |
ExprMac(..) | ExprAddrOf(..) | ExprStruct(..) | ExprRepeat(..) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -436,7 +436,7 @@ impl mem_categorization_ctxt {
ast::ExprAddrOf(..) | ast::ExprCall(..) |
ast::ExprAssign(..) | ast::ExprAssignOp(..) |
ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprRet(..) |
ast::ExprDoBody(..) | ast::ExprUnary(..) |
ast::ExprUnary(..) |
ast::ExprMethodCall(..) | ast::ExprCast(..) | ast::ExprVstore(..) |
ast::ExprVec(..) | ast::ExprTup(..) | ast::ExprIf(..) |
ast::ExprLogLevel | ast::ExprBinary(..) | ast::ExprWhile(..) |
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/middle/moves.rs
Expand Up @@ -570,10 +570,6 @@ impl VisitContext {
self.consume_expr(count);
}

ExprDoBody(base) => {
self.use_expr(base, comp_mode);
}

ExprFnBlock(ref decl, body) |
ExprProc(ref decl, body) => {
for a in decl.inputs.iter() {
Expand Down
14 changes: 0 additions & 14 deletions src/librustc/middle/trans/debuginfo.rs
Expand Up @@ -2655,20 +2655,6 @@ fn populate_scope_map(cx: &CrateContext,
})
}

ast::ExprDoBody(inner_exp) => {
let inner_expr_is_expr_fn_block = match *inner_exp {
ast::Expr { node: ast::ExprFnBlock(..), .. } => true,
_ => false
};

if !inner_expr_is_expr_fn_block {
cx.sess.span_bug(inner_exp.span, "debuginfo: Inner expression was expected \
to be an ast::expr_fn_block.");
}

walk_expr(cx, inner_exp, scope_stack, scope_map);
}

ast::ExprCall(fn_exp, ref args, _) => {
walk_expr(cx, fn_exp, scope_stack, scope_map);

Expand Down
3 changes: 0 additions & 3 deletions src/librustc/middle/trans/expr.rs
Expand Up @@ -867,9 +867,6 @@ fn trans_rvalue_dps_unadjusted<'a>(bcx: &'a Block<'a>,
closure::trans_expr_fn(bcx, sigil, decl, body,
expr.id, expr.id, dest)
}
ast::ExprDoBody(blk) => {
trans_into(bcx, blk, dest)
}
ast::ExprCall(f, ref args, _) => {
callee::trans_call(bcx, expr, f,
callee::ArgExprs(*args), expr.id, dest)
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/ty.rs
Expand Up @@ -3166,7 +3166,6 @@ pub fn expr_kind(tcx: ctxt,
ast::ExprMatch(..) |
ast::ExprFnBlock(..) |
ast::ExprProc(..) |
ast::ExprDoBody(..) |
ast::ExprBlock(..) |
ast::ExprRepeat(..) |
ast::ExprVstore(_, ast::ExprVstoreSlice) |
Expand Down
43 changes: 1 addition & 42 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -1640,8 +1640,6 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
} else {
let suffix = match sugar {
ast::NoSugar => "",
ast::DoSugar => " (including the closure passed by \
the `do` keyword)",
ast::ForSugar => " (including the closure passed by \
the `for` keyword)"
};
Expand Down Expand Up @@ -1690,8 +1688,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
for (i, arg) in args.iter().take(t).enumerate() {
let is_block = match arg.node {
ast::ExprFnBlock(..) |
ast::ExprProc(..) |
ast::ExprDoBody(..) => true,
ast::ExprProc(..) => true,
_ => false
};

Expand Down Expand Up @@ -2928,44 +2925,6 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
Vanilla,
expected);
}
ast::ExprDoBody(b) => {
let expected_sty = unpack_expected(fcx,
expected,
|x| Some((*x).clone()));
let inner_ty = match expected_sty {
Some(ty::ty_closure(ref closure_ty))
if closure_ty.sigil == ast::OwnedSigil => {
expected.unwrap()
}
_ => match expected {
Some(expected_t) => {
fcx.type_error_message(expr.span, |actual| {
format!("last argument in `do` call \
has non-procedure type: {}",
actual)
}, expected_t, None);
let err_ty = ty::mk_err();
fcx.write_ty(id, err_ty);
err_ty
}
None => {
fcx.tcx().sess.impossible_case(
expr.span,
"do body must have expected type")
}
}
};
match b.node {
ast::ExprFnBlock(decl, body) => {
check_expr_fn(fcx, b, None,
decl, body, DoBlock, Some(inner_ty));
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
}
// argh
_ => fail!("expected fn ty")
}
fcx.write_ty(expr.id, fcx.node_ty(b.id));
}
ast::ExprBlock(b) => {
check_block_with_expected(fcx, b, expected);
fcx.write_ty(id, fcx.node_ty(b.id));
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/typeck/check/regionck.rs
Expand Up @@ -1045,7 +1045,6 @@ pub mod guarantor {
ast::ExprMatch(..) |
ast::ExprFnBlock(..) |
ast::ExprProc(..) |
ast::ExprDoBody(..) |
ast::ExprBlock(..) |
ast::ExprRepeat(..) |
ast::ExprVec(..) => {
Expand Down
2 changes: 0 additions & 2 deletions src/libsyntax/ast.rs
Expand Up @@ -539,7 +539,6 @@ impl Expr {
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum CallSugar {
NoSugar,
DoSugar,
ForSugar
}

Expand All @@ -566,7 +565,6 @@ pub enum Expr_ {
ExprMatch(@Expr, ~[Arm]),
ExprFnBlock(P<FnDecl>, P<Block>),
ExprProc(P<FnDecl>, P<Block>),
ExprDoBody(@Expr),
ExprBlock(P<Block>),

ExprAssign(@Expr, @Expr),
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/fold.rs
Expand Up @@ -752,7 +752,6 @@ pub fn noop_fold_expr<T: Folder>(e: @Expr, folder: &mut T) -> @Expr {
ExprUnary(callee_id, binop, ohs) => {
ExprUnary(folder.new_id(callee_id), binop, folder.fold_expr(ohs))
}
ExprDoBody(f) => ExprDoBody(folder.fold_expr(f)),
ExprLit(_) => e.node.clone(),
ExprCast(expr, ty) => {
ExprCast(folder.fold_expr(expr), folder.fold_ty(ty))
Expand Down
2 changes: 0 additions & 2 deletions src/libsyntax/parse/classify.rs
Expand Up @@ -29,9 +29,7 @@ pub fn expr_requires_semi_to_be_stmt(e: @ast::Expr) -> bool {
| ast::ExprWhile(..)
| ast::ExprLoop(..)
| ast::ExprForLoop(..)
| ast::ExprCall(_, _, ast::DoSugar)
| ast::ExprCall(_, _, ast::ForSugar)
| ast::ExprMethodCall(_, _, _, _, ast::DoSugar)
| ast::ExprMethodCall(_, _, _, _, ast::ForSugar) => false,
_ => true
}
Expand Down
76 changes: 2 additions & 74 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -13,7 +13,7 @@
use abi;
use abi::AbiSet;
use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil};
use ast::{CallSugar, NoSugar, DoSugar};
use ast::{CallSugar, NoSugar};
use ast::{BareFnTy, ClosureTy};
use ast::{RegionTyParamBound, TraitTyParamBound};
use ast::{Provided, Public, Purity};
Expand All @@ -24,7 +24,7 @@ use ast::{Crate, CrateConfig, Decl, DeclItem};
use ast::{DeclLocal, DefaultBlock, 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, ExprDoBody};
use ast::{ExprBreak, ExprCall, ExprCast};
use ast::{ExprField, ExprFnBlock, ExprIf, ExprIndex};
use ast::{ExprLit, ExprLogLevel, ExprLoop, ExprMac};
use ast::{ExprMethodCall, ExprParen, ExprPath, ExprProc};
Expand Down Expand Up @@ -1796,9 +1796,6 @@ impl Parser {
return self.parse_if_expr();
} else if self.eat_keyword(keywords::For) {
return self.parse_for_expr(None);
} else if self.eat_keyword(keywords::Do) {
return self.parse_sugary_call_expr(lo, ~"do", DoSugar,
ExprDoBody);
} else if self.eat_keyword(keywords::While) {
return self.parse_while_expr();
} else if Parser::token_is_lifetime(&self.token) {
Expand Down Expand Up @@ -2541,75 +2538,6 @@ impl Parser {
self.mk_expr(lo, hi, ExprForLoop(pat, expr, loop_block, opt_ident))
}


// parse a 'do'.
// the 'do' expression parses as a call, but looks like
// a function call followed by a closure expression.
pub fn parse_sugary_call_expr(&mut self,
lo: BytePos,
keyword: ~str,
sugar: CallSugar,
ctor: |v: @Expr| -> Expr_)
-> @Expr {
// Parse the callee `foo` in
// do foo || {
// do foo.bar || {
// etc, or the portion of the call expression before the lambda in
// do foo() || {
// or
// do foo.bar(a) || {
// Turn on the restriction to stop at | or || so we can parse
// them as the lambda arguments
let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP);
match e.node {
ExprCall(f, ref args, NoSugar) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
let args = vec::append_one((*args).clone(), last_arg);
self.mk_expr(lo, block.span.hi, ExprCall(f, args, sugar))
}
ExprMethodCall(_, i, ref tps, ref args, NoSugar) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
let args = vec::append_one((*args).clone(), last_arg);
let method_call = self.mk_method_call(i,
(*tps).clone(),
args,
sugar);
self.mk_expr(lo, block.span.hi, method_call)
}
ExprField(f, i, ref tps) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
let method_call = self.mk_method_call(i,
(*tps).clone(),
~[f, last_arg],
sugar);
self.mk_expr(lo, block.span.hi, method_call)
}
ExprPath(..) | ExprCall(..) | ExprMethodCall(..) |
ExprParen(..) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
let call = self.mk_call(e, ~[last_arg], sugar);
self.mk_expr(lo, last_arg.span.hi, call)
}
_ => {
// There may be other types of expressions that can
// represent the callee in `do` expressions
// but they aren't represented by tests
debug!("sugary call on {:?}", e.node);
self.span_fatal(
e.span,
format!("`{}` must be followed by a block call", keyword));
}
}
}

pub fn parse_while_expr(&mut self) -> @Expr {
let lo = self.last_span.lo;
let cond = self.parse_expr();
Expand Down

5 comments on commit a6867e2

@bors
Copy link
Contributor

@bors bors commented on a6867e2 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at bytbox@a6867e2

@bors
Copy link
Contributor

@bors bors commented on a6867e2 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bytbox/rust/remove-do = a6867e2 into auto

@bors
Copy link
Contributor

@bors bors commented on a6867e2 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytbox/rust/remove-do = a6867e2 merged ok, testing candidate = e1580f6

@bors
Copy link
Contributor

@bors bors commented on a6867e2 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a6867e2 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e1580f6

Please sign in to comment.