about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-05-06 18:48:24 -0700
committerBrian Anderson <banderson@mozilla.com>2013-05-08 12:03:15 -0700
commit3970d02ec5fb33b2e10132b48dd193b86c245596 (patch)
tree93fcebec55f829ddc5b458ea88e7db6c4bf9a0cb
parent98f5c6d5b683b82e347247192061182cdd844cf5 (diff)
downloadrust-3970d02ec5fb33b2e10132b48dd193b86c245596.tar.gz
rust-3970d02ec5fb33b2e10132b48dd193b86c245596.zip
rustc: Fix the logic for finding the Android main function
I don't understand what this logic is doing
-rw-r--r--src/librustc/middle/entry.rs32
-rw-r--r--src/test/compile-fail/issue-2995.rs2
-rw-r--r--src/test/compile-fail/tag-variant-disr-dup.rs2
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 &int; //~ 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