File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -380,6 +380,17 @@ class Module {
380
380
}
381
381
}
382
382
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
+
383
394
// XXX: This is a workaround due to is_none in the standard library mistakenly
384
395
// requiring a T:copy.
385
396
@@ -2802,6 +2813,20 @@ class Resolver {
2802
2813
}
2803
2814
2804
2815
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
+
2805
2830
self . resolve_function ( NormalRibKind ,
2806
2831
some ( @fn_decl) ,
2807
2832
HasTypeParameters ( & ty_params,
You can’t perform that action at this time.
0 commit comments