1
Fork 0

Remove field expr of ast::Block

This commit is contained in:
Jeffrey Seyfried 2016-06-23 09:51:18 +00:00
parent 4960f2f907
commit b7da35a5aa
19 changed files with 87 additions and 119 deletions

View file

@ -587,10 +587,23 @@ impl<'a> LoweringContext<'a> {
} }
fn lower_block(&mut self, b: &Block) -> P<hir::Block> { fn lower_block(&mut self, b: &Block) -> P<hir::Block> {
let mut stmts = Vec::new();
let mut expr = None;
if let Some((last, rest)) = b.stmts.split_last() {
stmts = rest.iter().map(|s| self.lower_stmt(s)).collect::<Vec<_>>();
let last = self.lower_stmt(last);
if let hir::StmtExpr(e, _) = last.node {
expr = Some(e);
} else {
stmts.push(last);
}
}
P(hir::Block { P(hir::Block {
id: b.id, id: b.id,
stmts: b.stmts.iter().map(|s| self.lower_stmt(s)).collect(), stmts: stmts.into(),
expr: b.expr.as_ref().map(|ref x| self.lower_expr(x)), expr: expr,
rules: self.lower_block_check_mode(&b.rules), rules: self.lower_block_check_mode(&b.rules),
span: b.span, span: b.span,
}) })

View file

@ -657,8 +657,10 @@ impl fold::Folder for ReplaceBodyWithLoop {
fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> { fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> {
fn expr_to_block(rules: ast::BlockCheckMode, e: Option<P<ast::Expr>>) -> P<ast::Block> { fn expr_to_block(rules: ast::BlockCheckMode, e: Option<P<ast::Expr>>) -> P<ast::Block> {
P(ast::Block { P(ast::Block {
expr: e, stmts: e.map(|e| codemap::Spanned {
stmts: vec![], span: e.span,
node: ast::StmtKind::Expr(e, ast::DUMMY_NODE_ID),
}).into_iter().collect(),
rules: rules, rules: rules,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: codemap::DUMMY_SP, span: codemap::DUMMY_SP,

View file

@ -528,9 +528,6 @@ impl PartialEq for MetaItemKind {
pub struct Block { pub struct Block {
/// Statements in a block /// Statements in a block
pub stmts: Vec<Stmt>, pub stmts: Vec<Stmt>,
/// An expression at the end of the block
/// without a semicolon, if any
pub expr: Option<P<Expr>>,
pub id: NodeId, pub id: NodeId,
/// Distinguishes between `unsafe { ... }` and `{ ... }` /// Distinguishes between `unsafe { ... }` and `{ ... }`
pub rules: BlockCheckMode, pub rules: BlockCheckMode,
@ -803,7 +800,7 @@ pub enum StmtKind {
/// Could be an item or a local (let) binding: /// Could be an item or a local (let) binding:
Decl(P<Decl>, NodeId), Decl(P<Decl>, NodeId),
/// Expr without trailing semi-colon (must have unit type): /// Expr without trailing semi-colon
Expr(P<Expr>, NodeId), Expr(P<Expr>, NodeId),
/// Expr with trailing semi-colon (may have any type): /// Expr with trailing semi-colon (may have any type):

View file

@ -98,12 +98,9 @@ pub trait AstBuilder {
fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt; fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt;
// blocks // blocks
fn block(&self, span: Span, stmts: Vec<ast::Stmt>, fn block(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block>;
expr: Option<P<ast::Expr>>) -> P<ast::Block>;
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block>; fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block>;
fn block_all(&self, span: Span, fn block_all(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block>;
stmts: Vec<ast::Stmt>,
expr: Option<P<ast::Expr>>) -> P<ast::Block>;
// expressions // expressions
fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr>; fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr>;
@ -508,7 +505,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
} }
fn stmt_expr(&self, expr: P<ast::Expr>) -> ast::Stmt { fn stmt_expr(&self, expr: P<ast::Expr>) -> ast::Stmt {
respan(expr.span, ast::StmtKind::Semi(expr, ast::DUMMY_NODE_ID)) respan(expr.span, ast::StmtKind::Expr(expr, ast::DUMMY_NODE_ID))
} }
fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
@ -556,9 +553,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))) P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID)))
} }
fn block(&self, span: Span, stmts: Vec<ast::Stmt>, fn block(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block> {
expr: Option<P<Expr>>) -> P<ast::Block> { self.block_all(span, stmts)
self.block_all(span, stmts, expr)
} }
fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt { fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt {
@ -567,19 +563,18 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
} }
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> { fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {
self.block_all(expr.span, Vec::new(), Some(expr)) self.block_all(expr.span, vec![Spanned {
span: expr.span,
node: ast::StmtKind::Expr(expr, ast::DUMMY_NODE_ID),
}])
} }
fn block_all(&self, fn block_all(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block> {
span: Span, P(ast::Block {
stmts: Vec<ast::Stmt>, stmts: stmts,
expr: Option<P<ast::Expr>>) -> P<ast::Block> { id: ast::DUMMY_NODE_ID,
P(ast::Block { rules: BlockCheckMode::Default,
stmts: stmts, span: span,
expr: expr, })
id: ast::DUMMY_NODE_ID,
rules: BlockCheckMode::Default,
span: span,
})
} }
fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr> { fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr> {
@ -948,14 +943,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
ids: Vec<ast::Ident>, ids: Vec<ast::Ident>,
stmts: Vec<ast::Stmt>) stmts: Vec<ast::Stmt>)
-> P<ast::Expr> { -> P<ast::Expr> {
self.lambda(span, ids, self.block(span, stmts, None)) self.lambda(span, ids, self.block(span, stmts))
} }
fn lambda_stmts_0(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Expr> { fn lambda_stmts_0(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Expr> {
self.lambda0(span, self.block(span, stmts, None)) self.lambda0(span, self.block(span, stmts))
} }
fn lambda_stmts_1(&self, span: Span, stmts: Vec<ast::Stmt>, fn lambda_stmts_1(&self, span: Span, stmts: Vec<ast::Stmt>,
ident: ast::Ident) -> P<ast::Expr> { ident: ast::Ident) -> P<ast::Expr> {
self.lambda1(span, self.block(span, stmts, None), ident) self.lambda1(span, self.block(span, stmts), ident)
} }
fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Arg { fn arg(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Arg {

View file

@ -636,23 +636,14 @@ pub fn expand_block(blk: P<Block>, fld: &mut MacroExpander) -> P<Block> {
// expand the elements of a block. // expand the elements of a block.
pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> { pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
b.map(|Block {id, stmts, expr, rules, span}| { b.map(|Block {id, stmts, rules, span}| {
let new_stmts = stmts.into_iter().flat_map(|x| { let new_stmts = stmts.into_iter().flat_map(|x| {
// perform pending renames and expand macros in the statement // perform pending renames and expand macros in the statement
fld.fold_stmt(x).into_iter() fld.fold_stmt(x).into_iter()
}).collect(); }).collect();
let new_expr = expr.map(|x| {
let expr = {
let pending_renames = &mut fld.cx.syntax_env.info().pending_renames;
let mut rename_fld = IdentRenamer{renames:pending_renames};
rename_fld.fold_expr(x)
};
fld.fold_expr(expr)
});
Block { Block {
id: fld.new_id(id), id: fld.new_id(id),
stmts: new_stmts, stmts: new_stmts,
expr: new_expr,
rules: rules, rules: rules,
span: span span: span
} }

View file

@ -512,10 +512,8 @@ pub fn expand_quote_matcher(cx: &mut ExtCtxt,
let (cx_expr, tts) = parse_arguments_to_quote(cx, tts); let (cx_expr, tts) = parse_arguments_to_quote(cx, tts);
let mut vector = mk_stmts_let(cx, sp); let mut vector = mk_stmts_let(cx, sp);
vector.extend(statements_mk_tts(cx, &tts[..], true)); vector.extend(statements_mk_tts(cx, &tts[..], true));
let block = cx.expr_block( vector.push(cx.stmt_expr(cx.expr_ident(sp, id_ext("tt"))));
cx.block_all(sp, let block = cx.expr_block(cx.block_all(sp, vector));
vector,
Some(cx.expr_ident(sp, id_ext("tt")))));
let expanded = expand_wrapper(cx, sp, cx_expr, block, &[&["syntax", "ext", "quote", "rt"]]); let expanded = expand_wrapper(cx, sp, cx_expr, block, &[&["syntax", "ext", "quote", "rt"]]);
base::MacEager::expr(expanded) base::MacEager::expr(expanded)
@ -765,8 +763,9 @@ fn statements_mk_tt(cx: &ExtCtxt, tt: &TokenTree, matcher: bool) -> Vec<ast::Stm
let stmt_let_tt = cx.stmt_let(sp, true, id_ext("tt"), cx.expr_vec_ng(sp)); let stmt_let_tt = cx.stmt_let(sp, true, id_ext("tt"), cx.expr_vec_ng(sp));
let mut tts_stmts = vec![stmt_let_tt]; let mut tts_stmts = vec![stmt_let_tt];
tts_stmts.extend(statements_mk_tts(cx, &seq.tts[..], matcher)); tts_stmts.extend(statements_mk_tts(cx, &seq.tts[..], matcher));
let e_tts = cx.expr_block(cx.block(sp, tts_stmts, tts_stmts.push(cx.stmt_expr(cx.expr_ident(sp, id_ext("tt"))));
Some(cx.expr_ident(sp, id_ext("tt"))))); let e_tts = cx.expr_block(cx.block(sp, tts_stmts));
let e_separator = match seq.separator { let e_separator = match seq.separator {
Some(ref sep) => cx.expr_some(sp, expr_mk_token(cx, sp, sep)), Some(ref sep) => cx.expr_some(sp, expr_mk_token(cx, sp, sep)),
None => cx.expr_none(sp), None => cx.expr_none(sp),
@ -884,10 +883,8 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[TokenTree])
let mut vector = mk_stmts_let(cx, sp); let mut vector = mk_stmts_let(cx, sp);
vector.extend(statements_mk_tts(cx, &tts[..], false)); vector.extend(statements_mk_tts(cx, &tts[..], false));
let block = cx.expr_block( vector.push(cx.stmt_expr(cx.expr_ident(sp, id_ext("tt"))));
cx.block_all(sp, let block = cx.expr_block(cx.block_all(sp, vector));
vector,
Some(cx.expr_ident(sp, id_ext("tt")))));
(cx_expr, block) (cx_expr, block)
} }
@ -901,13 +898,14 @@ fn expand_wrapper(cx: &ExtCtxt,
let cx_expr_borrow = cx.expr_addr_of(sp, cx.expr_deref(sp, cx_expr)); let cx_expr_borrow = cx.expr_addr_of(sp, cx.expr_deref(sp, cx_expr));
let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr_borrow); let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr_borrow);
let stmts = imports.iter().map(|path| { let mut stmts = imports.iter().map(|path| {
// make item: `use ...;` // make item: `use ...;`
let path = path.iter().map(|s| s.to_string()).collect(); let path = path.iter().map(|s| s.to_string()).collect();
cx.stmt_item(sp, cx.item_use_glob(sp, ast::Visibility::Inherited, ids_ext(path))) cx.stmt_item(sp, cx.item_use_glob(sp, ast::Visibility::Inherited, ids_ext(path)))
}).chain(Some(stmt_let_ext_cx)).collect(); }).chain(Some(stmt_let_ext_cx)).collect::<Vec<_>>();
stmts.push(cx.stmt_expr(expr));
cx.expr_block(cx.block_all(sp, stmts, Some(expr))) cx.expr_block(cx.block_all(sp, stmts))
} }
fn expand_parse_call(cx: &ExtCtxt, fn expand_parse_call(cx: &ExtCtxt,

View file

@ -845,10 +845,9 @@ fn noop_fold_bounds<T: Folder>(bounds: TyParamBounds, folder: &mut T)
} }
pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> { pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> {
b.map(|Block {id, stmts, expr, rules, span}| Block { b.map(|Block {id, stmts, rules, span}| Block {
id: folder.new_id(id), id: folder.new_id(id),
stmts: stmts.move_flat_map(|s| folder.fold_stmt(s).into_iter()), stmts: stmts.move_flat_map(|s| folder.fold_stmt(s).into_iter()),
expr: expr.and_then(|x| folder.fold_opt_expr(x)),
rules: rules, rules: rules,
span: folder.new_span(span), span: folder.new_span(span),
}) })

View file

@ -3217,9 +3217,11 @@ impl<'a> Parser<'a> {
let body_expr = self.parse_expr()?; let body_expr = self.parse_expr()?;
P(ast::Block { P(ast::Block {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
stmts: vec![],
span: body_expr.span, span: body_expr.span,
expr: Some(body_expr), stmts: vec![Spanned {
span: body_expr.span,
node: StmtKind::Expr(body_expr, ast::DUMMY_NODE_ID),
}],
rules: BlockCheckMode::Default, rules: BlockCheckMode::Default,
}) })
} }
@ -4082,7 +4084,6 @@ impl<'a> Parser<'a> {
/// Precondition: already parsed the '{'. /// Precondition: already parsed the '{'.
fn parse_block_tail(&mut self, lo: BytePos, s: BlockCheckMode) -> PResult<'a, P<Block>> { fn parse_block_tail(&mut self, lo: BytePos, s: BlockCheckMode) -> PResult<'a, P<Block>> {
let mut stmts = vec![]; let mut stmts = vec![];
let mut expr = None;
while !self.eat(&token::CloseDelim(token::Brace)) { while !self.eat(&token::CloseDelim(token::Brace)) {
let Spanned {node, span} = if let Some(s) = self.parse_stmt_() { let Spanned {node, span} = if let Some(s) = self.parse_stmt_() {
@ -4095,11 +4096,10 @@ impl<'a> Parser<'a> {
}; };
match node { match node {
StmtKind::Expr(e, _) => { StmtKind::Expr(e, _) => {
self.handle_expression_like_statement(e, span, &mut stmts, &mut expr)?; self.handle_expression_like_statement(e, span, &mut stmts)?;
} }
StmtKind::Mac(mac, MacStmtStyle::NoBraces, attrs) => { StmtKind::Mac(mac, MacStmtStyle::NoBraces, attrs) => {
// statement macro without braces; might be an // statement macro without braces
// expr depending on whether a semicolon follows
match self.token { match self.token {
token::Semi => { token::Semi => {
stmts.push(Spanned { stmts.push(Spanned {
@ -4115,11 +4115,7 @@ impl<'a> Parser<'a> {
let lo = e.span.lo; let lo = e.span.lo;
let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?; let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?;
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?; let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?;
self.handle_expression_like_statement( self.handle_expression_like_statement(e, span, &mut stmts)?;
e,
span,
&mut stmts,
&mut expr)?;
} }
} }
} }
@ -4133,13 +4129,6 @@ impl<'a> Parser<'a> {
}); });
self.bump(); self.bump();
} }
token::CloseDelim(token::Brace) => {
// if a block ends in `m!(arg)` without
// a `;`, it must be an expr
expr = Some(self.mk_mac_expr(span.lo, span.hi,
m.and_then(|x| x.node),
attrs));
}
_ => { _ => {
stmts.push(Spanned { stmts.push(Spanned {
node: StmtKind::Mac(m, style, attrs), node: StmtKind::Mac(m, style, attrs),
@ -4165,7 +4154,6 @@ impl<'a> Parser<'a> {
Ok(P(ast::Block { Ok(P(ast::Block {
stmts: stmts, stmts: stmts,
expr: expr,
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
rules: s, rules: s,
span: mk_sp(lo, self.last_span.hi), span: mk_sp(lo, self.last_span.hi),
@ -4175,8 +4163,7 @@ impl<'a> Parser<'a> {
fn handle_expression_like_statement(&mut self, fn handle_expression_like_statement(&mut self,
e: P<Expr>, e: P<Expr>,
span: Span, span: Span,
stmts: &mut Vec<Stmt>, stmts: &mut Vec<Stmt>)
last_block_expr: &mut Option<P<Expr>>)
-> PResult<'a, ()> { -> PResult<'a, ()> {
// expression without semicolon // expression without semicolon
if classify::expr_requires_semi_to_be_stmt(&e) { if classify::expr_requires_semi_to_be_stmt(&e) {
@ -4202,7 +4189,6 @@ impl<'a> Parser<'a> {
span: span_with_semi, span: span_with_semi,
}); });
} }
token::CloseDelim(token::Brace) => *last_block_expr = Some(e),
_ => { _ => {
stmts.push(Spanned { stmts.push(Spanned {
node: StmtKind::Expr(e, ast::DUMMY_NODE_ID), node: StmtKind::Expr(e, ast::DUMMY_NODE_ID),

View file

@ -1619,9 +1619,6 @@ impl<'a> State<'a> {
} }
} }
} }
if parse::classify::stmt_ends_with_semi(&st.node) {
try!(word(&mut self.s, ";"));
}
self.maybe_print_trailing_comment(st.span, None) self.maybe_print_trailing_comment(st.span, None)
} }
@ -1668,14 +1665,6 @@ impl<'a> State<'a> {
for st in &blk.stmts { for st in &blk.stmts {
try!(self.print_stmt(st)); try!(self.print_stmt(st));
} }
match blk.expr {
Some(ref expr) => {
try!(self.space_if_not_bol());
try!(self.print_expr_outer_attr_style(&expr, false));
try!(self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi)));
}
_ => ()
}
try!(self.bclose_maybe_open(blk.span, indented, close_box)); try!(self.bclose_maybe_open(blk.span, indented, close_box));
self.ann.post(self, NodeBlock(blk)) self.ann.post(self, NodeBlock(blk))
} }
@ -2084,24 +2073,23 @@ impl<'a> State<'a> {
_ => false _ => false
}; };
if !default_return || !body.stmts.is_empty() || body.expr.is_none() { match body.stmts.last().map(|stmt| &stmt.node) {
try!(self.print_block_unclosed(&body)); Some(&ast::StmtKind::Expr(ref i_expr, _)) if default_return &&
} else { body.stmts.len() == 1 => {
// we extract the block, so as not to create another set of boxes // we extract the block, so as not to create another set of boxes
let i_expr = body.expr.as_ref().unwrap(); if let ast::ExprKind::Block(ref blk) = i_expr.node {
match i_expr.node {
ast::ExprKind::Block(ref blk) => {
try!(self.print_block_unclosed_with_attrs( try!(self.print_block_unclosed_with_attrs(
&blk, &blk,
i_expr.attrs.as_attr_slice())); i_expr.attrs.as_attr_slice()));
} } else {
_ => {
// this is a bare expression // this is a bare expression
try!(self.print_expr(&i_expr)); try!(self.print_expr(&i_expr));
try!(self.end()); // need to close a box try!(self.end()); // need to close a box
} }
} }
_ => try!(self.print_block_unclosed(&body)),
} }
// a box will be closed by print_expr, but we didn't want an overall // a box will be closed by print_expr, but we didn't want an overall
// wrapper so we closed the corresponding opening. so create an // wrapper so we closed the corresponding opening. so create an
// empty box to satisfy the close. // empty box to satisfy the close.
@ -2295,6 +2283,7 @@ impl<'a> State<'a> {
try!(self.word_space("=")); try!(self.word_space("="));
try!(self.print_expr(&init)); try!(self.print_expr(&init));
} }
try!(word(&mut self.s, ";"));
self.end() self.end()
} }
ast::DeclKind::Item(ref item) => self.print_item(&item) ast::DeclKind::Item(ref item) => self.print_item(&item)

View file

@ -474,7 +474,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
let main_attr = ecx.attribute(sp, main_meta); let main_attr = ecx.attribute(sp, main_meta);
// pub fn main() { ... } // pub fn main() { ... }
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![])); let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![]));
let main_body = ecx.block_all(sp, vec![call_test_main], None); let main_body = ecx.block_all(sp, vec![call_test_main]);
let main = ast::ItemKind::Fn(ecx.fn_decl(vec![], main_ret_ty), let main = ast::ItemKind::Fn(ecx.fn_decl(vec![], main_ret_ty),
ast::Unsafety::Normal, ast::Unsafety::Normal,
ast::Constness::NotConst, ast::Constness::NotConst,

View file

@ -608,7 +608,6 @@ pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V,
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) {
walk_list!(visitor, visit_stmt, &block.stmts); walk_list!(visitor, visit_stmt, &block.stmts);
walk_list!(visitor, visit_expr, &block.expr);
} }
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {

View file

@ -145,12 +145,10 @@ fn cs_clone(
match mode { match mode {
Mode::Shallow => { Mode::Shallow => {
cx.expr_block(cx.block(trait_span, let mut stmts: Vec<_> =
all_fields.iter() all_fields.iter().map(subcall).map(|e| cx.stmt_expr(e)).collect();
.map(subcall) stmts.push(cx.stmt_expr(cx.expr_deref(trait_span, cx.expr_self(trait_span))));
.map(|e| cx.stmt_expr(e)) cx.expr_block(cx.block(trait_span, stmts))
.collect(),
Some(cx.expr_deref(trait_span, cx.expr_self(trait_span)))))
} }
Mode::Deep => { Mode::Deep => {
match *vdata { match *vdata {

View file

@ -30,7 +30,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
// create `a.<method>(); b.<method>(); c.<method>(); ...` // create `a.<method>(); b.<method>(); c.<method>(); ...`
// (where method is `assert_receiver_is_total_eq`) // (where method is `assert_receiver_is_total_eq`)
let stmts = exprs.into_iter().map(|e| cx.stmt_expr(e)).collect(); let stmts = exprs.into_iter().map(|e| cx.stmt_expr(e)).collect();
let block = cx.block(span, stmts, None); let block = cx.block(span, stmts);
cx.expr_block(block) cx.expr_block(block)
}, },
Box::new(|cx, sp, _, _| { Box::new(|cx, sp, _, _| {

View file

@ -78,7 +78,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
let fmt = substr.nonself_args[0].clone(); let fmt = substr.nonself_args[0].clone();
let stmts = match *substr.fields { let mut stmts = match *substr.fields {
Struct(_, ref fields) | EnumMatching(_, _, ref fields) => { Struct(_, ref fields) | EnumMatching(_, _, ref fields) => {
let mut stmts = vec![]; let mut stmts = vec![];
if !is_struct { if !is_struct {
@ -136,7 +136,8 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
token::str_to_ident("finish"), token::str_to_ident("finish"),
vec![]); vec![]);
let block = cx.block(span, stmts, Some(expr)); stmts.push(cx.stmt_expr(expr));
let block = cx.block(span, stmts);
cx.expr_block(block) cx.expr_block(block)
} }

View file

@ -285,7 +285,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
cx.expr_str(trait_span, substr.type_ident.name.as_str()), cx.expr_str(trait_span, substr.type_ident.name.as_str()),
blk blk
)); ));
cx.expr_block(cx.block(trait_span, vec!(me), Some(ret))) cx.expr_block(cx.block(trait_span, vec![me, cx.stmt_expr(ret)]))
} }
_ => cx.bug("expected Struct or EnumMatching in derive(Encodable)") _ => cx.bug("expected Struct or EnumMatching in derive(Encodable)")

View file

@ -1332,8 +1332,8 @@ impl<'a> MethodDef<'a> {
// } // }
let all_match = cx.expr_match(sp, match_arg, match_arms); let all_match = cx.expr_match(sp, match_arg, match_arms);
let arm_expr = cx.expr_if(sp, discriminant_test, all_match, Some(arm_expr)); let arm_expr = cx.expr_if(sp, discriminant_test, all_match, Some(arm_expr));
cx.expr_block( index_let_stmts.push(cx.stmt_expr(arm_expr));
cx.block_all(sp, index_let_stmts, Some(arm_expr))) cx.expr_block(cx.block_all(sp, index_let_stmts))
} else if variants.is_empty() { } else if variants.is_empty() {
// As an additional wrinkle, For a zero-variant enum A, // As an additional wrinkle, For a zero-variant enum A,
// currently the compiler // currently the compiler

View file

@ -99,5 +99,5 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
stmts.push(call_hash(span, self_.clone())); stmts.push(call_hash(span, self_.clone()));
} }
cx.expr_block(cx.block(trait_span, stmts, None)) cx.expr_block(cx.block(trait_span, stmts))
} }

View file

@ -297,8 +297,7 @@ fn call_intrinsic(cx: &ExtCtxt,
let call = cx.expr_call_global(span, path, args); let call = cx.expr_call_global(span, path, args);
cx.expr_block(P(ast::Block { cx.expr_block(P(ast::Block {
stmts: vec![], stmts: vec![cx.stmt_expr(call)],
expr: Some(call),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated), rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated),
span: span })) span: span }))

View file

@ -444,9 +444,10 @@ impl<'a, 'b> Context<'a, 'b> {
let decl = respan(sp, ast::DeclKind::Item(item)); let decl = respan(sp, ast::DeclKind::Item(item));
// Wrap the declaration in a block so that it forms a single expression. // Wrap the declaration in a block so that it forms a single expression.
ecx.expr_block(ecx.block(sp, ecx.expr_block(ecx.block(sp, vec![
vec![respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))], respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID)),
Some(ecx.expr_ident(sp, name)))) ecx.stmt_expr(ecx.expr_ident(sp, name)),
]))
} }
/// Actually builds the expression which the iformat! block will be expanded /// Actually builds the expression which the iformat! block will be expanded