rustc: Record the main function in the session in resolve3
This commit is contained in:
parent
1c2843c8ad
commit
db8d9ddcbb
1 changed files with 25 additions and 0 deletions
|
@ -380,6 +380,17 @@ class Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pure fn is_crate_root(module: @Module) -> bool {
|
||||||
|
alt module.def_id {
|
||||||
|
none => {
|
||||||
|
ret false;
|
||||||
|
}
|
||||||
|
some(def_id) => {
|
||||||
|
ret def_id.crate == 0 && def_id.node == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// XXX: This is a workaround due to is_none in the standard library mistakenly
|
// XXX: This is a workaround due to is_none in the standard library mistakenly
|
||||||
// requiring a T:copy.
|
// requiring a T:copy.
|
||||||
|
|
||||||
|
@ -2802,6 +2813,20 @@ class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
item_fn(fn_decl, ty_params, block) {
|
item_fn(fn_decl, ty_params, block) {
|
||||||
|
// If this is the main function, we must record it in the
|
||||||
|
// session.
|
||||||
|
//
|
||||||
|
// For speed, we put the string comparison last in this chain
|
||||||
|
// of conditionals.
|
||||||
|
|
||||||
|
if !self.session.building_library &&
|
||||||
|
is_none(self.session.main_fn) &&
|
||||||
|
is_crate_root(self.current_module) &&
|
||||||
|
str::eq(*item.ident, "main") {
|
||||||
|
|
||||||
|
self.session.main_fn = some((item.id, item.span));
|
||||||
|
}
|
||||||
|
|
||||||
self.resolve_function(NormalRibKind,
|
self.resolve_function(NormalRibKind,
|
||||||
some(@fn_decl),
|
some(@fn_decl),
|
||||||
HasTypeParameters(&ty_params,
|
HasTypeParameters(&ty_params,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue