Skip to content

Commit

Permalink
Add a distinct error code and description for "main function has wron…
Browse files Browse the repository at this point in the history
…g type"
  • Loading branch information
jfirebaugh committed Nov 13, 2016
1 parent 876b761 commit 6bb4b84
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
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/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]
}

0 comments on commit 6bb4b84

Please sign in to comment.