Skip to content

Commit 664d71f

Browse files
committed
Improve a typechecker error message (wrong type for main())
As per #1903, state what type is expected for main(). Closes #1903
1 parent fde4c1e commit 664d71f

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

Diff for: src/rustc/middle/typeck.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3122,10 +3122,11 @@ fn check_main_fn_ty(tcx: ty::ctxt, main_id: ast::node_id, main_span: span) {
31223122
ok &= num_args == 0u || num_args == 1u &&
31233123
arg_is_argv_ty(tcx, inputs[0]);
31243124
if !ok {
3125-
tcx.sess.span_err(main_span,
3126-
"wrong type in main function: found `" +
3127-
ty_to_str(tcx, main_t) + "`");
3128-
}
3125+
tcx.sess.span_err(main_span,
3126+
#fmt("Wrong type in main function: found `%s`, \
3127+
expecting `native fn([str]) -> ()` or `native fn() -> ()`",
3128+
ty_to_str(tcx, main_t)));
3129+
}
31293130
}
31303131
_ {
31313132
tcx.sess.span_bug(main_span,

Diff for: src/test/compile-fail/bad-main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// error-pattern:wrong type in main function
1+
// error-pattern:expecting `native fn([str])
22

33
fn main(x: int) { }

Diff for: src/test/compile-fail/main-wrong-type-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fn main() -> char {
2-
//!^ ERROR wrong type in main function: found `native fn() -> char`
2+
//!^ ERROR Wrong type in main function: found `native fn() -> char`
33
}

Diff for: src/test/compile-fail/main-wrong-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fn main(foo: {x: int, y: int}) {
2-
//!^ ERROR wrong type in main function: found `native fn({x: int,y: int})`
2+
//!^ ERROR Wrong type in main function: found `native fn({x: int,y: int})`
33
}

0 commit comments

Comments
 (0)