diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-02-25 11:06:01 -0800 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-02-25 11:06:01 -0800 |
| commit | c28c258f915f0ab46a51519a2b79bd42af383891 (patch) | |
| tree | 92b8a15e3b9077a38ead8d9bad6b51ec59f35e7d | |
| parent | 13781f3d8dbc966b2edc5d10747a62378d616287 (diff) | |
| download | rust-c28c258f915f0ab46a51519a2b79bd42af383891.tar.gz rust-c28c258f915f0ab46a51519a2b79bd42af383891.zip | |
Disallow type parameters in the main() function
Closes #1900
| -rw-r--r-- | src/comp/middle/typeck.rs | 13 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-1900.rs | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 0343c2c102f..2fcafb9cafb 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -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); diff --git a/src/test/compile-fail/issue-1900.rs b/src/test/compile-fail/issue-1900.rs new file mode 100644 index 00000000000..7b20b69b2cd --- /dev/null +++ b/src/test/compile-fail/issue-1900.rs @@ -0,0 +1,2 @@ +// error-pattern: main function is not allowed to have type parameters +fn main<T>() { } \ No newline at end of file |
