Add ecx.stmt_semi()
and fix issues with the pretty-printer
This commit is contained in:
parent
060a84d1f7
commit
8cad25199a
3 changed files with 18 additions and 3 deletions
|
@ -87,6 +87,7 @@ pub trait AstBuilder {
|
|||
|
||||
// statements
|
||||
fn stmt_expr(&self, expr: P<ast::Expr>) -> ast::Stmt;
|
||||
fn stmt_semi(&self, expr: P<ast::Expr>) -> ast::Stmt;
|
||||
fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: P<ast::Expr>) -> ast::Stmt;
|
||||
fn stmt_let_typed(&self,
|
||||
sp: Span,
|
||||
|
@ -507,6 +508,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||
respan(expr.span, ast::StmtKind::Expr(expr, ast::DUMMY_NODE_ID))
|
||||
}
|
||||
|
||||
fn stmt_semi(&self, expr: P<ast::Expr>) -> ast::Stmt {
|
||||
respan(expr.span, ast::StmtKind::Semi(expr, ast::DUMMY_NODE_ID))
|
||||
}
|
||||
|
||||
fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
|
||||
ex: P<ast::Expr>) -> ast::Stmt {
|
||||
let pat = if mutbl {
|
||||
|
|
|
@ -953,7 +953,6 @@ mod tests {
|
|||
attrs: None,}),
|
||||
ast::DUMMY_NODE_ID),
|
||||
span: sp(17,19)}),
|
||||
expr: None,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
rules: ast::BlockCheckMode::Default, // no idea
|
||||
span: sp(15,21),
|
||||
|
|
|
@ -1599,6 +1599,9 @@ impl<'a> State<'a> {
|
|||
ast::StmtKind::Expr(ref expr, _) => {
|
||||
try!(self.space_if_not_bol());
|
||||
try!(self.print_expr_outer_attr_style(&expr, false));
|
||||
if parse::classify::expr_requires_semi_to_be_stmt(expr) {
|
||||
try!(word(&mut self.s, ";"));
|
||||
}
|
||||
}
|
||||
ast::StmtKind::Semi(ref expr, _) => {
|
||||
try!(self.space_if_not_bol());
|
||||
|
@ -1662,9 +1665,17 @@ impl<'a> State<'a> {
|
|||
|
||||
try!(self.print_inner_attributes(attrs));
|
||||
|
||||
for st in &blk.stmts {
|
||||
try!(self.print_stmt(st));
|
||||
for (i, st) in blk.stmts.iter().enumerate() {
|
||||
match st.node {
|
||||
ast::StmtKind::Expr(ref expr, _) if i == blk.stmts.len() - 1 => {
|
||||
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.print_stmt(st)),
|
||||
}
|
||||
}
|
||||
|
||||
try!(self.bclose_maybe_open(blk.span, indented, close_box));
|
||||
self.ann.post(self, NodeBlock(blk))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue