diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-06-26 02:19:34 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-06-26 02:20:14 +0000 |
| commit | 9bb3ea0febcbb8f6d7715256a5644daa985cf4e7 (patch) | |
| tree | eeed21468b6bceeed80766490852c8cee2653170 /src/libsyntax/ext/build.rs | |
| parent | 8eddf0280014972e051856dfe949054acf53c043 (diff) | |
| parent | 8cad25199acb346bf8d6b1771f1f50dc9e59374c (diff) | |
| download | rust-9bb3ea0febcbb8f6d7715256a5644daa985cf4e7.tar.gz rust-9bb3ea0febcbb8f6d7715256a5644daa985cf4e7.zip | |
Rollup merge of #34436 - jseyfried:no_block_expr, r=eddyb
To allow these braced macro invocation, this PR removes the optional expression from `ast::Block` and instead uses a `StmtKind::Expr` at the end of the statement list.
Currently, braced macro invocations in blocks can expand into statements (and items) except when they are last in a block, in which case they can only expand into expressions.
For example,
```rust
macro_rules! make_stmt {
() => { let x = 0; }
}
fn f() {
make_stmt! {} //< This is OK...
let x = 0; //< ... unless this line is commented out.
}
```
Fixes #34418.
Diffstat (limited to 'src/libsyntax/ext/build.rs')
| -rw-r--r-- | src/libsyntax/ext/build.rs | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index f4ae23ed8be..435241f426e 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -88,6 +88,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, @@ -99,12 +100,8 @@ pub trait AstBuilder { fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt; // blocks - fn block(&self, span: Span, stmts: Vec<ast::Stmt>, - expr: Option<P<ast::Expr>>) -> P<ast::Block>; + 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>, - expr: Option<P<ast::Expr>>) -> P<ast::Block>; // expressions fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr>; @@ -512,6 +509,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ast::Stmt { id: ast::DUMMY_NODE_ID, span: expr.span, + node: ast::StmtKind::Expr(expr), + } + } + + fn stmt_semi(&self, expr: P<ast::Expr>) -> ast::Stmt { + ast::Stmt { + id: ast::DUMMY_NODE_ID, + span: expr.span, node: ast::StmtKind::Semi(expr), } } @@ -567,11 +572,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> { }) } - fn block(&self, span: Span, stmts: Vec<ast::Stmt>, - expr: Option<P<Expr>>) -> P<ast::Block> { - self.block_all(span, stmts, expr) - } - fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt { ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -581,19 +581,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> { - self.block_all(expr.span, Vec::new(), Some(expr)) - } - fn block_all(&self, - span: Span, - stmts: Vec<ast::Stmt>, - expr: Option<P<ast::Expr>>) -> P<ast::Block> { - P(ast::Block { - stmts: stmts, - expr: expr, - id: ast::DUMMY_NODE_ID, - rules: BlockCheckMode::Default, - span: span, - }) + self.block(expr.span, vec![ast::Stmt { + id: ast::DUMMY_NODE_ID, + span: expr.span, + node: ast::StmtKind::Expr(expr), + }]) + } + fn block(&self, span: Span, stmts: Vec<ast::Stmt>) -> P<ast::Block> { + P(ast::Block { + stmts: stmts, + id: ast::DUMMY_NODE_ID, + rules: BlockCheckMode::Default, + span: span, + }) } fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr> { @@ -962,14 +962,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ids: Vec<ast::Ident>, stmts: Vec<ast::Stmt>) -> 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> { - 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>, 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 { |
