From 3970d02ec5fb33b2e10132b48dd193b86c245596 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 6 May 2013 18:48:24 -0700 Subject: [PATCH] rustc: Fix the logic for finding the Android main function I don't understand what this logic is doing --- src/librustc/middle/entry.rs | 32 +++++++++++-------- src/test/compile-fail/issue-2995.rs | 2 ++ src/test/compile-fail/tag-variant-disr-dup.rs | 2 ++ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index 47873b3fa1f..9ffd0e6f22c 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -42,8 +42,8 @@ type EntryVisitor = vt<@mut EntryContext>; pub fn find_entry_point(session: Session, crate: @crate, ast_map: ast_map::map) { // FIXME #4404 android JNI hacks - if *session.building_library || - session.targ_cfg.os == session::os_android { + if *session.building_library && + session.targ_cfg.os != session::os_android { // No need to find a main function return; } @@ -127,18 +127,24 @@ fn configure_main(ctxt: @mut EntryContext) { *this.session.entry_fn = this.main_fn; *this.session.entry_type = Some(session::EntryMain); } else { - // No main function - this.session.err(~"main function not found"); - if !this.non_main_fns.is_empty() { - // There were some functions named 'main' though. Try to give the user a hint. - this.session.note(~"the main function must be defined at the crate level \ - but you have one or more functions named 'main' that are not \ - defined at the crate level. Either move the definition or attach \ - the `#[main]` attribute to override this behavior."); - for this.non_main_fns.each |&(_, span)| { - this.session.span_note(span, ~"here is a function named 'main'"); + if !*this.session.building_library { + // No main function + this.session.err(~"main function not found"); + if !this.non_main_fns.is_empty() { + // There were some functions named 'main' though. Try to give the user a hint. + this.session.note(~"the main function must be defined at the crate level \ + but you have one or more functions named 'main' that are not \ + defined at the crate level. Either move the definition or \ + attach the `#[main]` attribute to override this behavior."); + for this.non_main_fns.each |&(_, span)| { + this.session.span_note(span, ~"here is a function named 'main'"); + } } + this.session.abort_if_errors(); + } else { + // If we *are* building a library, then we're on android where we still might + // optionally want to translate main $4404 + assert!(this.session.targ_cfg.os == session::os_android); } - this.session.abort_if_errors(); } } diff --git a/src/test/compile-fail/issue-2995.rs b/src/test/compile-fail/issue-2995.rs index 5c48416667f..3e771eef970 100644 --- a/src/test/compile-fail/issue-2995.rs +++ b/src/test/compile-fail/issue-2995.rs @@ -11,3 +11,5 @@ fn bad (p: *int) { let _q: &int = p as ∫ //~ ERROR non-scalar cast } + +fn main() { } \ No newline at end of file diff --git a/src/test/compile-fail/tag-variant-disr-dup.rs b/src/test/compile-fail/tag-variant-disr-dup.rs index be53b6a0ba3..216779fac7c 100644 --- a/src/test/compile-fail/tag-variant-disr-dup.rs +++ b/src/test/compile-fail/tag-variant-disr-dup.rs @@ -19,3 +19,5 @@ enum color { black = 0x000000, white = 0x000000, } + +fn main() { } \ No newline at end of file