Add crate name to "main function not found" error message.
Fixes #44798 and rust-lang/cargo#4948.
This commit is contained in:
parent
11d9959641
commit
b4b7ccbd1c
@ -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
|
||||
});
|
||||
@ -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
|
||||
@ -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));
|
||||
@ -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 \
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user