@@ -55,7 +55,9 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
55
55
}
56
56
}
57
57
58
- pub fn find_entry_point ( session : & Session , hir_map : & hir_map:: Map ) {
58
+ pub fn find_entry_point ( session : & Session ,
59
+ hir_map : & hir_map:: Map ,
60
+ crate_name : & str ) {
59
61
let any_exe = session. crate_types . borrow ( ) . iter ( ) . any ( |ty| {
60
62
* ty == config:: CrateTypeExecutable
61
63
} ) ;
@@ -81,7 +83,7 @@ pub fn find_entry_point(session: &Session, hir_map: &hir_map::Map) {
81
83
82
84
hir_map. krate ( ) . visit_all_item_likes ( & mut ctxt) ;
83
85
84
- configure_main ( & mut ctxt) ;
86
+ configure_main ( & mut ctxt, crate_name ) ;
85
87
}
86
88
87
89
// Beware, this is duplicated in libsyntax/entry.rs, make sure to keep
@@ -150,7 +152,7 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
150
152
}
151
153
}
152
154
153
- fn configure_main ( this : & mut EntryContext ) {
155
+ fn configure_main ( this : & mut EntryContext , crate_name : & str ) {
154
156
if this. start_fn . is_some ( ) {
155
157
* this. session . entry_fn . borrow_mut ( ) = this. start_fn ;
156
158
this. session . entry_type . set ( Some ( config:: EntryStart ) ) ;
@@ -162,7 +164,8 @@ fn configure_main(this: &mut EntryContext) {
162
164
this. session . entry_type . set ( Some ( config:: EntryMain ) ) ;
163
165
} else {
164
166
// No main function
165
- let mut err = struct_err ! ( this. session, E0601 , "main function not found" ) ;
167
+ let mut err = struct_err ! ( this. session, E0601 ,
168
+ "`main` function not found in crate `{}`" , crate_name) ;
166
169
if !this. non_main_fns . is_empty ( ) {
167
170
// There were some functions named 'main' though. Try to give the user a hint.
168
171
err. note ( "the main function must be defined at the crate level \
@@ -175,6 +178,9 @@ fn configure_main(this: &mut EntryContext) {
175
178
err. emit ( ) ;
176
179
this. session . abort_if_errors ( ) ;
177
180
} else {
181
+ if let Some ( ref filename) = this. session . local_crate_source_file {
182
+ err. note ( & format ! ( "consider adding a `main` function to `{}`" , filename. display( ) ) ) ;
183
+ }
178
184
if this. session . teach ( & err. get_code ( ) . unwrap ( ) ) {
179
185
err. note ( "If you don't know the basics of Rust, you can go look to the Rust Book \
180
186
to get started: https://doc.rust-lang.org/book/") ;
0 commit comments