Skip to content

Commit c28c258

Browse files
committed
Disallow type parameters in the main() function
Closes #1900
1 parent 13781f3 commit c28c258

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/comp/middle/typeck.rs

+13
Original file line numberDiff line numberDiff line change
@@ -3066,6 +3066,19 @@ fn check_main_fn_ty(tcx: ty::ctxt, main_id: ast::node_id, main_span: span) {
30663066
alt ty::get(main_t).struct {
30673067
ty::ty_fn({proto: ast::proto_bare, inputs, output,
30683068
ret_style: ast::return_val, constraints}) {
3069+
alt tcx.items.find(main_id) {
3070+
some(ast_map::node_item(it,_)) {
3071+
alt it.node {
3072+
ast::item_fn(_,ps,_) if vec::is_not_empty(ps) {
3073+
tcx.sess.span_err(main_span,
3074+
"main function is not allowed to have type parameters");
3075+
ret;
3076+
}
3077+
_ {}
3078+
}
3079+
}
3080+
_ {}
3081+
}
30693082
let ok = vec::len(constraints) == 0u;
30703083
ok &= ty::type_is_nil(output);
30713084
let num_args = vec::len(inputs);

src/test/compile-fail/issue-1900.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// error-pattern: main function is not allowed to have type parameters
2+
fn main<T>() { }

0 commit comments

Comments
 (0)