From 11024eaebbd5d958df3944178e5746c0d9fda383 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 7 Nov 2012 12:19:50 -0800 Subject: [PATCH] rustc: Only strip out the main function when generating test executable, not lib --- src/librustc/front/test.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 4a6936a32a5..21fb1d49b3a 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -71,14 +71,15 @@ 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 - // the one we're going to add. + // the one we're going to add. Only if compiling an executable. // FIXME (#2403): This is sloppy. Instead we should have some mechanism to // indicate to the translation pass which function we want to be main. fn nomain(cx: test_ctxt, item: @ast::item) -> Option<@ast::item> { match item.node { ast::item_fn(*) => { - if item.ident == cx.sess.ident_of(~"main") { + if item.ident == cx.sess.ident_of(~"main") + && !cx.sess.building_library { option::None } else { option::Some(item) } }