summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorPaul Stansifer <paul.stansifer@gmail.com>2012-07-06 12:17:34 -0700
committerPaul Stansifer <paul.stansifer@gmail.com>2012-07-09 17:44:46 -0700
commit579768baa56e1344ef541cca6fef673b5e9eb683 (patch)
tree548fabedd02f610733e477e2eb4c8a8348411f4f /src/libsyntax/ext
parent7d90edcb3b292baaf406d4e6969987d466fc8fba (diff)
downloadrust-579768baa56e1344ef541cca6fef673b5e9eb683.tar.gz
rust-579768baa56e1344ef541cca6fef673b5e9eb683.zip
Allow folds to drop items.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/expand.rs24
-rw-r--r--src/libsyntax/ext/qquote.rs4
2 files changed, 18 insertions, 10 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 4ac7dc19c00..9cb610f486c 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -130,28 +130,34 @@ fn expand_mod_items(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
 /* record module we enter for `#mod` */
 fn expand_item(exts: hashmap<str, syntax_extension>,
                cx: ext_ctxt, &&it: @ast::item, fld: ast_fold,
-               orig: fn@(&&@ast::item, ast_fold) -> @ast::item)
-    -> @ast::item
+               orig: fn@(&&@ast::item, ast_fold) -> option<@ast::item>)
+    -> option<@ast::item>
 {
     let is_mod = alt it.node {
       ast::item_mod(_) | ast::item_foreign_mod(_) {true}
       _ {false}
     };
-    let it = alt it.node {
+    let maybe_it = alt it.node {
       ast::item_mac(*) {
         expand_item_mac(exts, cx, it, fld)
       }
-      _ { it }
+      _ { some(it) }
     };
-    if is_mod { cx.mod_push(it.ident); }
-    let ret_val = orig(it, fld);
-    if is_mod { cx.mod_pop(); }
-    ret ret_val;
+
+    alt maybe_it {
+      some(it) {
+        if is_mod { cx.mod_push(it.ident); }
+        let ret_val = orig(it, fld);
+        if is_mod { cx.mod_pop(); }
+        ret ret_val;
+      }
+      none { ret none; }
+    }
 }
 
 fn expand_item_mac(exts: hashmap<str, syntax_extension>,
                    cx: ext_ctxt, &&it: @ast::item,
-                   fld: ast_fold) -> @ast::item {
+                   fld: ast_fold) -> option<@ast::item> {
     alt it.node {
       item_mac({node: mac_invoc_tt(pth, tt), span}) {
         let extname = pth.idents[0];
diff --git a/src/libsyntax/ext/qquote.rs b/src/libsyntax/ext/qquote.rs
index 2bb8c27828c..e82901f2b3f 100644
--- a/src/libsyntax/ext/qquote.rs
+++ b/src/libsyntax/ext/qquote.rs
@@ -282,7 +282,9 @@ fn fold_crate(f: ast_fold, &&n: @ast::crate) -> @ast::crate {
 }
 fn fold_expr(f: ast_fold, &&n: @ast::expr) -> @ast::expr {f.fold_expr(n)}
 fn fold_ty(f: ast_fold, &&n: @ast::ty) -> @ast::ty {f.fold_ty(n)}
-fn fold_item(f: ast_fold, &&n: @ast::item) -> @ast::item {f.fold_item(n)}
+fn fold_item(f: ast_fold, &&n: @ast::item) -> @ast::item {
+    option::get(f.fold_item(n)) //HACK: we know we don't drop items
+}
 fn fold_stmt(f: ast_fold, &&n: @ast::stmt) -> @ast::stmt {f.fold_stmt(n)}
 fn fold_pat(f: ast_fold, &&n: @ast::pat) -> @ast::pat {f.fold_pat(n)}