mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 06:35:27 +00:00
handle moves in let initializers and allow moves from unsafe ptrs
Related to issue #2657, but this is not a complete fix.
This commit is contained in:
parent
f9afce319a
commit
60603703ea
@ -47,6 +47,7 @@ fn check_loans(bccx: borrowck_ctxt,
|
||||
mut declared_purity: ast::impure_fn,
|
||||
mut fn_args: @[]});
|
||||
let vt = visit::mk_vt(@{visit_expr: check_loans_in_expr,
|
||||
visit_local: check_loans_in_local,
|
||||
visit_block: check_loans_in_block,
|
||||
visit_fn: check_loans_in_fn
|
||||
with *visit::default_visitor()});
|
||||
@ -419,6 +420,9 @@ impl methods for check_loan_ctxt {
|
||||
// rvalues, I guess.
|
||||
cat_special(sk_static_item) { }
|
||||
|
||||
cat_deref(_, _, unsafe_ptr) {
|
||||
}
|
||||
|
||||
// Nothing else.
|
||||
_ {
|
||||
self.bccx.span_err(
|
||||
@ -542,6 +546,18 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
|
||||
#debug["purity on exit=%?", copy self.declared_purity];
|
||||
}
|
||||
|
||||
fn check_loans_in_local(local: @ast::local,
|
||||
&&self: check_loan_ctxt,
|
||||
vt: visit::vt<check_loan_ctxt>) {
|
||||
alt local.node.init {
|
||||
some({op: ast::init_move, expr: expr}) {
|
||||
self.check_move_out(expr);
|
||||
}
|
||||
some({op: ast::init_assign, _}) | none {}
|
||||
}
|
||||
visit::visit_local(local, self, vt);
|
||||
}
|
||||
|
||||
fn check_loans_in_expr(expr: @ast::expr,
|
||||
&&self: check_loan_ctxt,
|
||||
vt: visit::vt<check_loan_ctxt>) {
|
||||
|
9
src/test/compile-fail/borrowck-issue-2657-1.rs
Normal file
9
src/test/compile-fail/borrowck-issue-2657-1.rs
Normal file
@ -0,0 +1,9 @@
|
||||
fn main() {
|
||||
let x = some(~1);
|
||||
alt x { //! NOTE loan of immutable local variable granted here
|
||||
some(y) {
|
||||
let _a <- x; //! ERROR moving out of immutable local variable prohibited due to outstanding loan
|
||||
}
|
||||
_ {}
|
||||
}
|
||||
}
|
14
src/test/compile-fail/borrowck-issue-2657-2.rs
Normal file
14
src/test/compile-fail/borrowck-issue-2657-2.rs
Normal file
@ -0,0 +1,14 @@
|
||||
//xfail-test
|
||||
|
||||
// this should be illegal but borrowck is not handling
|
||||
// pattern bindings correctly right now
|
||||
|
||||
fn main() {
|
||||
let x = some(~1);
|
||||
alt x {
|
||||
some(y) {
|
||||
let b <- y;
|
||||
}
|
||||
_ {}
|
||||
}
|
||||
}
|
7
src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs
Normal file
7
src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs
Normal file
@ -0,0 +1,7 @@
|
||||
fn foo(x: *~int) -> ~int {
|
||||
let y <- *x; //! ERROR dereference of unsafe pointer requires unsafe function or block
|
||||
ret y;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
11
src/test/run-pass/borrowck-move-from-unsafe-ptr-ok.rs
Normal file
11
src/test/run-pass/borrowck-move-from-unsafe-ptr-ok.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// just make sure this compiles:
|
||||
|
||||
fn bar(x: *~int) -> ~int {
|
||||
unsafe {
|
||||
let y <- *x;
|
||||
ret y;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
Loading…
Reference in New Issue
Block a user