Skip to content

Commit

Permalink
Disallow type parameters in the main() function
Browse files Browse the repository at this point in the history
Closes #1900
  • Loading branch information
catamorphism committed Feb 25, 2012
1 parent 13781f3 commit c28c258
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3066,6 +3066,19 @@ fn check_main_fn_ty(tcx: ty::ctxt, main_id: ast::node_id, main_span: span) {
alt ty::get(main_t).struct {
ty::ty_fn({proto: ast::proto_bare, inputs, output,
ret_style: ast::return_val, constraints}) {
alt tcx.items.find(main_id) {
some(ast_map::node_item(it,_)) {
alt it.node {
ast::item_fn(_,ps,_) if vec::is_not_empty(ps) {
tcx.sess.span_err(main_span,
"main function is not allowed to have type parameters");
ret;
}
_ {}
}
}
_ {}
}
let ok = vec::len(constraints) == 0u;
ok &= ty::type_is_nil(output);
let num_args = vec::len(inputs);
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-1900.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// error-pattern: main function is not allowed to have type parameters
fn main<T>() { }

0 comments on commit c28c258

Please sign in to comment.