From e7c3fb90eeda06c6ac2bed523ce8fa358d48505b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 4 Jan 2017 12:56:33 +0100 Subject: Add a distinct error code and description for "main function has wrong type" --- src/librustc/diagnostics.rs | 24 ++++++++++++++++++++++++ src/librustc/infer/error_reporting.rs | 7 +++++-- src/test/compile-fail/E0308-3.rs | 11 ----------- src/test/compile-fail/E0579.rs | 11 +++++++++++ src/test/compile-fail/bad-main.rs | 2 +- src/test/compile-fail/extern-main-fn.rs | 2 +- src/test/compile-fail/main-wrong-type-2.rs | 2 +- src/test/compile-fail/main-wrong-type.rs | 2 +- 8 files changed, 44 insertions(+), 17 deletions(-) delete mode 100644 src/test/compile-fail/E0308-3.rs create mode 100644 src/test/compile-fail/E0579.rs diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 0d180e6ad76..6d94e1d7259 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1694,6 +1694,30 @@ To understand better how closures work in Rust, read: https://doc.rust-lang.org/book/closures.html "##, +E0579: r##" +The `main` function was incorrectly declared. + +Erroneous code example: + +```compile_fail,E0579 +fn main() -> i32 { // error: main function has wrong type + 0 +} +``` + +The `main` function prototype should never take arguments or return type. +Example: + +``` +fn main() { + // your code +} +``` + +If you want to get command-line arguments, use `std::env::args`. To exit with a +specified exit code, use `std::process::exit`. +"##, + } diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index 095d2a78a94..2bed8148b9f 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -629,10 +629,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let mut diag = match trace.cause.code { ObligationCauseCode::IfExpressionWithNoElse => { struct_span_err!(self.tcx.sess, span, E0317, "{}", failure_str) - }, + } + ObligationCauseCode::MainFunctionType => { + struct_span_err!(self.tcx.sess, span, E0579, "{}", failure_str) + } _ => { struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str) - }, + } }; self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr); diag diff --git a/src/test/compile-fail/E0308-3.rs b/src/test/compile-fail/E0308-3.rs deleted file mode 100644 index d7dca056f3f..00000000000 --- a/src/test/compile-fail/E0308-3.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() -> i32 { 0 } //~ ERROR E0308 diff --git a/src/test/compile-fail/E0579.rs b/src/test/compile-fail/E0579.rs new file mode 100644 index 00000000000..beb6c792fa1 --- /dev/null +++ b/src/test/compile-fail/E0579.rs @@ -0,0 +1,11 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() -> i32 { 0 } //~ ERROR E0579 diff --git a/src/test/compile-fail/bad-main.rs b/src/test/compile-fail/bad-main.rs index 1253f7569e7..6cd033da4bd 100644 --- a/src/test/compile-fail/bad-main.rs +++ b/src/test/compile-fail/bad-main.rs @@ -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 [E0579] diff --git a/src/test/compile-fail/extern-main-fn.rs b/src/test/compile-fail/extern-main-fn.rs index 11f299acefa..479b3e532c6 100644 --- a/src/test/compile-fail/extern-main-fn.rs +++ b/src/test/compile-fail/extern-main-fn.rs @@ -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 [E0579] diff --git a/src/test/compile-fail/main-wrong-type-2.rs b/src/test/compile-fail/main-wrong-type-2.rs index 2878cbc7fc1..da1455403c2 100644 --- a/src/test/compile-fail/main-wrong-type-2.rs +++ b/src/test/compile-fail/main-wrong-type-2.rs @@ -9,6 +9,6 @@ // except according to those terms. fn main() -> char { -//~^ ERROR: main function has wrong type +//~^ ERROR: main function has wrong type [E0579] ' ' } diff --git a/src/test/compile-fail/main-wrong-type.rs b/src/test/compile-fail/main-wrong-type.rs index 431b855d517..dc517775035 100644 --- a/src/test/compile-fail/main-wrong-type.rs +++ b/src/test/compile-fail/main-wrong-type.rs @@ -14,5 +14,5 @@ struct S { } fn main(foo: S) { -//~^ ERROR: main function has wrong type +//~^ ERROR: main function has wrong type [E0579] } -- cgit 1.4.1-3-g733a5 From 97b9c8b8d37ec21212d9c54ae510eae0220fbf7e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 26 Jan 2017 11:17:17 +0100 Subject: Update error code number --- src/librustc/diagnostics.rs | 4 ++-- src/librustc/infer/error_reporting.rs | 2 +- src/test/compile-fail/E0579.rs | 11 ----------- src/test/compile-fail/E0580.rs | 11 +++++++++++ src/test/compile-fail/bad-main.rs | 2 +- src/test/compile-fail/extern-main-fn.rs | 2 +- src/test/compile-fail/main-wrong-type-2.rs | 2 +- src/test/compile-fail/main-wrong-type.rs | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 src/test/compile-fail/E0579.rs create mode 100644 src/test/compile-fail/E0580.rs diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 6d94e1d7259..2878ff5e284 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1694,12 +1694,12 @@ To understand better how closures work in Rust, read: https://doc.rust-lang.org/book/closures.html "##, -E0579: r##" +E0580: r##" The `main` function was incorrectly declared. Erroneous code example: -```compile_fail,E0579 +```compile_fail,E0580 fn main() -> i32 { // error: main function has wrong type 0 } diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index 2bed8148b9f..d859a8b44db 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -631,7 +631,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { struct_span_err!(self.tcx.sess, span, E0317, "{}", failure_str) } ObligationCauseCode::MainFunctionType => { - struct_span_err!(self.tcx.sess, span, E0579, "{}", failure_str) + struct_span_err!(self.tcx.sess, span, E0580, "{}", failure_str) } _ => { struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str) diff --git a/src/test/compile-fail/E0579.rs b/src/test/compile-fail/E0579.rs deleted file mode 100644 index beb6c792fa1..00000000000 --- a/src/test/compile-fail/E0579.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() -> i32 { 0 } //~ ERROR E0579 diff --git a/src/test/compile-fail/E0580.rs b/src/test/compile-fail/E0580.rs new file mode 100644 index 00000000000..a2ef7da78a8 --- /dev/null +++ b/src/test/compile-fail/E0580.rs @@ -0,0 +1,11 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() -> i32 { 0 } //~ ERROR E0580 diff --git a/src/test/compile-fail/bad-main.rs b/src/test/compile-fail/bad-main.rs index 6cd033da4bd..b73b4a6af6e 100644 --- a/src/test/compile-fail/bad-main.rs +++ b/src/test/compile-fail/bad-main.rs @@ -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 [E0579] +fn main(x: isize) { } //~ ERROR: main function has wrong type [E0580] diff --git a/src/test/compile-fail/extern-main-fn.rs b/src/test/compile-fail/extern-main-fn.rs index 479b3e532c6..d9bdb4ecd04 100644 --- a/src/test/compile-fail/extern-main-fn.rs +++ b/src/test/compile-fail/extern-main-fn.rs @@ -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 [E0579] +extern fn main() {} //~ ERROR: main function has wrong type [E0580] diff --git a/src/test/compile-fail/main-wrong-type-2.rs b/src/test/compile-fail/main-wrong-type-2.rs index da1455403c2..9d74d1a9049 100644 --- a/src/test/compile-fail/main-wrong-type-2.rs +++ b/src/test/compile-fail/main-wrong-type-2.rs @@ -9,6 +9,6 @@ // except according to those terms. fn main() -> char { -//~^ ERROR: main function has wrong type [E0579] +//~^ ERROR: main function has wrong type [E0580] ' ' } diff --git a/src/test/compile-fail/main-wrong-type.rs b/src/test/compile-fail/main-wrong-type.rs index dc517775035..402cd3a2d31 100644 --- a/src/test/compile-fail/main-wrong-type.rs +++ b/src/test/compile-fail/main-wrong-type.rs @@ -14,5 +14,5 @@ struct S { } fn main(foo: S) { -//~^ ERROR: main function has wrong type [E0579] +//~^ ERROR: main function has wrong type [E0580] } -- cgit 1.4.1-3-g733a5