about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/expand.rs24
-rw-r--r--src/libsyntax/ext/qquote.rs4
-rw-r--r--src/libsyntax/fold.rs29
3 files changed, 35 insertions, 22 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)}
 
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 7f83b16b8ab..9ea58865425 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -22,7 +22,7 @@ iface ast_fold {
     fn fold_crate_directive(&&@crate_directive) -> @crate_directive;
     fn fold_view_item(&&@view_item) -> @view_item;
     fn fold_foreign_item(&&@foreign_item) -> @foreign_item;
-    fn fold_item(&&@item) -> @item;
+    fn fold_item(&&@item) -> option<@item>;
     fn fold_class_item(&&@class_member) -> @class_member;
     fn fold_item_underscore(item_) -> item_;
     fn fold_method(&&@method) -> @method;
@@ -55,7 +55,7 @@ type ast_fold_precursor = @{
                               ast_fold) -> (crate_directive_, span),
     fold_view_item: fn@(view_item_, ast_fold) -> view_item_,
     fold_foreign_item: fn@(&&@foreign_item, ast_fold) -> @foreign_item,
-    fold_item: fn@(&&@item, ast_fold) -> @item,
+    fold_item: fn@(&&@item, ast_fold) -> option<@item>,
     fold_class_item: fn@(&&@class_member, ast_fold) -> @class_member,
     fold_item_underscore: fn@(item_, ast_fold) -> item_,
     fold_method: fn@(&&@method, ast_fold) -> @method,
@@ -211,15 +211,15 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
           span: fld.new_span(ni.span)};
 }
 
-fn noop_fold_item(&&i: @item, fld: ast_fold) -> @item {
+fn noop_fold_item(&&i: @item, fld: ast_fold) -> option<@item> {
     let fold_attribute = |x| fold_attribute_(x, fld);
 
-    ret @{ident: fld.fold_ident(i.ident),
-          attrs: vec::map(i.attrs, fold_attribute),
-          id: fld.new_id(i.id),
-          node: fld.fold_item_underscore(i.node),
-          vis: i.vis,
-          span: fld.new_span(i.span)};
+    ret some(@{ident: fld.fold_ident(i.ident),
+               attrs: vec::map(i.attrs, fold_attribute),
+               id: fld.new_id(i.id),
+               node: fld.fold_item_underscore(i.node),
+               vis: i.vis,
+               span: fld.new_span(i.span)});
 }
 
 fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold)
@@ -361,7 +361,12 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
 fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
     alt d {
       decl_local(ls) { decl_local(vec::map(ls, fld.fold_local)) }
-      decl_item(it) { decl_item(fld.fold_item(it)) }
+      decl_item(it) {
+        alt fld.fold_item(it) {
+          some(it_folded) { decl_item(it_folded) }
+          none { decl_local(~[]) }
+        }
+      }
     }
 }
 
@@ -520,7 +525,7 @@ fn noop_fold_ty_constr(c: ty_constr_, fld: ast_fold) -> ty_constr_ {
 // ...nor do modules
 fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod {
     ret {view_items: vec::map(m.view_items, fld.fold_view_item),
-         items: vec::map(m.items, fld.fold_item)};
+         items: vec::filter_map(m.items, fld.fold_item)};
 }
 
 fn noop_fold_foreign_mod(nm: foreign_mod, fld: ast_fold) -> foreign_mod {
@@ -638,7 +643,7 @@ impl of ast_fold for ast_fold_precursor {
         -> @foreign_item {
         ret self.fold_foreign_item(x, self as ast_fold);
     }
-    fn fold_item(&&i: @item) -> @item {
+    fn fold_item(&&i: @item) -> option<@item> {
         ret self.fold_item(i, self as ast_fold);
     }
     fn fold_class_item(&&ci: @class_member) -> @class_member {