Avoid returning original macro if expansion fails.

Closes #11692. Instead of returning the original expression, a dummy expression
(with identical span) is returned. This prevents infinite loops of failed
expansions as well as odd double error messages in certain situations.
This commit is contained in:
Douglas Young
2014-02-18 16:14:12 +00:00
parent 517e38997d
commit 0bdfd0f4c7
11 changed files with 53 additions and 28 deletions

View File

@@ -101,6 +101,7 @@ pub trait AnyMacro {
fn make_stmt(&self) -> @ast::Stmt;
}
pub enum MacResult {
MRExpr(@ast::Expr),
MRItem(@ast::Item),
@@ -112,10 +113,15 @@ impl MacResult {
/// type signatures after emitting a non-fatal error (which stop
/// compilation well before the validity (or otherwise)) of the
/// expression are checked.
pub fn dummy_expr() -> MacResult {
MRExpr(@ast::Expr {
id: ast::DUMMY_NODE_ID, node: ast::ExprLogLevel, span: codemap::DUMMY_SP
})
pub fn raw_dummy_expr(sp: codemap::Span) -> @ast::Expr {
@ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprLogLevel,
span: sp
}
}
pub fn dummy_expr(sp: codemap::Span) -> MacResult {
MRExpr(MacResult::raw_dummy_expr(sp))
}
}