Skip to content

Commit

Permalink
Add crate name to "main function not found" error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Mar 14, 2018
1 parent 11d9959 commit b4b7ccb
Show file tree
Hide file tree
Showing 26 changed files with 32 additions and 29 deletions.
11 changes: 7 additions & 4 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
}
}

pub fn find_entry_point(session: &Session, hir_map: &hir_map::Map) {
pub fn find_entry_point(session: &Session,
hir_map: &hir_map::Map,
crate_name: &str) {
let any_exe = session.crate_types.borrow().iter().any(|ty| {
*ty == config::CrateTypeExecutable
});
Expand All @@ -81,7 +83,7 @@ pub fn find_entry_point(session: &Session, hir_map: &hir_map::Map) {

hir_map.krate().visit_all_item_likes(&mut ctxt);

configure_main(&mut ctxt);
configure_main(&mut ctxt, crate_name);
}

// Beware, this is duplicated in libsyntax/entry.rs, make sure to keep
Expand Down Expand Up @@ -150,7 +152,7 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
}
}

fn configure_main(this: &mut EntryContext) {
fn configure_main(this: &mut EntryContext, crate_name: &str) {
if this.start_fn.is_some() {
*this.session.entry_fn.borrow_mut() = this.start_fn;
this.session.entry_type.set(Some(config::EntryStart));
Expand All @@ -162,7 +164,8 @@ fn configure_main(this: &mut EntryContext) {
this.session.entry_type.set(Some(config::EntryMain));
} else {
// No main function
let mut err = struct_err!(this.session, E0601, "main function not found");
let mut err = struct_err!(this.session, E0601,
"main function not found in crate {}", crate_name);
if !this.non_main_fns.is_empty() {
// There were some functions named 'main' though. Try to give the user a hint.
err.note("the main function must be defined at the crate level \
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate,

time(sess,
"looking for entry point",
|| middle::entry::find_entry_point(sess, &hir_map));
|| middle::entry::find_entry_point(sess, &hir_map, name));

sess.plugin_registrar_fn.set(time(sess, "looking for plugin registrar", || {
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0522.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate E0522

error[E0522]: definition of an unknown language item: `cookie`
--> $DIR/E0522.rs:13:1
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/feature-gate-i128_type2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LL | let x: u128 = 0; //~ ERROR 128-bit type is unstable
|
= help: add #![feature(i128_type)] to the crate attributes to enable

error[E0601]: main function not found
error[E0601]: main function not found in crate feature_gate_i128_type2

error[E0658]: repr with 128-bit type is unstable (see issue #35118)
--> $DIR/feature-gate-i128_type2.rs:30:1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate issue_43106_gating_of_bench

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate issue_43106_gating_of_inline

error[E0518]: attribute should be applied to function
--> $DIR/issue-43106-gating-of-inline.rs:21:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | #![macro_escape]
|
= help: consider an outer attribute, #[macro_use] mod ...

error[E0601]: main function not found
error[E0601]: main function not found in crate issue_43106_gating_of_macro_escape

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ error: the `#[proc_macro_derive]` attribute may only be used on bare functions
LL | #[proc_macro_derive = "2500"] impl S { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0601]: main function not found
error[E0601]: main function not found in crate issue_43106_gating_of_proc_macro_derive

error: aborting due to 7 previous errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate issue_43106_gating_of_rustc_deprecated

error: stability attributes may not be used outside of the standard library
--> $DIR/issue-43106-gating-of-rustc_deprecated.rs:17:1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate issue_43106_gating_of_stable

error: stability attributes may not be used outside of the standard library
--> $DIR/issue-43106-gating-of-stable.rs:17:1
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/feature-gate/issue-43106-gating-of-test.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate issue_43106_gating_of_test

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate issue_43106_gating_of_unstable

error: stability attributes may not be used outside of the standard library
--> $DIR/issue-43106-gating-of-unstable.rs:17:1
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generator/yield-in-const.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate yield_in_const

error[E0627]: yield statement outside of generator literal
--> $DIR/yield-in-const.rs:13:17
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generator/yield-in-static.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate yield_in_static

error[E0627]: yield statement outside of generator literal
--> $DIR/yield-in-static.rs:13:18
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/imports/macro-paths.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LL | | }
| |_^
= note: macro-expanded items do not shadow when used in a macro invocation path

error[E0601]: main function not found
error[E0601]: main function not found in crate macro_paths

error: aborting due to 3 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/imports/macros.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ LL | use two_macros::m;
| ^^^^^^^^^^^^^
= note: macro-expanded macro imports do not shadow

error[E0601]: main function not found
error[E0601]: main function not found in crate macros

error: aborting due to 4 previous errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate mismatched_trait_impl_2

error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in generic type due to conflicting requirements
--> $DIR/mismatched_trait_impl-2.rs:18:5
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issue-47706-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate issue_47706_trait

error[E0593]: function is expected to take a single 0-tuple as argument, but it takes 2 distinct arguments
--> $DIR/issue-47706-trait.rs:13:20
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/main-wrong-location.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate main_wrong_location
|
= note: the main function must be defined at the crate level but you have one or more functions named 'main' that are not defined at the crate level. Either move the definition or attach the `#[main]` attribute to override this behavior.
note: here is a function named 'main'
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/missing-items/m2.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0601]: main function not found
error[E0601]: main function not found in crate m2

error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`
--> $DIR/m2.rs:19:1
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-14254.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ error[E0425]: cannot find value `bah` in this scope
LL | bah;
| ^^^ help: try: `Self::bah`

error[E0601]: main function not found
error[E0601]: main function not found in crate issue_14254

error: aborting due to 25 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-21221-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ help: possible candidate is found in another module, you can import it into scop
LL | use foo::bar::T;
|

error[E0601]: main function not found
error[E0601]: main function not found in crate issue_21221_2

error: cannot continue compilation due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ LL | a::b()
| |
| did you mean `I`?

error[E0601]: main function not found
error[E0601]: main function not found in crate suggest_path_instead_of_mod_dot_item

error: aborting due to 10 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/span/issue-35987.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ help: possible better candidate is found in another module, you can import it in
LL | use std::ops::Add;
|

error[E0601]: main function not found
error[E0601]: main function not found in crate issue_35987

error: cannot continue compilation due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/token/issue-10636-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ error: expected expression, found `)`
LL | } //~ ERROR: incorrect close delimiter
| ^ expected expression

error[E0601]: main function not found
error[E0601]: main function not found in crate issue_10636_2

error: aborting due to 4 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/token/issue-41155.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ error[E0412]: cannot find type `S` in this scope
LL | impl S { //~ ERROR cannot find type
| ^ not found in this scope

error[E0601]: main function not found
error[E0601]: main function not found in crate issue_41155

error: aborting due to 3 previous errors

Expand Down

0 comments on commit b4b7ccb

Please sign in to comment.