Skip to content

Commit db8d9dd

Browse files
committed
rustc: Record the main function in the session in resolve3
1 parent 1c2843c commit db8d9dd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/rustc/middle/resolve3.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,17 @@ class Module {
380380
}
381381
}
382382

383+
pure fn is_crate_root(module: @Module) -> bool {
384+
alt module.def_id {
385+
none => {
386+
ret false;
387+
}
388+
some(def_id) => {
389+
ret def_id.crate == 0 && def_id.node == 0;
390+
}
391+
}
392+
}
393+
383394
// XXX: This is a workaround due to is_none in the standard library mistakenly
384395
// requiring a T:copy.
385396

@@ -2802,6 +2813,20 @@ class Resolver {
28022813
}
28032814

28042815
item_fn(fn_decl, ty_params, block) {
2816+
// If this is the main function, we must record it in the
2817+
// session.
2818+
//
2819+
// For speed, we put the string comparison last in this chain
2820+
// of conditionals.
2821+
2822+
if !self.session.building_library &&
2823+
is_none(self.session.main_fn) &&
2824+
is_crate_root(self.current_module) &&
2825+
str::eq(*item.ident, "main") {
2826+
2827+
self.session.main_fn = some((item.id, item.span));
2828+
}
2829+
28052830
self.resolve_function(NormalRibKind,
28062831
some(@fn_decl),
28072832
HasTypeParameters(&ty_params,

0 commit comments

Comments
 (0)