Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a distinct error code and description for "main function has wrong type" #37242

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,14 @@ error. To resolve it, add an `else` block having the same type as the `if`
block.
"##,

E0330: r##"
The `main` function is required to have the signature `fn main() { ... }`, with
no arguments and a return type of `()`.

To access command-line arguments, use `std::env::args`. To terminate the process
with a specified exit code, use `std::process::exit`.
"##,

E0398: r##"
In Rust 1.3, the default object lifetime bounds are expected to change, as
described in RFC #1156 [1]. You are getting a warning because the compiler
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
TypeOrigin::IfExpressionWithNoElse(_) => {
struct_span_err!(self.tcx.sess, span, E0317, "{}", failure_str)
},
TypeOrigin::MainFunctionType(_) => {
struct_span_err!(self.tcx.sess, span, E0330, "{}", failure_str)
},
_ => {
struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str)
},
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/E0308-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() -> i32 { 0 } //~ ERROR E0308
fn main() -> i32 { 0 } //~ ERROR E0330
2 changes: 1 addition & 1 deletion src/test/compile-fail/bad-main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main(x: isize) { } //~ ERROR: main function has wrong type
fn main(x: isize) { } //~ ERROR: main function has wrong type [E0330]
2 changes: 1 addition & 1 deletion src/test/compile-fail/extern-main-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern fn main() {} //~ ERROR: main function has wrong type
extern fn main() {} //~ ERROR: main function has wrong type [E0330]
2 changes: 1 addition & 1 deletion src/test/compile-fail/main-wrong-type-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
// except according to those terms.

fn main() -> char {
//~^ ERROR: main function has wrong type
//~^ ERROR: main function has wrong type [E0330]
' '
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/main-wrong-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ struct S {
}

fn main(foo: S) {
//~^ ERROR: main function has wrong type
//~^ ERROR: main function has wrong type [E0330]
}