Skip to content

Commit b4b7ccb

Browse files
committed
Add crate name to "main function not found" error message.
Fixes rust-lang#44798 and rust-lang/cargo#4948.
1 parent 11d9959 commit b4b7ccb

26 files changed

+32
-29
lines changed

src/librustc/middle/entry.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
5555
}
5656
}
5757

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) {
5961
let any_exe = session.crate_types.borrow().iter().any(|ty| {
6062
*ty == config::CrateTypeExecutable
6163
});
@@ -81,7 +83,7 @@ pub fn find_entry_point(session: &Session, hir_map: &hir_map::Map) {
8183

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

84-
configure_main(&mut ctxt);
86+
configure_main(&mut ctxt, crate_name);
8587
}
8688

8789
// 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) {
150152
}
151153
}
152154

153-
fn configure_main(this: &mut EntryContext) {
155+
fn configure_main(this: &mut EntryContext, crate_name: &str) {
154156
if this.start_fn.is_some() {
155157
*this.session.entry_fn.borrow_mut() = this.start_fn;
156158
this.session.entry_type.set(Some(config::EntryStart));
@@ -162,7 +164,8 @@ fn configure_main(this: &mut EntryContext) {
162164
this.session.entry_type.set(Some(config::EntryMain));
163165
} else {
164166
// 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);
166169
if !this.non_main_fns.is_empty() {
167170
// There were some functions named 'main' though. Try to give the user a hint.
168171
err.note("the main function must be defined at the crate level \

src/librustc_driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate,
979979

980980
time(sess,
981981
"looking for entry point",
982-
|| middle::entry::find_entry_point(sess, &hir_map));
982+
|| middle::entry::find_entry_point(sess, &hir_map, name));
983983

984984
sess.plugin_registrar_fn.set(time(sess, "looking for plugin registrar", || {
985985
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)

src/test/ui/error-codes/E0522.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate E0522
22

33
error[E0522]: definition of an unknown language item: `cookie`
44
--> $DIR/E0522.rs:13:1

src/test/ui/feature-gate-i128_type2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | let x: u128 = 0; //~ ERROR 128-bit type is unstable
3030
|
3131
= help: add #![feature(i128_type)] to the crate attributes to enable
3232

33-
error[E0601]: main function not found
33+
error[E0601]: main function not found in crate feature_gate_i128_type2
3434

3535
error[E0658]: repr with 128-bit type is unstable (see issue #35118)
3636
--> $DIR/feature-gate-i128_type2.rs:30:1

src/test/ui/feature-gate/issue-43106-gating-of-bench.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate issue_43106_gating_of_bench
22

33
error: aborting due to previous error
44

src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate issue_43106_gating_of_inline
22

33
error[E0518]: attribute should be applied to function
44
--> $DIR/issue-43106-gating-of-inline.rs:21:1

src/test/ui/feature-gate/issue-43106-gating-of-macro_escape.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | #![macro_escape]
66
|
77
= help: consider an outer attribute, #[macro_use] mod ...
88

9-
error[E0601]: main function not found
9+
error[E0601]: main function not found in crate issue_43106_gating_of_macro_escape
1010

1111
error: aborting due to previous error
1212

src/test/ui/feature-gate/issue-43106-gating-of-proc_macro_derive.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ error: the `#[proc_macro_derive]` attribute may only be used on bare functions
3434
LL | #[proc_macro_derive = "2500"] impl S { }
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

37-
error[E0601]: main function not found
37+
error[E0601]: main function not found in crate issue_43106_gating_of_proc_macro_derive
3838

3939
error: aborting due to 7 previous errors
4040

src/test/ui/feature-gate/issue-43106-gating-of-rustc_deprecated.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate issue_43106_gating_of_rustc_deprecated
22

33
error: stability attributes may not be used outside of the standard library
44
--> $DIR/issue-43106-gating-of-rustc_deprecated.rs:17:1

src/test/ui/feature-gate/issue-43106-gating-of-stable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate issue_43106_gating_of_stable
22

33
error: stability attributes may not be used outside of the standard library
44
--> $DIR/issue-43106-gating-of-stable.rs:17:1

src/test/ui/feature-gate/issue-43106-gating-of-test.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate issue_43106_gating_of_test
22

33
error: aborting due to previous error
44

src/test/ui/feature-gate/issue-43106-gating-of-unstable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate issue_43106_gating_of_unstable
22

33
error: stability attributes may not be used outside of the standard library
44
--> $DIR/issue-43106-gating-of-unstable.rs:17:1

src/test/ui/generator/yield-in-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate yield_in_const
22

33
error[E0627]: yield statement outside of generator literal
44
--> $DIR/yield-in-const.rs:13:17

src/test/ui/generator/yield-in-static.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate yield_in_static
22

33
error[E0627]: yield statement outside of generator literal
44
--> $DIR/yield-in-static.rs:13:18

src/test/ui/imports/macro-paths.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ LL | | }
3636
| |_^
3737
= note: macro-expanded items do not shadow when used in a macro invocation path
3838

39-
error[E0601]: main function not found
39+
error[E0601]: main function not found in crate macro_paths
4040

4141
error: aborting due to 3 previous errors
4242

src/test/ui/imports/macros.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ LL | use two_macros::m;
5151
| ^^^^^^^^^^^^^
5252
= note: macro-expanded macro imports do not shadow
5353

54-
error[E0601]: main function not found
54+
error[E0601]: main function not found in crate macros
5555

5656
error: aborting due to 4 previous errors
5757

src/test/ui/in-band-lifetimes/mismatched_trait_impl-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate mismatched_trait_impl_2
22

33
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in generic type due to conflicting requirements
44
--> $DIR/mismatched_trait_impl-2.rs:18:5

src/test/ui/issue-47706-trait.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate issue_47706_trait
22

33
error[E0593]: function is expected to take a single 0-tuple as argument, but it takes 2 distinct arguments
44
--> $DIR/issue-47706-trait.rs:13:20

src/test/ui/main-wrong-location.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate main_wrong_location
22
|
33
= 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.
44
note: here is a function named 'main'

src/test/ui/missing-items/m2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0601]: main function not found
1+
error[E0601]: main function not found in crate m2
22

33
error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`
44
--> $DIR/m2.rs:19:1

src/test/ui/resolve/issue-14254.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ error[E0425]: cannot find value `bah` in this scope
142142
LL | bah;
143143
| ^^^ help: try: `Self::bah`
144144

145-
error[E0601]: main function not found
145+
error[E0601]: main function not found in crate issue_14254
146146

147147
error: aborting due to 25 previous errors
148148

src/test/ui/resolve/issue-21221-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ help: possible candidate is found in another module, you can import it into scop
88
LL | use foo::bar::T;
99
|
1010

11-
error[E0601]: main function not found
11+
error[E0601]: main function not found in crate issue_21221_2
1212

1313
error: cannot continue compilation due to previous error
1414

src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ LL | a::b()
7272
| |
7373
| did you mean `I`?
7474

75-
error[E0601]: main function not found
75+
error[E0601]: main function not found in crate suggest_path_instead_of_mod_dot_item
7676

7777
error: aborting due to 10 previous errors
7878

src/test/ui/span/issue-35987.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ help: possible better candidate is found in another module, you can import it in
88
LL | use std::ops::Add;
99
|
1010

11-
error[E0601]: main function not found
11+
error[E0601]: main function not found in crate issue_35987
1212

1313
error: cannot continue compilation due to previous error
1414

src/test/ui/token/issue-10636-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error: expected expression, found `)`
2222
LL | } //~ ERROR: incorrect close delimiter
2323
| ^ expected expression
2424

25-
error[E0601]: main function not found
25+
error[E0601]: main function not found in crate issue_10636_2
2626

2727
error: aborting due to 4 previous errors
2828

src/test/ui/token/issue-41155.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0412]: cannot find type `S` in this scope
1212
LL | impl S { //~ ERROR cannot find type
1313
| ^ not found in this scope
1414

15-
error[E0601]: main function not found
15+
error[E0601]: main function not found in crate issue_41155
1616

1717
error: aborting due to 3 previous errors
1818

0 commit comments

Comments
 (0)