Refactor away duplicate method ecx.block_all()
This commit is contained in:
parent
94479ad81f
commit
060a84d1f7
4 changed files with 7 additions and 12 deletions
|
@ -100,7 +100,6 @@ pub trait AstBuilder {
|
|||
// blocks
|
||||
fn block(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block>;
|
||||
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block>;
|
||||
fn block_all(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block>;
|
||||
|
||||
// expressions
|
||||
fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr>;
|
||||
|
@ -553,22 +552,18 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||
P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID)))
|
||||
}
|
||||
|
||||
fn block(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block> {
|
||||
self.block_all(span, stmts)
|
||||
}
|
||||
|
||||
fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt {
|
||||
let decl = respan(sp, ast::DeclKind::Item(item));
|
||||
respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))
|
||||
}
|
||||
|
||||
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {
|
||||
self.block_all(expr.span, vec![Spanned {
|
||||
self.block(expr.span, vec![Spanned {
|
||||
span: expr.span,
|
||||
node: ast::StmtKind::Expr(expr, ast::DUMMY_NODE_ID),
|
||||
}])
|
||||
}
|
||||
fn block_all(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block> {
|
||||
fn block(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block> {
|
||||
P(ast::Block {
|
||||
stmts: stmts,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
|
|
|
@ -513,7 +513,7 @@ pub fn expand_quote_matcher(cx: &mut ExtCtxt,
|
|||
let mut vector = mk_stmts_let(cx, sp);
|
||||
vector.extend(statements_mk_tts(cx, &tts[..], true));
|
||||
vector.push(cx.stmt_expr(cx.expr_ident(sp, id_ext("tt"))));
|
||||
let block = cx.expr_block(cx.block_all(sp, vector));
|
||||
let block = cx.expr_block(cx.block(sp, vector));
|
||||
|
||||
let expanded = expand_wrapper(cx, sp, cx_expr, block, &[&["syntax", "ext", "quote", "rt"]]);
|
||||
base::MacEager::expr(expanded)
|
||||
|
@ -884,7 +884,7 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[TokenTree])
|
|||
let mut vector = mk_stmts_let(cx, sp);
|
||||
vector.extend(statements_mk_tts(cx, &tts[..], false));
|
||||
vector.push(cx.stmt_expr(cx.expr_ident(sp, id_ext("tt"))));
|
||||
let block = cx.expr_block(cx.block_all(sp, vector));
|
||||
let block = cx.expr_block(cx.block(sp, vector));
|
||||
|
||||
(cx_expr, block)
|
||||
}
|
||||
|
@ -905,7 +905,7 @@ fn expand_wrapper(cx: &ExtCtxt,
|
|||
}).chain(Some(stmt_let_ext_cx)).collect::<Vec<_>>();
|
||||
stmts.push(cx.stmt_expr(expr));
|
||||
|
||||
cx.expr_block(cx.block_all(sp, stmts))
|
||||
cx.expr_block(cx.block(sp, stmts))
|
||||
}
|
||||
|
||||
fn expand_parse_call(cx: &ExtCtxt,
|
||||
|
|
|
@ -474,7 +474,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
|
|||
let main_attr = ecx.attribute(sp, main_meta);
|
||||
// pub fn main() { ... }
|
||||
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![]));
|
||||
let main_body = ecx.block_all(sp, vec![call_test_main]);
|
||||
let main_body = ecx.block(sp, vec![call_test_main]);
|
||||
let main = ast::ItemKind::Fn(ecx.fn_decl(vec![], main_ret_ty),
|
||||
ast::Unsafety::Normal,
|
||||
ast::Constness::NotConst,
|
||||
|
|
|
@ -1333,7 +1333,7 @@ impl<'a> MethodDef<'a> {
|
|||
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));
|
||||
index_let_stmts.push(cx.stmt_expr(arm_expr));
|
||||
cx.expr_block(cx.block_all(sp, index_let_stmts))
|
||||
cx.expr_block(cx.block(sp, index_let_stmts))
|
||||
} else if variants.is_empty() {
|
||||
// As an additional wrinkle, For a zero-variant enum A,
|
||||
// currently the compiler
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue