Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow statement-generating braced macro invocations at the end of blocks #34436

Merged
merged 5 commits into from
Jun 28, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid wasting node ids
  • Loading branch information
jseyfried committed Jun 23, 2016
commit a48a4f5c7a2f6df152b248059e9c926e6c23065d
25 changes: 25 additions & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
@@ -763,6 +763,10 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
}

pub fn assign_node_ids(sess: &Session, krate: ast::Crate) -> ast::Crate {
use syntax::codemap::Spanned;
use syntax::ptr::P;
use syntax::util::move_map::MoveMap;

struct NodeIdAssigner<'a> {
sess: &'a Session,
}
@@ -772,6 +776,27 @@ pub fn assign_node_ids(sess: &Session, krate: ast::Crate) -> ast::Crate {
assert_eq!(old_id, ast::DUMMY_NODE_ID);
self.sess.next_node_id()
}

fn fold_block(&mut self, block: P<ast::Block>) -> P<ast::Block> {
block.map(|mut block| {
block.id = self.new_id(block.id);

let stmt = block.stmts.pop();
block.stmts = block.stmts.move_flat_map(|s| self.fold_stmt(s).into_iter());
if let Some(Spanned { node: ast::StmtKind::Expr(expr, _), span }) = stmt {
let expr = self.fold_expr(expr);
let id = expr.id;
block.stmts.push(Spanned {
span: span,
node: ast::StmtKind::Expr(expr, id)
});
} else if let Some(stmt) = stmt {
block.stmts.extend(self.fold_stmt(stmt));
}

block
})
}
}

let krate = time(sess.time_passes(),