@@ -35,7 +35,8 @@ fn modify_for_testing(@ast::crate crate) -> @ast::crate {
35
35
mutable testfns = ~[ ] ) ;
36
36
37
37
auto precursor = rec( fold_crate = bind fold_crate( cx, _, _) ,
38
- fold_item = bind fold_item( cx, _, _)
38
+ fold_item = bind fold_item( cx, _, _) ,
39
+ fold_mod = bind fold_mod( cx, _, _)
39
40
with * fold:: default_ast_fold( ) ) ;
40
41
41
42
auto fold = fold:: make_fold( precursor) ;
@@ -45,6 +46,28 @@ fn modify_for_testing(@ast::crate crate) -> @ast::crate {
45
46
ret res;
46
47
}
47
48
49
+ fn fold_mod( & test_ctxt cx, & ast:: _mod m,
50
+ fold:: ast_fold fld) -> ast:: _mod {
51
+
52
+ // Remove any defined main function from the AST so it doesn't clash with
53
+ // the one we're going to add. FIXME: This is sloppy. Instead we should
54
+ // have some mechanism to indicate to the translation pass which function
55
+ // we want to be main.
56
+ fn nomain( & @ast:: item item) -> option:: t[ @ast:: item] {
57
+ alt ( item. node) {
58
+ ast:: item_fn( ?f, _) {
59
+ if ( item. ident == "main" ) { option:: none }
60
+ else { option:: some ( item) }
61
+ }
62
+ _ { option:: some ( item) }
63
+ }
64
+ }
65
+
66
+ auto mod_nomain = rec ( view_items=m. view_items ,
67
+ items=ivec:: filter_map ( nomain, m. items ) ) ;
68
+ ret fold:: noop_fold_mod ( mod_nomain, fld) ;
69
+ }
70
+
48
71
fn fold_crate ( & test_ctxt cx, & ast:: crate_ c,
49
72
fold:: ast_fold fld) -> ast:: crate_ {
50
73
auto folded = fold:: noop_fold_crate ( c, fld) ;
0 commit comments