Skip to content

Commit b08e6d3

Browse files
committed
Add suggestion where to add main function.
1 parent 6aa4dcb commit b08e6d3

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

src/librustc/middle/entry.rs

+3
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ fn configure_main(this: &mut EntryContext, crate_name: &str) {
178178
err.emit();
179179
this.session.abort_if_errors();
180180
} 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+
}
181184
if this.session.teach(&err.get_code().unwrap()) {
182185
err.note("If you don't know the basics of Rust, you can go look to the Rust Book \
183186
to get started: https://doc.rust-lang.org/book/");

src/test/ui/error-codes/E0601.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test for main function not found.

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

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error[E0601]: main function not found in crate E0601
2+
|
3+
= note: consider adding a main function to $DIR/E0601.rs
4+
5+
error: aborting due to previous error
6+
7+
If you want more information on this error, try using "rustc --explain E0601"

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
error[E0601]: main function not found in crate issue_43106_gating_of_bench
2+
|
3+
= note: consider adding a main function to $DIR/issue-43106-gating-of-bench.rs
24

35
error: aborting due to previous error
46

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
error[E0601]: main function not found in crate issue_43106_gating_of_test
2+
|
3+
= note: consider adding a main function to $DIR/issue-43106-gating-of-test.rs
24

35
error: aborting due to previous error
46

0 commit comments

Comments
 (0)