@@ -48,9 +48,12 @@ impl<'a> Visitor<()> for EntryContext<'a> {
4848}
4949
5050pub fn find_entry_point ( session : & Session , krate : & Crate , ast_map : & ast_map:: Map ) {
51- if session. building_library . get ( ) {
51+ let any_exe = session. crate_types . borrow ( ) . iter ( ) . any ( |ty| {
52+ * ty == session:: CrateTypeExecutable
53+ } ) ;
54+ if !any_exe {
5255 // No need to find a main function
53- return ;
56+ return
5457 }
5558
5659 // If the user wants no main function at all, then stop here.
@@ -132,18 +135,16 @@ fn configure_main(this: &mut EntryContext) {
132135 * this. session . entry_fn . borrow_mut ( ) = this. main_fn ;
133136 this. session . entry_type . set ( Some ( session:: EntryMain ) ) ;
134137 } else {
135- if !this. session . building_library . get ( ) {
136- // No main function
137- this. session . err ( "main function not found" ) ;
138- if !this. non_main_fns . is_empty ( ) {
139- // There were some functions named 'main' though. Try to give the user a hint.
140- this. session . note ( "the main function must be defined at the crate level \
141- but you have one or more functions named 'main' that are not \
142- defined at the crate level. Either move the definition or \
143- attach the `#[main]` attribute to override this behavior.") ;
144- for & ( _, span) in this. non_main_fns . iter ( ) {
145- this. session . span_note ( span, "here is a function named 'main'" ) ;
146- }
138+ // No main function
139+ this. session . err ( "main function not found" ) ;
140+ if !this. non_main_fns . is_empty ( ) {
141+ // There were some functions named 'main' though. Try to give the user a hint.
142+ this. session . note ( "the main function must be defined at the crate level \
143+ but you have one or more functions named 'main' that are not \
144+ defined at the crate level. Either move the definition or \
145+ attach the `#[main]` attribute to override this behavior.") ;
146+ for & ( _, span) in this. non_main_fns . iter ( ) {
147+ this. session . span_note ( span, "here is a function named 'main'" ) ;
147148 }
148149 this. session . abort_if_errors ( ) ;
149150 }
0 commit comments