Don't allow vectors of pinned kinds

Vectors of pinned kinds can't be safe because most interesting uses of vector
perform copies
This commit is contained in:
Brian Anderson 2011-09-28 14:37:28 -07:00
parent 14bac217b0
commit cb4e99b688
2 changed files with 21 additions and 0 deletions

View File

@ -189,6 +189,9 @@ fn need_shared_or_pinned_ctor(tcx: ty::ctxt, a: @ast::expr, descr: str) {
ast::expr_tup(_) {
true
}
ast::expr_vec(exprs, _) {
true
}
_ { false }
}
}
@ -262,6 +265,13 @@ fn check_expr(tcx: ty::ctxt, e: @ast::expr) {
need_shared_or_pinned_ctor(tcx, expr, "tuple parameter");
}
}
ast::expr_vec(exprs, _) {
// Putting pinned things into vectors is pretty useless since vector
// addition can't work (it's a copy)
for expr in exprs {
need_expr_kind(tcx, expr, ast::kind_shared, "vector element");
}
}
_ { }
}
}

View File

@ -0,0 +1,11 @@
// error-pattern:mismatched kinds
resource r(i: int) {
}
fn main() {
// This can't make sense as it would copy the resources
let i <- [r(0)];
let j <- [r(1)];
let k = i + j;
}