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:
parent
14bac217b0
commit
cb4e99b688
@ -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");
|
||||
}
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
}
|
||||
|
11
src/test/compile-fail/vec-res-add.rs
Normal file
11
src/test/compile-fail/vec-res-add.rs
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user