about summary refs log tree commit diff
path: root/src/libsyntax/ext/base.rs
diff options
context:
space:
mode:
authorDouglas Young <rcxdude@gmail.com>2014-02-18 16:14:12 +0000
committerDouglas Young <rcxdude@gmail.com>2014-02-18 16:17:51 +0000
commit0bdfd0f4c76fa29a4be774937bc72165390b06d6 (patch)
treee595de26e0a25bd8b8258a82ef653553c499d42e /src/libsyntax/ext/base.rs
parent517e38997db9f60612676c9f83dab6ed35c1b5df (diff)
downloadrust-0bdfd0f4c76fa29a4be774937bc72165390b06d6.tar.gz
rust-0bdfd0f4c76fa29a4be774937bc72165390b06d6.zip
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.
Diffstat (limited to 'src/libsyntax/ext/base.rs')
-rw-r--r--src/libsyntax/ext/base.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 3dac82ae3b7..e6fffe8b53f 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -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))
     }
 }