about summary refs log tree commit diff
diff options
context:
space:
mode:
authorILyoan <ilyoan@gmail.com>2013-01-15 16:28:20 +0900
committerILyoan <ilyoan@gmail.com>2013-01-15 17:06:37 +0900
commita63b11a009fef9207232bbde0392f9ec18a3e7a4 (patch)
tree25f0462becfcd046a269b1a5c08bc9b9d8d74215
parenteb8fd119c65c67f3b1b8268cc7341c22d39b7b61 (diff)
downloadrust-a63b11a009fef9207232bbde0392f9ec18a3e7a4.tar.gz
rust-a63b11a009fef9207232bbde0392f9ec18a3e7a4.zip
when test, just remove #[main] attr
-rw-r--r--src/librustc/front/test.rs20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs
index 979cc902cc7..e89a0a81701 100644
--- a/src/librustc/front/test.rs
+++ b/src/librustc/front/test.rs
@@ -86,24 +86,20 @@ fn strip_test_functions(crate: @ast::crate) -> @ast::crate {
 
 fn fold_mod(cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod {
 
-    // Remove any defined main function from the AST so it doesn't clash with
+    // Remove any #[main] from the AST so it doesn't clash with
     // the one we're going to add. Only if compiling an executable.
 
-    fn nomain(cx: test_ctxt, item: @ast::item) -> Option<@ast::item> {
-        match item.node {
-          ast::item_fn(*) => {
-            if attrs_contains_name(item.attrs, ~"main")
-                    && !cx.sess.building_library {
-                option::None
-            } else { option::Some(item) }
-          }
-          _ => option::Some(item)
-        }
+    fn nomain(cx: test_ctxt, item: @ast::item) -> @ast::item {
+        if !cx.sess.building_library {
+            @ast::item{attrs: item.attrs.filtered(|attr| {
+                               attr::get_attr_name(*attr) != ~"main"
+                           }),.. copy *item}
+        } else { item }
     }
 
     let mod_nomain =
         {view_items: /*bad*/copy m.view_items,
-         items: vec::filter_map(m.items, |i| nomain(cx, *i))};
+         items: vec::map(m.items, |i| nomain(cx, *i))};
     return fold::noop_fold_mod(mod_nomain, fld);
 }