Skip to content

Commit 8db7153

Browse files
committed
Forbid passing dynamically-sized types by value
Issue #1008
1 parent 2ff8946 commit 8db7153

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/comp/middle/alias.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,18 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> copy_map {
5757
ret cx.copy_map;
5858
}
5959

60-
fn visit_fn(cx: @ctx, f: ast::_fn, _tp: [ast::ty_param], _sp: span,
61-
_name: fn_ident, _id: ast::node_id, sc: scope, v: vt<scope>) {
60+
fn visit_fn(cx: @ctx, f: ast::_fn, _tp: [ast::ty_param], sp: span,
61+
_name: fn_ident, id: ast::node_id, sc: scope, v: vt<scope>) {
6262
visit::visit_fn_decl(f.decl, sc, v);
63+
let args = ty::ty_fn_args(cx.tcx, ty::node_id_to_type(cx.tcx, id));
64+
for arg in args {
65+
if arg.mode == ast::by_val &&
66+
ty::type_has_dynamic_size(cx.tcx, arg.ty) {
67+
cx.tcx.sess.span_err
68+
(sp, "can not pass a dynamically-sized type by value");
69+
}
70+
}
71+
6372
let bs = alt f.proto {
6473
// Blocks need to obey any restrictions from the enclosing scope.
6574
ast::proto_block. | ast::proto_closure. { sc.bs }

0 commit comments

Comments
 (0)