Skip to content

Commit 3970d02

Browse files
committed
rustc: Fix the logic for finding the Android main function
I don't understand what this logic is doing
1 parent 98f5c6d commit 3970d02

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/librustc/middle/entry.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ type EntryVisitor = vt<@mut EntryContext>;
4242
pub fn find_entry_point(session: Session, crate: @crate, ast_map: ast_map::map) {
4343

4444
// FIXME #4404 android JNI hacks
45-
if *session.building_library ||
46-
session.targ_cfg.os == session::os_android {
45+
if *session.building_library &&
46+
session.targ_cfg.os != session::os_android {
4747
// No need to find a main function
4848
return;
4949
}
@@ -127,18 +127,24 @@ fn configure_main(ctxt: @mut EntryContext) {
127127
*this.session.entry_fn = this.main_fn;
128128
*this.session.entry_type = Some(session::EntryMain);
129129
} else {
130-
// No main function
131-
this.session.err(~"main function not found");
132-
if !this.non_main_fns.is_empty() {
133-
// There were some functions named 'main' though. Try to give the user a hint.
134-
this.session.note(~"the main function must be defined at the crate level \
135-
but you have one or more functions named 'main' that are not \
136-
defined at the crate level. Either move the definition or attach \
137-
the `#[main]` attribute to override this behavior.");
138-
for this.non_main_fns.each |&(_, span)| {
139-
this.session.span_note(span, ~"here is a function named 'main'");
130+
if !*this.session.building_library {
131+
// No main function
132+
this.session.err(~"main function not found");
133+
if !this.non_main_fns.is_empty() {
134+
// There were some functions named 'main' though. Try to give the user a hint.
135+
this.session.note(~"the main function must be defined at the crate level \
136+
but you have one or more functions named 'main' that are not \
137+
defined at the crate level. Either move the definition or \
138+
attach the `#[main]` attribute to override this behavior.");
139+
for this.non_main_fns.each |&(_, span)| {
140+
this.session.span_note(span, ~"here is a function named 'main'");
141+
}
140142
}
143+
this.session.abort_if_errors();
144+
} else {
145+
// If we *are* building a library, then we're on android where we still might
146+
// optionally want to translate main $4404
147+
assert!(this.session.targ_cfg.os == session::os_android);
141148
}
142-
this.session.abort_if_errors();
143149
}
144150
}

src/test/compile-fail/issue-2995.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
fn bad (p: *int) {
1212
let _q: &int = p as &int; //~ ERROR non-scalar cast
1313
}
14+
15+
fn main() { }

src/test/compile-fail/tag-variant-disr-dup.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ enum color {
1919
black = 0x000000,
2020
white = 0x000000,
2121
}
22+
23+
fn main() { }

0 commit comments

Comments
 (0)