Skip to content

Commit

Permalink
rustc: Fix the logic for finding the Android main function
Browse files Browse the repository at this point in the history
I don't understand what this logic is doing
  • Loading branch information
brson committed May 8, 2013
1 parent 98f5c6d commit 3970d02
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-2995.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
fn bad (p: *int) {
let _q: &int = p as &int; //~ ERROR non-scalar cast
}

fn main() { }
2 changes: 2 additions & 0 deletions src/test/compile-fail/tag-variant-disr-dup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ enum color {
black = 0x000000,
white = 0x000000,
}

fn main() { }

1 comment on commit 3970d02

@brson
Copy link
Owner Author

@brson brson commented on 3970d02 May 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.