Auto merge of #38819 - GuillaumeGomez:main_func_wrong_type, r=GuillaumeGomez
Add a distinct error code and description for "main function has wron… …g type"
This commit is contained in:
commit
07fe04c1e2
@ -1694,6 +1694,30 @@ fn main() {
|
|||||||
https://doc.rust-lang.org/book/closures.html
|
https://doc.rust-lang.org/book/closures.html
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
|
E0580: r##"
|
||||||
|
The `main` function was incorrectly declared.
|
||||||
|
|
||||||
|
Erroneous code example:
|
||||||
|
|
||||||
|
```compile_fail,E0580
|
||||||
|
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`.
|
||||||
|
"##,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -629,10 +629,13 @@ pub fn report_and_explain_type_error(&self,
|
|||||||
let mut diag = match trace.cause.code {
|
let mut diag = match trace.cause.code {
|
||||||
ObligationCauseCode::IfExpressionWithNoElse => {
|
ObligationCauseCode::IfExpressionWithNoElse => {
|
||||||
struct_span_err!(self.tcx.sess, span, E0317, "{}", failure_str)
|
struct_span_err!(self.tcx.sess, span, E0317, "{}", failure_str)
|
||||||
},
|
}
|
||||||
|
ObligationCauseCode::MainFunctionType => {
|
||||||
|
struct_span_err!(self.tcx.sess, span, E0580, "{}", failure_str)
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
struct_span_err!(self.tcx.sess, span, E0308, "{}", 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);
|
self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr);
|
||||||
diag
|
diag
|
||||||
|
@ -8,4 +8,4 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn main() -> i32 { 0 } //~ ERROR E0308
|
fn main() -> i32 { 0 } //~ ERROR E0580
|
@ -8,4 +8,4 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// 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 [E0580]
|
||||||
|
@ -8,4 +8,4 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
extern fn main() {} //~ ERROR: main function has wrong type
|
extern fn main() {} //~ ERROR: main function has wrong type [E0580]
|
||||||
|
@ -9,6 +9,6 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn main() -> char {
|
fn main() -> char {
|
||||||
//~^ ERROR: main function has wrong type
|
//~^ ERROR: main function has wrong type [E0580]
|
||||||
' '
|
' '
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,5 @@ struct S {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main(foo: S) {
|
fn main(foo: S) {
|
||||||
//~^ ERROR: main function has wrong type
|
//~^ ERROR: main function has wrong type [E0580]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user