diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-10-07 09:45:31 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-10-07 10:41:40 +0200 |
| commit | 8db71530f55d21b9b5d076ac24242eb74e2f96bd (patch) | |
| tree | 935388061c1d3240db844f829bc783cf1db959f7 /src/comp/middle | |
| parent | 2ff89469d43a3da326d7da50e4a97fb9c0ba359b (diff) | |
| download | rust-8db71530f55d21b9b5d076ac24242eb74e2f96bd.tar.gz rust-8db71530f55d21b9b5d076ac24242eb74e2f96bd.zip | |
Forbid passing dynamically-sized types by value
Issue #1008
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/alias.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/comp/middle/alias.rs b/src/comp/middle/alias.rs index 5d9d736f209..27021c2a208 100644 --- a/src/comp/middle/alias.rs +++ b/src/comp/middle/alias.rs @@ -57,9 +57,18 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> copy_map { ret cx.copy_map; } -fn visit_fn(cx: @ctx, f: ast::_fn, _tp: [ast::ty_param], _sp: span, - _name: fn_ident, _id: ast::node_id, sc: scope, v: vt<scope>) { +fn visit_fn(cx: @ctx, f: ast::_fn, _tp: [ast::ty_param], sp: span, + _name: fn_ident, id: ast::node_id, sc: scope, v: vt<scope>) { visit::visit_fn_decl(f.decl, sc, v); + let args = ty::ty_fn_args(cx.tcx, ty::node_id_to_type(cx.tcx, id)); + for arg in args { + if arg.mode == ast::by_val && + ty::type_has_dynamic_size(cx.tcx, arg.ty) { + cx.tcx.sess.span_err + (sp, "can not pass a dynamically-sized type by value"); + } + } + let bs = alt f.proto { // Blocks need to obey any restrictions from the enclosing scope. ast::proto_block. | ast::proto_closure. { sc.bs } |
