From a896440ca1b93cc5dc6edd827ea2ae89602bfa9e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 15 Mar 2013 15:24:24 -0400 Subject: new borrow checker (mass squash) --- src/test/compile-fail/access-mode-in-closures.rs | 2 +- .../arc-rw-read-mode-shouldnt-escape.rs | 1 + .../arc-rw-write-mode-shouldnt-escape.rs | 1 + .../compile-fail/attempted-access-non-fatal.rs | 4 +- src/test/compile-fail/auto-ref-borrowck-failure.rs | 31 ---- src/test/compile-fail/borrowck-addr-of-upvar.rs | 4 +- src/test/compile-fail/borrowck-assign-comp-idx.rs | 10 +- src/test/compile-fail/borrowck-assign-comp.rs | 18 ++- .../compile-fail/borrowck-assign-to-constants.rs | 4 +- src/test/compile-fail/borrowck-assign-to-enum.rs | 2 +- .../compile-fail/borrowck-assign-to-subfield.rs | 2 +- .../borrowck-auto-mut-ref-to-immut-var.rs | 27 ++++ src/test/compile-fail/borrowck-autoref-3261.rs | 4 +- .../compile-fail/borrowck-bad-nested-calls-free.rs | 43 ++++++ .../compile-fail/borrowck-bad-nested-calls-move.rs | 43 ++++++ .../compile-fail/borrowck-borrow-from-owned-ptr.rs | 70 +++++---- .../borrowck-borrow-from-stack-variable.rs | 67 +++++---- .../borrowck-borrowed-uniq-rvalue-2.rs | 3 +- .../compile-fail/borrowck-borrowed-uniq-rvalue.rs | 2 +- .../borrowck-call-method-from-mut-aliasable.rs | 8 +- ...rrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs | 4 +- .../compile-fail/borrowck-insert-during-each.rs | 4 +- src/test/compile-fail/borrowck-issue-2657-1.rs | 4 +- src/test/compile-fail/borrowck-issue-2657-2.rs | 2 +- src/test/compile-fail/borrowck-lend-flow-if.rs | 52 +++++++ src/test/compile-fail/borrowck-lend-flow-loop.rs | 164 +++++++++++++++++++++ src/test/compile-fail/borrowck-lend-flow-match.rs | 60 ++++++++ src/test/compile-fail/borrowck-lend-flow.rs | 93 +++--------- .../compile-fail/borrowck-loan-blocks-move-cc.rs | 8 +- src/test/compile-fail/borrowck-loan-blocks-move.rs | 4 +- .../compile-fail/borrowck-loan-blocks-mut-uniq.rs | 4 +- .../borrowck-loan-local-as-both-mut-and-imm.rs | 4 +- .../borrowck-loan-rcvr-overloaded-op.rs | 6 +- src/test/compile-fail/borrowck-loan-rcvr.rs | 24 ++- src/test/compile-fail/borrowck-loan-vec-content.rs | 4 +- src/test/compile-fail/borrowck-move-by-capture.rs | 2 +- .../compile-fail/borrowck-mut-addr-of-imm-var.rs | 2 +- src/test/compile-fail/borrowck-mut-boxed-vec.rs | 4 +- src/test/compile-fail/borrowck-mut-deref-comp.rs | 4 +- .../compile-fail/borrowck-mut-slice-of-imm-vec.rs | 2 +- .../borrowck-no-cycle-in-exchange-heap.rs | 4 +- .../compile-fail/borrowck-pat-by-value-binding.rs | 11 +- src/test/compile-fail/borrowck-pat-enum.rs | 14 +- .../compile-fail/borrowck-pat-reassign-binding.rs | 11 +- .../borrowck-pat-reassign-sometimes-binding.rs | 26 ---- .../compile-fail/borrowck-reborrow-from-mut.rs | 22 +-- src/test/compile-fail/borrowck-ref-into-rvalue.rs | 8 +- src/test/compile-fail/borrowck-ref-mut-of-imm.rs | 2 +- src/test/compile-fail/borrowck-unary-move-2.rs | 2 +- src/test/compile-fail/borrowck-unary-move.rs | 4 +- src/test/compile-fail/borrowck-uniq-via-box.rs | 55 ------- src/test/compile-fail/borrowck-uniq-via-lend.rs | 8 +- src/test/compile-fail/borrowck-uniq-via-ref.rs | 7 +- .../borrowck-vec-pattern-element-loan.rs | 12 +- .../borrowck-vec-pattern-loan-from-mut.rs | 2 +- .../compile-fail/borrowck-vec-pattern-move-tail.rs | 5 +- .../compile-fail/borrowck-vec-pattern-nesting.rs | 4 +- .../borrowck-vec-pattern-tail-element-loan.rs | 4 +- .../borrowck-wg-borrow-mut-to-imm-fail-2.rs | 4 +- .../borrowck-wg-borrow-mut-to-imm-fail-3.rs | 4 +- .../borrowck-wg-borrow-mut-to-imm-fail.rs | 4 +- src/test/compile-fail/borrowck-wg-move-base-2.rs | 2 +- src/test/compile-fail/fn-variance-3.rs | 2 +- src/test/compile-fail/immut-function-arguments.rs | 4 +- src/test/compile-fail/index_message.rs | 2 +- src/test/compile-fail/issue-1896-1.rs | 4 +- src/test/compile-fail/issue-2149.rs | 1 - src/test/compile-fail/issue-2151.rs | 3 +- src/test/compile-fail/issue-2590.rs | 2 +- src/test/compile-fail/issue-3044.rs | 1 - src/test/compile-fail/issue-4500.rs | 14 -- src/test/compile-fail/issue-511.rs | 2 +- .../compile-fail/kindck-owned-trait-contains.rs | 3 + src/test/compile-fail/lambda-mutate-nested.rs | 2 +- src/test/compile-fail/lambda-mutate.rs | 2 +- .../compile-fail/moves-based-on-type-block-bad.rs | 2 +- ...d-on-type-move-out-of-closure-env-issue-1965.rs | 2 +- src/test/compile-fail/mutable-class-fields-2.rs | 3 +- src/test/compile-fail/mutable-class-fields.rs | 5 +- src/test/compile-fail/mutable-huh-ptr-assign.rs | 2 +- src/test/compile-fail/regions-addr-of-arg.rs | 2 +- src/test/compile-fail/regions-creating-enums.rs | 4 +- src/test/compile-fail/regions-creating-enums4.rs | 3 +- src/test/compile-fail/regions-escape-bound-fn.rs | 2 +- .../regions-escape-loop-via-variable.rs | 2 +- .../compile-fail/regions-escape-loop-via-vec.rs | 4 +- .../regions-escape-via-trait-or-not.rs | 7 +- .../regions-infer-borrow-scope-too-big.rs | 2 +- .../regions-infer-borrow-scope-within-loop.rs | 2 +- src/test/compile-fail/regions-nested-fns-2.rs | 2 +- src/test/compile-fail/regions-nested-fns.rs | 2 +- src/test/compile-fail/regions-ret-borrowed-1.rs | 1 + src/test/compile-fail/regions-ret-borrowed.rs | 1 + src/test/compile-fail/regions-ret.rs | 2 +- .../compile-fail/regions-var-type-out-of-scope.rs | 2 +- src/test/compile-fail/swap-no-lval.rs | 4 +- src/test/compile-fail/writing-to-immutable-vec.rs | 6 +- src/test/run-pass/borrowck-nested-calls.rs | 32 ++++ src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs | 6 +- src/test/run-pass/issue-2735-2.rs | 18 +-- src/test/run-pass/issue-2735-3.rs | 18 +-- 101 files changed, 734 insertions(+), 456 deletions(-) delete mode 100644 src/test/compile-fail/auto-ref-borrowck-failure.rs create mode 100644 src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs create mode 100644 src/test/compile-fail/borrowck-bad-nested-calls-free.rs create mode 100644 src/test/compile-fail/borrowck-bad-nested-calls-move.rs create mode 100644 src/test/compile-fail/borrowck-lend-flow-if.rs create mode 100644 src/test/compile-fail/borrowck-lend-flow-loop.rs create mode 100644 src/test/compile-fail/borrowck-lend-flow-match.rs delete mode 100644 src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs delete mode 100644 src/test/compile-fail/borrowck-uniq-via-box.rs delete mode 100644 src/test/compile-fail/issue-4500.rs create mode 100644 src/test/run-pass/borrowck-nested-calls.rs (limited to 'src/test') diff --git a/src/test/compile-fail/access-mode-in-closures.rs b/src/test/compile-fail/access-mode-in-closures.rs index f6b9a82ec67..61fb754f761 100644 --- a/src/test/compile-fail/access-mode-in-closures.rs +++ b/src/test/compile-fail/access-mode-in-closures.rs @@ -16,6 +16,6 @@ fn unpack(_unpack: &fn(v: &sty) -> ~[int]) {} fn main() { let _foo = unpack(|s| { // Test that `s` is moved here. - match *s { sty(v) => v } //~ ERROR moving out of dereference of immutable & pointer + match *s { sty(v) => v } //~ ERROR cannot move out }); } diff --git a/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs index e2dd13a4405..85f60f34bdb 100644 --- a/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs @@ -17,6 +17,7 @@ fn main() { y = Some(x.downgrade(write_mode)); //~^ ERROR cannot infer an appropriate lifetime } + y.get(); // Adding this line causes a method unification failure instead // do (&option::unwrap(y)).read |state| { assert!(*state == 1); } } diff --git a/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs index 78a50a4f212..c7ae6a0dc6c 100644 --- a/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs @@ -17,6 +17,7 @@ fn main() { do x.write_downgrade |write_mode| { y = Some(write_mode); } + y.get(); // Adding this line causes a method unification failure instead // do (&option::unwrap(y)).write |state| { assert!(*state == 1); } } diff --git a/src/test/compile-fail/attempted-access-non-fatal.rs b/src/test/compile-fail/attempted-access-non-fatal.rs index ba15abc3f89..1d9249bc17b 100644 --- a/src/test/compile-fail/attempted-access-non-fatal.rs +++ b/src/test/compile-fail/attempted-access-non-fatal.rs @@ -11,6 +11,6 @@ // Check that bogus field access is non-fatal fn main() { let x = 0; - debug!(x.foo); //~ ERROR attempted access of field - debug!(x.bar); //~ ERROR attempted access of field + let _ = x.foo; //~ ERROR attempted access of field + let _ = x.bar; //~ ERROR attempted access of field } diff --git a/src/test/compile-fail/auto-ref-borrowck-failure.rs b/src/test/compile-fail/auto-ref-borrowck-failure.rs deleted file mode 100644 index 90b9b44cfbe..00000000000 --- a/src/test/compile-fail/auto-ref-borrowck-failure.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Tests that auto-ref can't create mutable aliases to immutable memory. - -struct Foo { - x: int -} - -trait Stuff { - fn printme(self); -} - -impl<'self> Stuff for &'self mut Foo { - fn printme(self) { - io::println(fmt!("%d", self.x)); - } -} - -fn main() { - let x = Foo { x: 3 }; - x.printme(); //~ ERROR illegal borrow -} - diff --git a/src/test/compile-fail/borrowck-addr-of-upvar.rs b/src/test/compile-fail/borrowck-addr-of-upvar.rs index 640bc887731..83baedc7892 100644 --- a/src/test/compile-fail/borrowck-addr-of-upvar.rs +++ b/src/test/compile-fail/borrowck-addr-of-upvar.rs @@ -9,12 +9,12 @@ // except according to those terms. fn foo(x: @int) -> @fn() -> &'static int { - let result: @fn() -> &'static int = || &*x; //~ ERROR illegal borrow + let result: @fn() -> &'static int = || &*x; //~ ERROR cannot root result } fn bar(x: @int) -> @fn() -> &int { - let result: @fn() -> &int = || &*x; //~ ERROR illegal borrow + let result: @fn() -> &int = || &*x; //~ ERROR cannot root result } diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index 25b56abb5ba..d447d9e4a22 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -17,9 +17,11 @@ fn a() { let mut p = ~[1]; // Create an immutable pointer into p's contents: - let _q: &int = &p[0]; //~ NOTE loan of mutable vec content granted here + let q: &int = &p[0]; - p[0] = 5; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan + p[0] = 5; //~ ERROR cannot assign + + debug!("%d", *q); } fn borrow(_x: &[int], _f: &fn()) {} @@ -30,8 +32,8 @@ fn b() { let mut p = ~[1]; - do borrow(p) { //~ NOTE loan of mutable vec content granted here - p[0] = 5; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan + do borrow(p) { + p[0] = 5; //~ ERROR cannot assign to } } diff --git a/src/test/compile-fail/borrowck-assign-comp.rs b/src/test/compile-fail/borrowck-assign-comp.rs index 283f04a283f..b8c0cbe9743 100644 --- a/src/test/compile-fail/borrowck-assign-comp.rs +++ b/src/test/compile-fail/borrowck-assign-comp.rs @@ -12,12 +12,13 @@ struct point { x: int, y: int } fn a() { let mut p = point {x: 3, y: 4}; - let _q = &p; //~ NOTE loan of mutable local variable granted here + let q = &p; // This assignment is illegal because the field x is not // inherently mutable; since `p` was made immutable, `p.x` is now // immutable. Otherwise the type of &_q.x (&int) would be wrong. - p.x = 5; //~ ERROR assigning to mutable field prohibited due to outstanding loan + p.x = 5; //~ ERROR cannot assign to `p.x` + q.x; } fn c() { @@ -25,9 +26,10 @@ fn c() { // and then try to overwrite `p` as a whole. let mut p = point {x: 3, y: 4}; - let _q = &p.y; //~ NOTE loan of mutable local variable granted here - p = point {x: 5, y: 7};//~ ERROR assigning to mutable local variable prohibited due to outstanding loan - copy p; + let q = &p.y; + p = point {x: 5, y: 7};//~ ERROR cannot assign to `p` + p.x; // silence warning + *q; // stretch loan } fn d() { @@ -35,9 +37,9 @@ fn d() { // address of a subcomponent and then modify that subcomponent: let mut p = point {x: 3, y: 4}; - let _q = &p.y; //~ NOTE loan of mutable field granted here - p.y = 5; //~ ERROR assigning to mutable field prohibited due to outstanding loan - copy p; + let q = &p.y; + p.y = 5; //~ ERROR cannot assign to `p.y` + *q; } fn main() { diff --git a/src/test/compile-fail/borrowck-assign-to-constants.rs b/src/test/compile-fail/borrowck-assign-to-constants.rs index 0d65aacb65b..f0dc28b736d 100644 --- a/src/test/compile-fail/borrowck-assign-to-constants.rs +++ b/src/test/compile-fail/borrowck-assign-to-constants.rs @@ -12,6 +12,6 @@ static foo: int = 5; fn main() { // assigning to various global constants - None = Some(3); //~ ERROR assigning to static item - foo = 6; //~ ERROR assigning to static item + None = Some(3); //~ ERROR cannot assign to immutable static item + foo = 6; //~ ERROR cannot assign to immutable static item } diff --git a/src/test/compile-fail/borrowck-assign-to-enum.rs b/src/test/compile-fail/borrowck-assign-to-enum.rs index a35d88a76f3..fcaba0adc46 100644 --- a/src/test/compile-fail/borrowck-assign-to-enum.rs +++ b/src/test/compile-fail/borrowck-assign-to-enum.rs @@ -12,5 +12,5 @@ struct foo(int); fn main() { let x = foo(3); - *x = 4; //~ ERROR assigning to anonymous field + *x = 4; //~ ERROR cannot assign to immutable anonymous field } diff --git a/src/test/compile-fail/borrowck-assign-to-subfield.rs b/src/test/compile-fail/borrowck-assign-to-subfield.rs index 610802ca68b..2ee5ecfcb9c 100644 --- a/src/test/compile-fail/borrowck-assign-to-subfield.rs +++ b/src/test/compile-fail/borrowck-assign-to-subfield.rs @@ -34,6 +34,6 @@ fn main() { // in these cases we pass through a box, so the mut // of the box is dominant - p.x.a = 2; //~ ERROR assigning to immutable field + p.x.a = 2; //~ ERROR cannot assign to immutable field p.z.a = 2; } diff --git a/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs b/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs new file mode 100644 index 00000000000..ce95ee94f42 --- /dev/null +++ b/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs @@ -0,0 +1,27 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Tests that auto-ref can't create mutable aliases to immutable memory. + +struct Foo { + x: int +} + +pub impl Foo { + fn printme(&mut self) { + io::println(fmt!("%d", self.x)); + } +} + +fn main() { + let x = Foo { x: 3 }; + x.printme(); //~ ERROR cannot borrow +} + diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index c95b93445ad..192fe669f57 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -17,10 +17,10 @@ pub impl X { } fn main() { let mut x = X(Right(main)); - do (&mut x).with |opt| { //~ ERROR illegal borrow + do (&mut x).with |opt| { match opt { &Right(ref f) => { - x = X(Left((0,0))); //~ ERROR assigning to captured outer mutable variable + x = X(Left((0,0))); //~ ERROR cannot assign to `x` (*f)() }, _ => fail!() diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs new file mode 100644 index 00000000000..ff1ec38ad64 --- /dev/null +++ b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs @@ -0,0 +1,43 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we detect nested calls that could free pointers evaluated +// for earlier arguments. + +fn rewrite(v: &mut ~uint) -> uint { + *v = ~22; + **v +} + +fn add(v: &uint, w: uint) -> uint { + *v + w +} + +fn implicit() { + let mut a = ~1; + + // Note the danger here: + // + // the pointer for the first argument has already been + // evaluated, but it gets freed when evaluating the second + // argument! + add( + a, + rewrite(&mut a)); //~ ERROR cannot borrow +} + +fn explicit() { + let mut a = ~1; + add( + &*a, + rewrite(&mut a)); //~ ERROR cannot borrow +} + +fn main() {} \ No newline at end of file diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs new file mode 100644 index 00000000000..0adf486b8b3 --- /dev/null +++ b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs @@ -0,0 +1,43 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we detect nested calls that could free pointers evaluated +// for earlier arguments. + +fn rewrite(v: &mut ~uint) -> uint { + *v = ~22; + **v +} + +fn add(v: &uint, w: ~uint) -> uint { + *v + *w +} + +fn implicit() { + let mut a = ~1; + + // Note the danger here: + // + // the pointer for the first argument has already been + // evaluated, but it gets moved when evaluating the second + // argument! + add( + a, + a); //~ ERROR cannot move +} + +fn explicit() { + let mut a = ~1; + add( + &*a, + a); //~ ERROR cannot move +} + +fn main() {} \ No newline at end of file diff --git a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs index 005908f86d8..1051c5829ec 100644 --- a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs +++ b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs @@ -22,32 +22,37 @@ fn make_foo() -> ~Foo { fail!() } fn borrow_same_field_twice_mut_mut() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; - let _bar2 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1; + let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_same_field_twice_mut_imm() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; - let _bar2 = &foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1; + let _bar2 = &foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_same_field_twice_imm_mut() { let mut foo = make_foo(); - let _bar1 = &foo.bar1; - let _bar2 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &foo.bar1; + let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_same_field_twice_imm_imm() { let mut foo = make_foo(); - let _bar1 = &foo.bar1; + let bar1 = &foo.bar1; let _bar2 = &foo.bar1; + *bar1; } -fn borrow_both_mut() { +fn borrow_both_fields_mut() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; + let bar1 = &mut foo.bar1; let _bar2 = &mut foo.bar2; + *bar1; } fn borrow_both_mut_pattern() { @@ -59,66 +64,77 @@ fn borrow_both_mut_pattern() { fn borrow_var_and_pattern() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; + let bar1 = &mut foo.bar1; match *foo { Foo { bar1: ref mut _bar1, bar2: _ } => {} - //~^ ERROR conflicts with prior loan + //~^ ERROR cannot borrow } + *bar1; } fn borrow_mut_and_base_imm() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1.int1; - let _foo1 = &foo.bar1; //~ ERROR conflicts with prior loan - let _foo2 = &*foo; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1.int1; + let _foo1 = &foo.bar1; //~ ERROR cannot borrow + let _foo2 = &*foo; //~ ERROR cannot borrow + *bar1; } fn borrow_mut_and_base_mut() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1.int1; - let _foo1 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1.int1; + let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_mut_and_base_mut2() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1.int1; - let _foo2 = &mut *foo; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1.int1; + let _foo2 = &mut *foo; //~ ERROR cannot borrow + *bar1; } fn borrow_imm_and_base_mut() { let mut foo = make_foo(); - let _bar1 = &foo.bar1.int1; - let _foo1 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &foo.bar1.int1; + let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_imm_and_base_mut2() { let mut foo = make_foo(); - let _bar1 = &foo.bar1.int1; - let _foo2 = &mut *foo; //~ ERROR conflicts with prior loan + let bar1 = &foo.bar1.int1; + let _foo2 = &mut *foo; //~ ERROR cannot borrow + *bar1; } fn borrow_imm_and_base_imm() { let mut foo = make_foo(); - let _bar1 = &foo.bar1.int1; + let bar1 = &foo.bar1.int1; let _foo1 = &foo.bar1; let _foo2 = &*foo; + *bar1; } fn borrow_mut_and_imm() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; + let bar1 = &mut foo.bar1; let _foo1 = &foo.bar2; + *bar1; } fn borrow_mut_from_imm() { let foo = make_foo(); - let _bar1 = &mut foo.bar1; //~ ERROR illegal borrow + let bar1 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_long_path_both_mut() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1.int1; - let _foo1 = &mut foo.bar2.int2; + let bar1 = &mut foo.bar1.int1; + let foo1 = &mut foo.bar2.int2; + *bar1; + *foo1; } fn main() {} diff --git a/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs b/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs index 035e293bc36..cdcf50c906e 100644 --- a/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs +++ b/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs @@ -22,32 +22,37 @@ fn make_foo() -> Foo { fail!() } fn borrow_same_field_twice_mut_mut() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; - let _bar2 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1; + let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_same_field_twice_mut_imm() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; - let _bar2 = &foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1; + let _bar2 = &foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_same_field_twice_imm_mut() { let mut foo = make_foo(); - let _bar1 = &foo.bar1; - let _bar2 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &foo.bar1; + let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_same_field_twice_imm_imm() { let mut foo = make_foo(); - let _bar1 = &foo.bar1; + let bar1 = &foo.bar1; let _bar2 = &foo.bar1; + *bar1; } fn borrow_both_mut() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; + let bar1 = &mut foo.bar1; let _bar2 = &mut foo.bar2; + *bar1; } fn borrow_both_mut_pattern() { @@ -59,66 +64,76 @@ fn borrow_both_mut_pattern() { fn borrow_var_and_pattern() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; + let bar1 = &mut foo.bar1; match foo { - Foo { bar1: ref mut _bar1, bar2: _ } => {} - //~^ ERROR conflicts with prior loan + Foo { bar1: ref mut _bar1, bar2: _ } => {} // + //~^ ERROR cannot borrow } + *bar1; } fn borrow_mut_and_base_imm() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1.int1; - let _foo1 = &foo.bar1; //~ ERROR conflicts with prior loan - let _foo2 = &foo; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1.int1; + let _foo1 = &foo.bar1; //~ ERROR cannot borrow + let _foo2 = &foo; //~ ERROR cannot borrow + *bar1; } fn borrow_mut_and_base_mut() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1.int1; - let _foo1 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1.int1; + let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_mut_and_base_mut2() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1.int1; - let _foo2 = &mut foo; //~ ERROR conflicts with prior loan + let bar1 = &mut foo.bar1.int1; + let _foo2 = &mut foo; //~ ERROR cannot borrow + *bar1; } fn borrow_imm_and_base_mut() { let mut foo = make_foo(); - let _bar1 = &foo.bar1.int1; - let _foo1 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let bar1 = &foo.bar1.int1; + let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_imm_and_base_mut2() { let mut foo = make_foo(); - let _bar1 = &foo.bar1.int1; - let _foo2 = &mut foo; //~ ERROR conflicts with prior loan + let bar1 = &foo.bar1.int1; + let _foo2 = &mut foo; //~ ERROR cannot borrow + *bar1; } fn borrow_imm_and_base_imm() { let mut foo = make_foo(); - let _bar1 = &foo.bar1.int1; + let bar1 = &foo.bar1.int1; let _foo1 = &foo.bar1; let _foo2 = &foo; + *bar1; } fn borrow_mut_and_imm() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1; + let bar1 = &mut foo.bar1; let _foo1 = &foo.bar2; + *bar1; } fn borrow_mut_from_imm() { let foo = make_foo(); - let _bar1 = &mut foo.bar1; //~ ERROR illegal borrow + let bar1 = &mut foo.bar1; //~ ERROR cannot borrow + *bar1; } fn borrow_long_path_both_mut() { let mut foo = make_foo(); - let _bar1 = &mut foo.bar1.int1; + let bar1 = &mut foo.bar1.int1; let _foo1 = &mut foo.bar2.int2; + *bar1; } fn main() {} diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs index 4a6a90ae516..1e5c4c5cc41 100644 --- a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs @@ -28,5 +28,6 @@ fn defer<'r>(x: &'r [&'r str]) -> defer<'r> { } fn main() { - let _x = defer(~["Goodbye", "world!"]); //~ ERROR illegal borrow + let x = defer(~["Goodbye", "world!"]); //~ ERROR borrowed value does not live long enough + x.x[0]; } diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs index bda659aa7b9..887cb59930e 100644 --- a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs @@ -15,7 +15,7 @@ use core::hashmap::HashMap; fn main() { let mut buggy_map :HashMap = HashMap::new::(); - buggy_map.insert(42, &*~1); //~ ERROR illegal borrow + buggy_map.insert(42, &*~1); //~ ERROR borrowed value does not live long enough // but it is ok if we use a temporary let tmp = ~2; diff --git a/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs b/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs index 2c68429baec..be51091c1fd 100644 --- a/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs +++ b/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs @@ -27,13 +27,15 @@ fn a(x: &mut Foo) { fn b(x: &Foo) { x.f(); x.g(); - x.h(); //~ ERROR illegal borrow + x.h(); //~ ERROR cannot borrow } fn c(x: &const Foo) { - x.f(); //~ ERROR illegal borrow unless pure + x.f(); //~ ERROR cannot borrow + //~^ ERROR unsafe borrow x.g(); - x.h(); //~ ERROR illegal borrow + x.h(); //~ ERROR cannot borrow + //~^ ERROR unsafe borrow } fn main() { diff --git a/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs b/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs index 88db5f54341..8af10231921 100644 --- a/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs +++ b/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs @@ -10,9 +10,9 @@ fn main() { let mut _a = 3; - let _b = &mut _a; //~ NOTE loan of mutable local variable granted here + let _b = &mut _a; { let _c = &*_b; - _a = 4; //~ ERROR assigning to mutable local variable prohibited + _a = 4; //~ ERROR cannot assign to `_a` } } diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index 17c0efe225e..109753b38e7 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -23,8 +23,8 @@ pub impl Foo { } fn bar(f: &mut Foo) { - do f.foo |a| { //~ NOTE prior loan as mutable granted here - f.n.insert(*a); //~ ERROR conflicts with prior loan + do f.foo |a| { + f.n.insert(*a); //~ ERROR cannot borrow } } diff --git a/src/test/compile-fail/borrowck-issue-2657-1.rs b/src/test/compile-fail/borrowck-issue-2657-1.rs index ce183c1888f..8bcd5f9a72e 100644 --- a/src/test/compile-fail/borrowck-issue-2657-1.rs +++ b/src/test/compile-fail/borrowck-issue-2657-1.rs @@ -10,9 +10,9 @@ fn main() { let x = Some(~1); -match x { //~ NOTE loan of immutable local variable granted here +match x { Some(ref _y) => { - let _a = x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan + let _a = x; //~ ERROR cannot move } _ => {} } diff --git a/src/test/compile-fail/borrowck-issue-2657-2.rs b/src/test/compile-fail/borrowck-issue-2657-2.rs index d2217778d41..fac805c57ca 100644 --- a/src/test/compile-fail/borrowck-issue-2657-2.rs +++ b/src/test/compile-fail/borrowck-issue-2657-2.rs @@ -12,7 +12,7 @@ fn main() { let x = Some(~1); match x { Some(ref y) => { - let _b = *y; //~ ERROR moving out of dereference of immutable & pointer + let _b = *y; //~ ERROR cannot move out } _ => {} } diff --git a/src/test/compile-fail/borrowck-lend-flow-if.rs b/src/test/compile-fail/borrowck-lend-flow-if.rs new file mode 100644 index 00000000000..563f63b98be --- /dev/null +++ b/src/test/compile-fail/borrowck-lend-flow-if.rs @@ -0,0 +1,52 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Note: the borrowck analysis is currently flow-insensitive. +// Therefore, some of these errors are marked as spurious and could be +// corrected by a simple change to the analysis. The others are +// either genuine or would require more advanced changes. The latter +// cases are noted. + +fn borrow(_v: &int) {} +fn borrow_mut(_v: &mut int) {} +fn cond() -> bool { fail!() } +fn for_func(_f: &fn() -> bool) { fail!() } +fn produce() -> T { fail!(); } + +fn inc(v: &mut ~int) { + *v = ~(**v + 1); +} + +fn pre_freeze_cond() { + // In this instance, the freeze is conditional and starts before + // the mut borrow. + + let mut v = ~3; + let _w; + if cond() { + _w = &v; + } + borrow_mut(v); //~ ERROR cannot borrow +} + +fn pre_freeze_else() { + // In this instance, the freeze and mut borrow are on separate sides + // of the if. + + let mut v = ~3; + let _w; + if cond() { + _w = &v; + } else { + borrow_mut(v); + } +} + +fn main() {} diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs new file mode 100644 index 00000000000..b6384ad9590 --- /dev/null +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -0,0 +1,164 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Note: the borrowck analysis is currently flow-insensitive. +// Therefore, some of these errors are marked as spurious and could be +// corrected by a simple change to the analysis. The others are +// either genuine or would require more advanced changes. The latter +// cases are noted. + +fn borrow(_v: &int) {} +fn borrow_mut(_v: &mut int) {} +fn cond() -> bool { fail!() } +fn for_func(_f: &fn() -> bool) { fail!() } +fn produce() -> T { fail!(); } + +fn inc(v: &mut ~int) { + *v = ~(**v + 1); +} + +fn loop_overarching_alias_mut() { + // In this instance, the borrow encompasses the entire loop. + + let mut v = ~3; + let mut x = &mut v; + **x += 1; + loop { + borrow(v); //~ ERROR cannot borrow + } +} + +fn block_overarching_alias_mut() { + // In this instance, the borrow encompasses the entire closure call. + + let mut v = ~3; + let mut x = &mut v; + for 3.times { + borrow(v); //~ ERROR cannot borrow + } + *x = ~5; +} + +fn loop_aliased_mut() { + // In this instance, the borrow is carried through the loop. + + let mut v = ~3, w = ~4; + let mut _x = &w; + loop { + borrow_mut(v); //~ ERROR cannot borrow + _x = &v; + } +} + +fn while_aliased_mut() { + // In this instance, the borrow is carried through the loop. + + let mut v = ~3, w = ~4; + let mut _x = &w; + while cond() { + borrow_mut(v); //~ ERROR cannot borrow + _x = &v; + } +} + +fn for_loop_aliased_mut() { + // In this instance, the borrow is carried through the loop. + + let mut v = ~3, w = ~4; + let mut _x = &w; + for for_func { + borrow_mut(v); //~ ERROR cannot borrow + _x = &v; + } +} + +fn loop_aliased_mut_break() { + // In this instance, the borrow is carried through the loop. + + let mut v = ~3, w = ~4; + let mut _x = &w; + loop { + borrow_mut(v); + _x = &v; + break; + } + borrow_mut(v); //~ ERROR cannot borrow +} + +fn while_aliased_mut_break() { + // In this instance, the borrow is carried through the loop. + + let mut v = ~3, w = ~4; + let mut _x = &w; + while cond() { + borrow_mut(v); + _x = &v; + break; + } + borrow_mut(v); //~ ERROR cannot borrow +} + +fn for_aliased_mut_break() { + // In this instance, the borrow is carried through the loop. + + let mut v = ~3, w = ~4; + let mut _x = &w; + for for_func { + // here we cannot be sure that `for_func` respects the break below + borrow_mut(v); //~ ERROR cannot borrow + _x = &v; + break; + } + borrow_mut(v); //~ ERROR cannot borrow +} + +fn while_aliased_mut_cond(cond: bool, cond2: bool) { + let mut v = ~3, w = ~4; + let mut x = &mut w; + while cond { + **x += 1; + borrow(v); //~ ERROR cannot borrow + if cond2 { + x = &mut v; //~ ERROR cannot borrow + } + } +} + +fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: &fn(&'r mut uint) -> bool) { + // Here we check that when you break out of an inner loop, the + // borrows that go out of scope as you exit the inner loop are + // removed from the bitset. + + while cond() { + while cond() { + // this borrow is limited to the scope of `r`... + let r: &'r mut uint = produce(); + if !f(&mut *r) { + break; // ...so it is not live as exit the `while` loop here + } + } + } +} + +fn loop_loop_pops_scopes<'r>(_v: &'r mut [uint], f: &fn(&'r mut uint) -> bool) { + // Similar to `loop_break_pops_scopes` but for the `loop` keyword + + while cond() { + while cond() { + // this borrow is limited to the scope of `r`... + let r: &'r mut uint = produce(); + if !f(&mut *r) { + loop; // ...so it is not live as exit (and re-enter) the `while` loop here + } + } + } +} + +fn main() {} diff --git a/src/test/compile-fail/borrowck-lend-flow-match.rs b/src/test/compile-fail/borrowck-lend-flow-match.rs new file mode 100644 index 00000000000..7603fdc82a8 --- /dev/null +++ b/src/test/compile-fail/borrowck-lend-flow-match.rs @@ -0,0 +1,60 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// xfail-pretty -- comments are infaithfully preserved + +#[allow(unused_variable)]; +#[allow(dead_assignment)]; + +fn cond() -> bool { fail!() } +fn link<'a>(v: &'a uint, w: &mut &'a uint) -> bool { *w = v; true } + +fn separate_arms() { + // Here both arms perform assignments, but only is illegal. + + let mut x = None; + match x { + None => { + // It is ok to reassign x here, because there is in + // fact no outstanding loan of x! + x = Some(0); + } + Some(ref _i) => { + x = Some(1); //~ ERROR cannot assign + } + } + copy x; // just to prevent liveness warnings +} + +fn guard() { + // Here the guard performs a borrow. This borrow "infects" all + // subsequent arms (but not the prior ones). + + let mut a = ~3; + let mut b = ~4; + let mut w = &*a; + match 22 { + _ if cond() => { + b = ~5; + } + + _ if link(&*b, &mut w) => { + b = ~6; //~ ERROR cannot assign + } + + _ => { + b = ~7; //~ ERROR cannot assign + } + } + + b = ~8; //~ ERROR cannot assign +} + +fn main() {} diff --git a/src/test/compile-fail/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck-lend-flow.rs index ed6446a6311..59cac0c5d95 100644 --- a/src/test/compile-fail/borrowck-lend-flow.rs +++ b/src/test/compile-fail/borrowck-lend-flow.rs @@ -15,96 +15,37 @@ // cases are noted. fn borrow(_v: &int) {} +fn borrow_mut(_v: &mut int) {} +fn cond() -> bool { fail!() } +fn for_func(_f: &fn() -> bool) { fail!() } +fn produce() -> T { fail!(); } fn inc(v: &mut ~int) { *v = ~(**v + 1); } -fn post_aliased_const() { - let mut v = ~3; - borrow(v); - let _w = &const v; -} - -fn post_aliased_mut() { - // SPURIOUS--flow - let mut v = ~3; - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan - let _w = &mut v; //~ NOTE prior loan as mutable granted here -} +fn pre_freeze() { + // In this instance, the freeze starts before the mut borrow. -fn post_aliased_scope(cond: bool) { let mut v = ~3; - borrow(v); - if cond { inc(&mut v); } + let _w = &v; + borrow_mut(v); //~ ERROR cannot borrow } -fn loop_overarching_alias_mut() { - let mut v = ~3; - let mut _x = &mut v; //~ NOTE prior loan as mutable granted here - loop { - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan - } -} +fn pre_const() { + // In this instance, the freeze starts before the mut borrow. -fn block_overarching_alias_mut() { let mut v = ~3; - let mut _x = &mut v; //~ NOTE prior loan as mutable granted here - for 3.times { - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan - } -} - -fn loop_aliased_mut() { - let mut v = ~3, w = ~4; - let mut _x = &mut w; - loop { - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan - _x = &mut v; //~ NOTE prior loan as mutable granted here - } -} - -fn while_aliased_mut(cond: bool) { - let mut v = ~3, w = ~4; - let mut _x = &mut w; - while cond { - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan - _x = &mut v; //~ NOTE prior loan as mutable granted here - } -} - -fn while_aliased_mut_cond(cond: bool, cond2: bool) { - let mut v = ~3, w = ~4; - let mut _x = &mut w; - while cond { - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan - if cond2 { - _x = &mut v; //~ NOTE prior loan as mutable granted here - } - } -} - -fn loop_in_block() { - let mut v = ~3, w = ~4; - let mut _x = &mut w; - for uint::range(0u, 10u) |_i| { - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan - _x = &mut v; //~ NOTE prior loan as mutable granted here - } + let _w = &const v; + borrow_mut(v); } -fn at_most_once_block() { - fn at_most_once(f: &fn()) { f() } +fn post_freeze() { + // In this instance, the const alias starts after the borrow. - // Here, the borrow check has no way of knowing that the block is - // executed at most once. - - let mut v = ~3, w = ~4; - let mut _x = &mut w; - do at_most_once { - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan - _x = &mut v; //~ NOTE prior loan as mutable granted here - } + let mut v = ~3; + borrow_mut(v); + let _w = &v; } fn main() {} diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 784fce1300f..50dd815d493 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -14,17 +14,17 @@ fn borrow(v: &int, f: &fn(x: &int)) { fn box_imm() { let v = ~3; - let _w = &v; //~ NOTE loan of immutable local variable granted here + let _w = &v; do task::spawn { debug!("v=%d", *v); - //~^ ERROR by-move capture of immutable local variable prohibited due to outstanding loan + //~^ ERROR cannot move `v` into closure } let v = ~3; - let _w = &v; //~ NOTE loan of immutable local variable granted here + let _w = &v; task::spawn(|| { debug!("v=%d", *v); - //~^ ERROR by-move capture of immutable local variable prohibited due to outstanding loan + //~^ ERROR cannot move }); } diff --git a/src/test/compile-fail/borrowck-loan-blocks-move.rs b/src/test/compile-fail/borrowck-loan-blocks-move.rs index 3af77d2df7f..b9a79f4f3b1 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move.rs @@ -13,8 +13,8 @@ fn take(_v: ~int) { fn box_imm() { let v = ~3; - let _w = &v; //~ NOTE loan of immutable local variable granted here - take(v); //~ ERROR moving out of immutable local variable prohibited due to outstanding loan + let _w = &v; + take(v); //~ ERROR cannot move out of `v` because it is borrowed } fn main() { diff --git a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs index 14cb37d775c..f8415a38573 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs @@ -14,8 +14,8 @@ fn borrow(v: &int, f: &fn(x: &int)) { fn box_imm() { let mut v = ~3; - do borrow(v) |w| { //~ NOTE loan of mutable local variable granted here - v = ~4; //~ ERROR assigning to captured outer mutable variable in a stack closure prohibited due to outstanding loan + do borrow(v) |w| { + v = ~4; //~ ERROR cannot assign to `v` because it is borrowed assert!(*v == 3); assert!(*w == 4); } diff --git a/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs b/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs index a2ba5ad4891..f369bf208c2 100644 --- a/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs +++ b/src/test/compile-fail/borrowck-loan-local-as-both-mut-and-imm.rs @@ -22,13 +22,13 @@ use core::either::{Either, Left, Right}; fn g() { let mut x: Either = Left(3); - io::println(f(&mut x, &x).to_str()); //~ ERROR conflicts with prior loan + io::println(f(&mut x, &x).to_str()); //~ ERROR cannot borrow } fn h() { let mut x: Either = Left(3); let y: &Either = &x; - let z: &mut Either = &mut x; //~ ERROR conflicts with prior loan + let z: &mut Either = &mut x; //~ ERROR cannot borrow *z = *y; } diff --git a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs index a4ad7e69b33..8c9d3009e5e 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Point { +struct Point { x: int, y: int, } @@ -38,10 +38,10 @@ fn b() { // Here I create an outstanding loan and check that we get conflicts: - let q = &mut p; //~ NOTE prior loan as mutable granted here + let q = &mut p; p + 3; // ok for pure fns - p.times(3); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan + p.times(3); //~ ERROR cannot borrow `p` q.x += 1; } diff --git a/src/test/compile-fail/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck-loan-rcvr.rs index 4473574926a..decf6228fc6 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr.rs @@ -13,7 +13,6 @@ struct point { x: int, y: int } trait methods { fn impurem(&self); fn blockm(&self, f: &fn()); - fn purem(&self); } impl methods for point { @@ -21,9 +20,6 @@ impl methods for point { } fn blockm(&self, f: &fn()) { f() } - - fn purem(&self) { - } } fn a() { @@ -31,12 +27,11 @@ fn a() { // Here: it's ok to call even though receiver is mutable, because we // can loan it out. - p.purem(); p.impurem(); // But in this case we do not honor the loan: - do p.blockm { //~ NOTE loan of mutable local variable granted here - p.x = 10; //~ ERROR assigning to mutable field prohibited due to outstanding loan + do p.blockm { + p.x = 10; //~ ERROR cannot assign } } @@ -45,20 +40,21 @@ fn b() { // Here I create an outstanding loan and check that we get conflicts: - let l = &mut p; //~ NOTE prior loan as mutable granted here - //~^ NOTE prior loan as mutable granted here - - p.purem(); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan - p.impurem(); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan + let l = &mut p; + p.impurem(); //~ ERROR cannot borrow l.x += 1; } fn c() { - // Loaning @mut as & is considered legal due to dynamic checks: + // Loaning @mut as & is considered legal due to dynamic checks... let q = @mut point {x: 3, y: 4}; - q.purem(); q.impurem(); + + // ...but we still detect errors statically when we can. + do q.blockm { + q.x = 10; //~ ERROR cannot assign + } } fn main() { diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index d27d690437a..6a8e64377aa 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -24,8 +24,8 @@ fn has_mut_vec_and_does_not_try_to_change_it() { fn has_mut_vec_but_tries_to_change_it() { let mut v = ~[1, 2, 3]; - do takes_imm_elt(&v[0]) { //~ NOTE loan of mutable vec content granted here - v[1] = 4; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan + do takes_imm_elt(&v[0]) { + v[1] = 4; //~ ERROR cannot assign } } diff --git a/src/test/compile-fail/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck-move-by-capture.rs index 18b4ce0640c..c199c879575 100644 --- a/src/test/compile-fail/borrowck-move-by-capture.rs +++ b/src/test/compile-fail/borrowck-move-by-capture.rs @@ -4,7 +4,7 @@ fn main() { let foo = ~3; let _pfoo = &foo; let _f: @fn() -> int = || *foo + 5; - //~^ ERROR by-move capture + //~^ ERROR cannot move `foo` let bar = ~3; let _g = || { diff --git a/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs b/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs index d0b0f51d0cf..e4e44982276 100644 --- a/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs +++ b/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs @@ -10,7 +10,7 @@ fn main() { let x: int = 3; - let y: &mut int = &mut x; //~ ERROR illegal borrow + let y: &mut int = &mut x; //~ ERROR cannot borrow *y = 5; debug!(*y); } diff --git a/src/test/compile-fail/borrowck-mut-boxed-vec.rs b/src/test/compile-fail/borrowck-mut-boxed-vec.rs index d4c0b5a1e9b..a69edebce51 100644 --- a/src/test/compile-fail/borrowck-mut-boxed-vec.rs +++ b/src/test/compile-fail/borrowck-mut-boxed-vec.rs @@ -10,8 +10,8 @@ fn main() { let v = @mut [ 1, 2, 3 ]; - for v.each |_x| { //~ ERROR illegal borrow - v[1] = 4; + for v.each |_x| { + v[1] = 4; //~ ERROR cannot assign } } diff --git a/src/test/compile-fail/borrowck-mut-deref-comp.rs b/src/test/compile-fail/borrowck-mut-deref-comp.rs index 540793d4135..d1dc2961978 100644 --- a/src/test/compile-fail/borrowck-mut-deref-comp.rs +++ b/src/test/compile-fail/borrowck-mut-deref-comp.rs @@ -11,8 +11,8 @@ struct foo(~int); fn borrow(x: @mut foo) { - let _y = &***x; //~ ERROR illegal borrow unless pure - *x = foo(~4); //~ NOTE impure due to assigning to dereference of mutable @ pointer + let _y = &***x; + *x = foo(~4); //~ ERROR cannot assign } fn main() { diff --git a/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs b/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs index bc0340983ae..ec17976c506 100644 --- a/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs +++ b/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs @@ -14,5 +14,5 @@ fn write(v: &mut [int]) { fn main() { let v = ~[1, 2, 3]; - write(v); //~ ERROR illegal borrow + write(v); //~ ERROR cannot borrow } diff --git a/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs b/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs index 4af3bc17240..ed270de51e2 100644 --- a/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs +++ b/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs @@ -19,9 +19,9 @@ enum cycle { fn main() { let mut x = ~node(node_ {a: ~empty}); // Create a cycle! - match *x { //~ NOTE loan of mutable local variable granted here + match *x { node(ref mut y) => { - y.a = x; //~ ERROR moving out of mutable local variable prohibited due to outstanding loan + y.a = x; //~ ERROR cannot move out of } empty => {} }; diff --git a/src/test/compile-fail/borrowck-pat-by-value-binding.rs b/src/test/compile-fail/borrowck-pat-by-value-binding.rs index d8c8841d391..d60ed3d0e37 100644 --- a/src/test/compile-fail/borrowck-pat-by-value-binding.rs +++ b/src/test/compile-fail/borrowck-pat-by-value-binding.rs @@ -12,23 +12,24 @@ fn process(_t: T) {} fn match_const_opt_by_mut_ref(v: &const Option) { match *v { - Some(ref mut i) => process(i), //~ ERROR illegal borrow + Some(ref mut i) => process(i), //~ ERROR cannot borrow + //~^ ERROR unsafe borrow of aliasable, const value None => () } } fn match_const_opt_by_const_ref(v: &const Option) { match *v { - Some(ref const i) => process(i), //~ ERROR illegal borrow unless pure - //~^ NOTE impure due to + Some(ref const i) => process(i), + //~^ ERROR unsafe borrow of aliasable, const value None => () } } fn match_const_opt_by_imm_ref(v: &const Option) { match *v { - Some(ref i) => process(i), //~ ERROR illegal borrow unless pure - //~^ NOTE impure due to + Some(ref i) => process(i), //~ ERROR cannot borrow + //~^ ERROR unsafe borrow of aliasable, const value None => () } } diff --git a/src/test/compile-fail/borrowck-pat-enum.rs b/src/test/compile-fail/borrowck-pat-enum.rs index 4aa1ecc0ce3..c50357e8b9c 100644 --- a/src/test/compile-fail/borrowck-pat-enum.rs +++ b/src/test/compile-fail/borrowck-pat-enum.rs @@ -26,7 +26,8 @@ fn match_ref_unused(&&v: Option) { fn match_const_reg(v: &const Option) -> int { match *v { - Some(ref i) => {*i} // OK because this is pure + Some(ref i) => {*i} //~ ERROR cannot borrow + //~^ ERROR unsafe borrow None => {0} } } @@ -43,8 +44,8 @@ fn match_const_reg_unused(v: &const Option) { fn match_const_reg_impure(v: &const Option) { match *v { - Some(ref i) => {impure(*i)} //~ ERROR illegal borrow unless pure - //~^ NOTE impure due to access to impure function + Some(ref i) => {impure(*i)} //~ ERROR cannot borrow + //~^ ERROR unsafe borrow None => {} } } @@ -56,5 +57,12 @@ fn match_imm_reg(v: &Option) { } } +fn match_mut_reg(v: &mut Option) { + match *v { + Some(ref i) => {impure(*i)} // OK, frozen + None => {} + } +} + fn main() { } diff --git a/src/test/compile-fail/borrowck-pat-reassign-binding.rs b/src/test/compile-fail/borrowck-pat-reassign-binding.rs index ca1fdc97c22..d05160132c6 100644 --- a/src/test/compile-fail/borrowck-pat-reassign-binding.rs +++ b/src/test/compile-fail/borrowck-pat-reassign-binding.rs @@ -12,11 +12,14 @@ fn main() { let mut x: Option = None; - match x { //~ NOTE loan of mutable local variable granted here - None => {} + match x { + None => { + // Note: on this branch, no borrow has occurred. + x = Some(0); + } Some(ref i) => { - // Not ok: i is an outstanding ptr into x. - x = Some(*i+1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan + // But on this branch, `i` is an outstanding borrow + x = Some(*i+1); //~ ERROR cannot assign to `x` } } copy x; // just to prevent liveness warnings diff --git a/src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs b/src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs deleted file mode 100644 index dd6eca951b8..00000000000 --- a/src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-pretty -- comments are infaithfully preserved - -fn main() { - let mut x = None; - match x { //~ NOTE loan of mutable local variable granted here - None => { - // It is ok to reassign x here, because there is in - // fact no outstanding loan of x! - x = Some(0); - } - Some(ref _i) => { - x = Some(1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan - } - } - copy x; // just to prevent liveness warnings -} diff --git a/src/test/compile-fail/borrowck-reborrow-from-mut.rs b/src/test/compile-fail/borrowck-reborrow-from-mut.rs index 60f817dee0c..b4bd64f2135 100644 --- a/src/test/compile-fail/borrowck-reborrow-from-mut.rs +++ b/src/test/compile-fail/borrowck-reborrow-from-mut.rs @@ -20,17 +20,17 @@ struct Bar { fn borrow_same_field_twice_mut_mut(foo: &mut Foo) { let _bar1 = &mut foo.bar1; - let _bar2 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow } fn borrow_same_field_twice_mut_imm(foo: &mut Foo) { let _bar1 = &mut foo.bar1; - let _bar2 = &foo.bar1; //~ ERROR conflicts with prior loan + let _bar2 = &foo.bar1; //~ ERROR cannot borrow } fn borrow_same_field_twice_imm_mut(foo: &mut Foo) { let _bar1 = &foo.bar1; - let _bar2 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow } fn borrow_same_field_twice_imm_imm(foo: &mut Foo) { @@ -53,34 +53,34 @@ fn borrow_var_and_pattern(foo: &mut Foo) { let _bar1 = &mut foo.bar1; match *foo { Foo { bar1: ref mut _bar1, bar2: _ } => {} - //~^ ERROR conflicts with prior loan + //~^ ERROR cannot borrow } } fn borrow_mut_and_base_imm(foo: &mut Foo) { let _bar1 = &mut foo.bar1.int1; - let _foo1 = &foo.bar1; //~ ERROR conflicts with prior loan - let _foo2 = &*foo; //~ ERROR conflicts with prior loan + let _foo1 = &foo.bar1; //~ ERROR cannot borrow + let _foo2 = &*foo; //~ ERROR cannot borrow } fn borrow_mut_and_base_mut(foo: &mut Foo) { let _bar1 = &mut foo.bar1.int1; - let _foo1 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow } fn borrow_mut_and_base_mut2(foo: &mut Foo) { let _bar1 = &mut foo.bar1.int1; - let _foo2 = &mut *foo; //~ ERROR conflicts with prior loan + let _foo2 = &mut *foo; //~ ERROR cannot borrow } fn borrow_imm_and_base_mut(foo: &mut Foo) { let _bar1 = &foo.bar1.int1; - let _foo1 = &mut foo.bar1; //~ ERROR conflicts with prior loan + let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow } fn borrow_imm_and_base_mut2(foo: &mut Foo) { let _bar1 = &foo.bar1.int1; - let _foo2 = &mut *foo; //~ ERROR conflicts with prior loan + let _foo2 = &mut *foo; //~ ERROR cannot borrow } fn borrow_imm_and_base_imm(foo: &mut Foo) { @@ -95,7 +95,7 @@ fn borrow_mut_and_imm(foo: &mut Foo) { } fn borrow_mut_from_imm(foo: &Foo) { - let _bar1 = &mut foo.bar1; //~ ERROR illegal borrow + let _bar1 = &mut foo.bar1; //~ ERROR cannot borrow } fn borrow_long_path_both_mut(foo: &mut Foo) { diff --git a/src/test/compile-fail/borrowck-ref-into-rvalue.rs b/src/test/compile-fail/borrowck-ref-into-rvalue.rs index 37ee747069c..18865ad7d54 100644 --- a/src/test/compile-fail/borrowck-ref-into-rvalue.rs +++ b/src/test/compile-fail/borrowck-ref-into-rvalue.rs @@ -10,12 +10,12 @@ fn main() { let msg; - match Some(~"Hello") { //~ ERROR illegal borrow - Some(ref m) => { + match Some(~"Hello") { + Some(ref m) => { //~ ERROR borrowed value does not live long enough msg = m; - }, + }, None => { fail!() } - } + } io::println(*msg); } diff --git a/src/test/compile-fail/borrowck-ref-mut-of-imm.rs b/src/test/compile-fail/borrowck-ref-mut-of-imm.rs index aad86241e9a..3a37116a166 100644 --- a/src/test/compile-fail/borrowck-ref-mut-of-imm.rs +++ b/src/test/compile-fail/borrowck-ref-mut-of-imm.rs @@ -11,7 +11,7 @@ fn destructure(x: Option) -> int { match x { None => 0, - Some(ref mut v) => *v //~ ERROR illegal borrow + Some(ref mut v) => *v //~ ERROR cannot borrow } } diff --git a/src/test/compile-fail/borrowck-unary-move-2.rs b/src/test/compile-fail/borrowck-unary-move-2.rs index 520772f1cee..898830bbe55 100644 --- a/src/test/compile-fail/borrowck-unary-move-2.rs +++ b/src/test/compile-fail/borrowck-unary-move-2.rs @@ -28,5 +28,5 @@ struct wrapper(noncopyable); fn main() { let x1 = wrapper(noncopyable()); - let _x2 = *x1; //~ ERROR moving out of anonymous field + let _x2 = *x1; //~ ERROR cannot move out } diff --git a/src/test/compile-fail/borrowck-unary-move.rs b/src/test/compile-fail/borrowck-unary-move.rs index f95b365ee2e..107e478004a 100644 --- a/src/test/compile-fail/borrowck-unary-move.rs +++ b/src/test/compile-fail/borrowck-unary-move.rs @@ -9,8 +9,8 @@ // except according to those terms. fn foo(+x: ~int) -> int { - let y = &*x; //~ NOTE loan of argument granted here - free(x); //~ ERROR moving out of argument prohibited due to outstanding loan + let y = &*x; + free(x); //~ ERROR cannot move out of `*x` because it is borrowed *y } diff --git a/src/test/compile-fail/borrowck-uniq-via-box.rs b/src/test/compile-fail/borrowck-uniq-via-box.rs deleted file mode 100644 index e1c0e67ff8d..00000000000 --- a/src/test/compile-fail/borrowck-uniq-via-box.rs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct Rec { - f: ~int, -} - -struct Outer { - f: Inner -} - -struct Inner { - g: Innermost -} - -struct Innermost { - h: ~int, -} - -fn borrow(_v: &int) {} - -fn box_mut(v: @mut ~int) { - borrow(*v); //~ ERROR illegal borrow unless pure -} - -fn box_mut_rec(v: @mut Rec) { - borrow(v.f); //~ ERROR illegal borrow unless pure -} - -fn box_mut_recs(v: @mut Outer) { - borrow(v.f.g.h); //~ ERROR illegal borrow unless pure -} - -fn box_imm(v: @~int) { - borrow(*v); // OK -} - -fn box_imm_rec(v: @Rec) { - borrow(v.f); // OK -} - -fn box_imm_recs(v: @Outer) { - borrow(v.f.g.h); // OK -} - -fn main() { -} - diff --git a/src/test/compile-fail/borrowck-uniq-via-lend.rs b/src/test/compile-fail/borrowck-uniq-via-lend.rs index ee96237a26c..80ba1968bc7 100644 --- a/src/test/compile-fail/borrowck-uniq-via-lend.rs +++ b/src/test/compile-fail/borrowck-uniq-via-lend.rs @@ -43,8 +43,8 @@ fn aliased_const() { fn aliased_mut() { let mut v = ~3; - let _w = &mut v; //~ NOTE prior loan as mutable granted here - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan + let _w = &mut v; + borrow(v); //~ ERROR cannot borrow `*v` } fn aliased_other() { @@ -56,8 +56,8 @@ fn aliased_other() { fn aliased_other_reassign() { let mut v = ~3, w = ~4; let mut _x = &mut w; - _x = &mut v; //~ NOTE prior loan as mutable granted here - borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan + _x = &mut v; + borrow(v); //~ ERROR cannot borrow `*v` } fn main() { diff --git a/src/test/compile-fail/borrowck-uniq-via-ref.rs b/src/test/compile-fail/borrowck-uniq-via-ref.rs index 2cf363e13ee..8bf627d9919 100644 --- a/src/test/compile-fail/borrowck-uniq-via-ref.rs +++ b/src/test/compile-fail/borrowck-uniq-via-ref.rs @@ -25,6 +25,7 @@ struct Innermost { } fn borrow(_v: &int) {} +fn borrow_const(_v: &const int) {} fn box_mut(v: &mut ~int) { borrow(*v); // OK: &mut -> &imm @@ -51,15 +52,15 @@ fn box_imm_recs(v: &Outer) { } fn box_const(v: &const ~int) { - borrow(*v); //~ ERROR illegal borrow unless pure + borrow_const(*v); //~ ERROR unsafe borrow } fn box_const_rec(v: &const Rec) { - borrow(v.f); //~ ERROR illegal borrow unless pure + borrow_const(v.f); //~ ERROR unsafe borrow } fn box_const_recs(v: &const Outer) { - borrow(v.f.g.h); //~ ERROR illegal borrow unless pure + borrow_const(v.f.g.h); //~ ERROR unsafe borrow } fn main() { diff --git a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs index c8a0dbedd5d..0c21b64bb0f 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs @@ -1,7 +1,7 @@ fn a() -> &[int] { let vec = [1, 2, 3, 4]; - let tail = match vec { //~ ERROR illegal borrow - [_, ..tail] => tail, + let tail = match vec { + [_, ..tail] => tail, //~ ERROR does not live long enough _ => fail!(~"a") }; tail @@ -9,8 +9,8 @@ fn a() -> &[int] { fn b() -> &[int] { let vec = [1, 2, 3, 4]; - let init = match vec { //~ ERROR illegal borrow - [..init, _] => init, + let init = match vec { + [..init, _] => init, //~ ERROR does not live long enough _ => fail!(~"b") }; init @@ -18,8 +18,8 @@ fn b() -> &[int] { fn c() -> &[int] { let vec = [1, 2, 3, 4]; - let slice = match vec { //~ ERROR illegal borrow - [_, ..slice, _] => slice, + let slice = match vec { + [_, ..slice, _] => slice, //~ ERROR does not live long enough _ => fail!(~"c") }; slice diff --git a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs index 27902100373..6b51fc8f5b3 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs @@ -2,7 +2,7 @@ fn a() { let mut v = ~[1, 2, 3]; match v { [_a, ..tail] => { - v.push(tail[0] + tail[1]); //~ ERROR conflicts with prior loan + v.push(tail[0] + tail[1]); //~ ERROR cannot borrow } _ => {} }; diff --git a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs index 16b48aedb0c..2898e312930 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs @@ -1,8 +1,9 @@ fn main() { let mut a = [1, 2, 3, 4]; - let _ = match a { + let t = match a { [1, 2, ..tail] => tail, _ => core::util::unreachable() }; - a[0] = 0; //~ ERROR: assigning to mutable vec content prohibited due to outstanding loan + a[0] = 0; //~ ERROR cannot assign to `a[]` because it is borrowed + t[0]; } diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs index 05ff85d612c..16711ea61ff 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs @@ -2,7 +2,7 @@ fn a() { let mut vec = [~1, ~2, ~3]; match vec { [~ref _a] => { - vec[0] = ~4; //~ ERROR prohibited due to outstanding loan + vec[0] = ~4; //~ ERROR cannot assign to `vec[]` because it is borrowed } _ => fail!(~"foo") } @@ -12,7 +12,7 @@ fn b() { let mut vec = [~1, ~2, ~3]; match vec { [.._b] => { - vec[0] = ~4; //~ ERROR prohibited due to outstanding loan + vec[0] = ~4; //~ ERROR cannot assign to `vec[]` because it is borrowed } } } diff --git a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs index 714a80def93..dbdd8f0809a 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs @@ -1,7 +1,7 @@ fn a() -> &int { let vec = [1, 2, 3, 4]; - let tail = match vec { //~ ERROR illegal borrow - [_a, ..tail] => &tail[0], + let tail = match vec { + [_a, ..tail] => &tail[0], //~ ERROR borrowed value does not live long enough _ => fail!(~"foo") }; tail diff --git a/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail-2.rs b/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail-2.rs index e47ad721b0d..5ef23897ec0 100644 --- a/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail-2.rs +++ b/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail-2.rs @@ -1,6 +1,6 @@ fn main() { let mut b = ~3; - let _x = &mut *b; //~ NOTE prior loan as mutable granted here - let _y = &mut *b; //~ ERROR loan of dereference of mutable ~ pointer as mutable conflicts with prior loan + let _x = &mut *b; + let _y = &mut *b; //~ ERROR cannot borrow } diff --git a/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail-3.rs b/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail-3.rs index 015f368ecb0..a744127a600 100644 --- a/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail-3.rs +++ b/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail-3.rs @@ -1,8 +1,8 @@ fn main() { let mut a = ~3; - let mut b = &mut a; //~ NOTE loan of mutable local variable granted here + let mut b = &mut a; let _c = &mut *b; - let mut d = /*move*/ a; //~ ERROR moving out of mutable local variable prohibited due to outstanding loan + let mut d = /*move*/ a; //~ ERROR cannot move out *d += 1; } diff --git a/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail.rs b/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail.rs index 36d32fddda1..44da00d8d17 100644 --- a/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail.rs +++ b/src/test/compile-fail/borrowck-wg-borrow-mut-to-imm-fail.rs @@ -1,7 +1,7 @@ fn main() { let mut b = ~3; - let _x = &mut *b; //~ NOTE loan of mutable local variable granted here - let mut y = /*move*/ b; //~ ERROR moving out of mutable local variable prohibited + let _x = &mut *b; + let mut y = /*move*/ b; //~ ERROR cannot move out *y += 1; } diff --git a/src/test/compile-fail/borrowck-wg-move-base-2.rs b/src/test/compile-fail/borrowck-wg-move-base-2.rs index ba85616e63f..8a218771453 100644 --- a/src/test/compile-fail/borrowck-wg-move-base-2.rs +++ b/src/test/compile-fail/borrowck-wg-move-base-2.rs @@ -2,7 +2,7 @@ fn foo(x: &mut int) { let mut a = 3; let mut _y = &mut *x; let _z = &mut *_y; - _y = &mut a; //~ ERROR assigning to mutable local variable prohibited + _y = &mut a; //~ ERROR cannot assign } fn main() { diff --git a/src/test/compile-fail/fn-variance-3.rs b/src/test/compile-fail/fn-variance-3.rs index 5df2007721d..4d145d3f9ea 100644 --- a/src/test/compile-fail/fn-variance-3.rs +++ b/src/test/compile-fail/fn-variance-3.rs @@ -31,5 +31,5 @@ fn main() { // mutability check will fail, because the // type of r has been inferred to be // fn(@const int) -> @const int - *r(@mut 3) = 4; //~ ERROR assigning to dereference of const @ pointer + *r(@mut 3) = 4; //~ ERROR cannot assign to const dereference of @ pointer } diff --git a/src/test/compile-fail/immut-function-arguments.rs b/src/test/compile-fail/immut-function-arguments.rs index 2084729372d..66b5bd172ca 100644 --- a/src/test/compile-fail/immut-function-arguments.rs +++ b/src/test/compile-fail/immut-function-arguments.rs @@ -9,11 +9,11 @@ // except according to those terms. fn f(y: ~int) { - *y = 5; //~ ERROR assigning to dereference of immutable ~ pointer + *y = 5; //~ ERROR cannot assign } fn g() { - let _frob: &fn(~int) = |q| { *q = 2; }; //~ ERROR assigning to dereference of immutable ~ pointer + let _frob: &fn(~int) = |q| { *q = 2; }; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/index_message.rs b/src/test/compile-fail/index_message.rs index 3611dbb6866..26dd98757a8 100644 --- a/src/test/compile-fail/index_message.rs +++ b/src/test/compile-fail/index_message.rs @@ -10,5 +10,5 @@ fn main() { let z = (); - debug!(z[0]); //~ ERROR cannot index a value of type `()` + let _ = z[0]; //~ ERROR cannot index a value of type `()` } diff --git a/src/test/compile-fail/issue-1896-1.rs b/src/test/compile-fail/issue-1896-1.rs index fc5132d6510..13adcd42da2 100644 --- a/src/test/compile-fail/issue-1896-1.rs +++ b/src/test/compile-fail/issue-1896-1.rs @@ -8,11 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// Test that we require managed closures to be rooted when borrowed. + struct boxedFn<'self> { theFn: &'self fn() -> uint } fn createClosure (closedUint: uint) -> boxedFn { let theFn: @fn() -> uint = || closedUint; - boxedFn {theFn: theFn} //~ ERROR illegal borrow + boxedFn {theFn: theFn} //~ ERROR cannot root } fn main () { diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 2842d884c99..cdc8d546dd8 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -23,5 +23,4 @@ impl vec_monad for ~[A] { fn main() { ["hi"].bind(|x| [x] ); //~^ ERROR type `[&'static str, .. 1]` does not implement any method in scope named `bind` - //~^^ ERROR Unconstrained region variable } diff --git a/src/test/compile-fail/issue-2151.rs b/src/test/compile-fail/issue-2151.rs index e2bbda7d65a..bb6d47a4762 100644 --- a/src/test/compile-fail/issue-2151.rs +++ b/src/test/compile-fail/issue-2151.rs @@ -10,7 +10,6 @@ fn main() { for vec::each(fail!()) |i| { - debug!(i * 2); - //~^ ERROR the type of this value must be known + let _ = i * 2; //~ ERROR the type of this value must be known }; } diff --git a/src/test/compile-fail/issue-2590.rs b/src/test/compile-fail/issue-2590.rs index 7a99ab8a94f..a0b967d5959 100644 --- a/src/test/compile-fail/issue-2590.rs +++ b/src/test/compile-fail/issue-2590.rs @@ -18,7 +18,7 @@ trait parse { impl parse for parser { fn parse(&self) -> ~[int] { - self.tokens //~ ERROR moving out of immutable field + self.tokens //~ ERROR cannot move out of field } } diff --git a/src/test/compile-fail/issue-3044.rs b/src/test/compile-fail/issue-3044.rs index fcd5b1deee5..23b11bbe409 100644 --- a/src/test/compile-fail/issue-3044.rs +++ b/src/test/compile-fail/issue-3044.rs @@ -11,7 +11,6 @@ fn main() { let needlesArr: ~[char] = ~['a', 'f']; do vec::foldr(needlesArr) |x, y| { - //~^ ERROR Unconstrained region variable #2 } //~^ ERROR 2 parameters were supplied (including the closure passed by the `do` keyword) // diff --git a/src/test/compile-fail/issue-4500.rs b/src/test/compile-fail/issue-4500.rs deleted file mode 100644 index 356a6449821..00000000000 --- a/src/test/compile-fail/issue-4500.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main () { - let mut _p: & int = & 4; - _p = &*~3; //~ ERROR illegal borrow -} diff --git a/src/test/compile-fail/issue-511.rs b/src/test/compile-fail/issue-511.rs index 90c46e5d602..c872f89d884 100644 --- a/src/test/compile-fail/issue-511.rs +++ b/src/test/compile-fail/issue-511.rs @@ -17,5 +17,5 @@ fn f(o: &mut Option) { fn main() { f::(&mut option::None); - //~^ ERROR illegal borrow: creating mutable alias to static item + //~^ ERROR cannot borrow } diff --git a/src/test/compile-fail/kindck-owned-trait-contains.rs b/src/test/compile-fail/kindck-owned-trait-contains.rs index 54ee8bcc70e..6bb90bff228 100644 --- a/src/test/compile-fail/kindck-owned-trait-contains.rs +++ b/src/test/compile-fail/kindck-owned-trait-contains.rs @@ -29,4 +29,7 @@ fn main() { }; assert!(3 == *(y.get())); //~ ERROR dereference of reference outside its lifetime //~^ ERROR reference is not valid outside of its lifetime + //~^^ ERROR reference is not valid outside of its lifetime + //~^^^ ERROR reference is not valid outside of its lifetime + //~^^^^ ERROR cannot infer an appropriate lifetime } diff --git a/src/test/compile-fail/lambda-mutate-nested.rs b/src/test/compile-fail/lambda-mutate-nested.rs index 8b009b91af9..bfd1e12f3a6 100644 --- a/src/test/compile-fail/lambda-mutate-nested.rs +++ b/src/test/compile-fail/lambda-mutate-nested.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:assigning to captured outer immutable variable in a stack closure // Make sure that nesting a block within a @fn doesn't let us // mutate upvars from a @fn. fn f2(x: &fn()) { x(); } @@ -16,6 +15,7 @@ fn f2(x: &fn()) { x(); } fn main() { let i = 0; let ctr: @fn() -> int = || { f2(|| i = i + 1 ); i }; + //~^ ERROR cannot assign error!(ctr()); error!(ctr()); error!(ctr()); diff --git a/src/test/compile-fail/lambda-mutate.rs b/src/test/compile-fail/lambda-mutate.rs index ee5b3d89684..a848d8698a3 100644 --- a/src/test/compile-fail/lambda-mutate.rs +++ b/src/test/compile-fail/lambda-mutate.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:assigning to captured outer variable in a heap closure // Make sure we can't write to upvars from @fns fn main() { let i = 0; let ctr: @fn() -> int = || { i = i + 1; i }; + //~^ ERROR cannot assign error!(ctr()); error!(ctr()); error!(ctr()); diff --git a/src/test/compile-fail/moves-based-on-type-block-bad.rs b/src/test/compile-fail/moves-based-on-type-block-bad.rs index 020dadfc96c..feeaadeea82 100644 --- a/src/test/compile-fail/moves-based-on-type-block-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-block-bad.rs @@ -16,7 +16,7 @@ fn main() { let s = S { x: ~Bar(~42) }; loop { do f(&s) |hellothere| { - match hellothere.x { //~ ERROR moving out of immutable field + match hellothere.x { //~ ERROR cannot move out ~Foo(_) => {} ~Bar(x) => io::println(x.to_str()), ~Baz => {} diff --git a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs index 3c15047a296..ecd58d485a8 100644 --- a/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs +++ b/src/test/compile-fail/moves-based-on-type-move-out-of-closure-env-issue-1965.rs @@ -13,6 +13,6 @@ fn test(_x: ~uint) {} fn main() { let i = ~3; for uint::range(0, 10) |_x| { - test(i); //~ ERROR moving out of captured outer immutable variable in a stack closure + test(i); //~ ERROR cannot move out } } diff --git a/src/test/compile-fail/mutable-class-fields-2.rs b/src/test/compile-fail/mutable-class-fields-2.rs index 56c715c9847..f5d24b31641 100644 --- a/src/test/compile-fail/mutable-class-fields-2.rs +++ b/src/test/compile-fail/mutable-class-fields-2.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:assigning to immutable field struct cat { priv mut meows : uint, @@ -17,7 +16,7 @@ struct cat { pub impl cat { fn eat(&self) { - self.how_hungry -= 5; + self.how_hungry -= 5; //~ ERROR cannot assign } } diff --git a/src/test/compile-fail/mutable-class-fields.rs b/src/test/compile-fail/mutable-class-fields.rs index 6d11a98c0cb..8bebec7134c 100644 --- a/src/test/compile-fail/mutable-class-fields.rs +++ b/src/test/compile-fail/mutable-class-fields.rs @@ -8,12 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:assigning to immutable field struct cat { priv mut meows : uint, - how_hungry : int, - } fn cat(in_x : uint, in_y : int) -> cat { @@ -25,5 +22,5 @@ fn cat(in_x : uint, in_y : int) -> cat { fn main() { let nyan : cat = cat(52u, 99); - nyan.how_hungry = 0; + nyan.how_hungry = 0; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/mutable-huh-ptr-assign.rs b/src/test/compile-fail/mutable-huh-ptr-assign.rs index ed356f4001d..6b3fd4f7153 100644 --- a/src/test/compile-fail/mutable-huh-ptr-assign.rs +++ b/src/test/compile-fail/mutable-huh-ptr-assign.rs @@ -12,7 +12,7 @@ extern mod std; fn main() { unsafe fn f(&&v: *const int) { - *v = 1 //~ ERROR assigning to dereference of const * pointer + *v = 1 //~ ERROR cannot assign } unsafe { diff --git a/src/test/compile-fail/regions-addr-of-arg.rs b/src/test/compile-fail/regions-addr-of-arg.rs index 7f2140d96e1..4fff5a6f87c 100644 --- a/src/test/compile-fail/regions-addr-of-arg.rs +++ b/src/test/compile-fail/regions-addr-of-arg.rs @@ -9,7 +9,7 @@ // except according to those terms. fn foo(a: int) { - let _p: &'static int = &a; //~ ERROR illegal borrow + let _p: &'static int = &a; //~ ERROR borrowed value does not live long enough } fn bar(a: int) { diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index 120428e02f4..2ab0c14b49b 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -30,12 +30,12 @@ fn compute(x: &ast) -> uint { fn map_nums(x: &ast, f: &fn(uint) -> uint) -> &ast { match *x { num(x) => { - return &num(f(x)); //~ ERROR illegal borrow + return &num(f(x)); //~ ERROR borrowed value does not live long enough } add(x, y) => { let m_x = map_nums(x, f); let m_y = map_nums(y, f); - return &add(m_x, m_y); //~ ERROR illegal borrow + return &add(m_x, m_y); //~ ERROR borrowed value does not live long enough } } } diff --git a/src/test/compile-fail/regions-creating-enums4.rs b/src/test/compile-fail/regions-creating-enums4.rs index 1cb378cf406..8f764745697 100644 --- a/src/test/compile-fail/regions-creating-enums4.rs +++ b/src/test/compile-fail/regions-creating-enums4.rs @@ -14,8 +14,7 @@ enum ast<'self> { } fn mk_add_bad2<'a>(x: &'a ast<'a>, y: &'a ast<'a>, z: &ast) -> ast { - add(x, y) - //~^ ERROR cannot infer an appropriate lifetime + add(x, y) //~ ERROR cannot infer an appropriate lifetime } fn main() { diff --git a/src/test/compile-fail/regions-escape-bound-fn.rs b/src/test/compile-fail/regions-escape-bound-fn.rs index c81ef77f497..5ac5e334be2 100644 --- a/src/test/compile-fail/regions-escape-bound-fn.rs +++ b/src/test/compile-fail/regions-escape-bound-fn.rs @@ -14,6 +14,6 @@ fn with_int(f: &fn(x: &int)) { } fn main() { - let mut x: Option<&int> = None; //~ ERROR cannot infer + let mut x: Option<&int> = None; //~ ERROR cannot infer with_int(|y| x = Some(y)); } diff --git a/src/test/compile-fail/regions-escape-loop-via-variable.rs b/src/test/compile-fail/regions-escape-loop-via-variable.rs index ac10b5c454a..19bd0bf9747 100644 --- a/src/test/compile-fail/regions-escape-loop-via-variable.rs +++ b/src/test/compile-fail/regions-escape-loop-via-variable.rs @@ -18,6 +18,6 @@ fn main() { loop { let x = 1 + *p; - p = &x; //~ ERROR illegal borrow + p = &x; //~ ERROR borrowed value does not live long enough } } diff --git a/src/test/compile-fail/regions-escape-loop-via-vec.rs b/src/test/compile-fail/regions-escape-loop-via-vec.rs index da5e3c2660e..92e2cd73dfb 100644 --- a/src/test/compile-fail/regions-escape-loop-via-vec.rs +++ b/src/test/compile-fail/regions-escape-loop-via-vec.rs @@ -14,8 +14,8 @@ fn broken() { let mut _y = ~[&mut x]; while x < 10 { let mut z = x; - _y.push(&mut z); //~ ERROR illegal borrow - x += 1; //~ ERROR assigning to mutable local variable prohibited due to outstanding loan + _y.push(&mut z); //~ ERROR borrowed value does not live long enough + x += 1; //~ ERROR cannot assign } } diff --git a/src/test/compile-fail/regions-escape-via-trait-or-not.rs b/src/test/compile-fail/regions-escape-via-trait-or-not.rs index f7165784c79..aa431d6b81c 100644 --- a/src/test/compile-fail/regions-escape-via-trait-or-not.rs +++ b/src/test/compile-fail/regions-escape-via-trait-or-not.rs @@ -23,13 +23,8 @@ fn with(f: &fn(x: &int) -> R) -> int { } fn return_it() -> int { - with(|o| o) - //~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements - //~^^ ERROR reference is not valid outside of its lifetime - //~^^^ ERROR reference is not valid outside of its lifetime + with(|o| o) //~ ERROR reference is not valid outside of its lifetime } fn main() { - let x = return_it(); - debug!("foo=%d", x); } diff --git a/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs b/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs index a8b7ae1b9c8..6e9d6c1ef0f 100644 --- a/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs +++ b/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs @@ -18,7 +18,7 @@ fn x_coord<'r>(p: &'r point) -> &'r int { } fn foo(p: @point) -> &int { - let xc = x_coord(p); //~ ERROR illegal borrow + let xc = x_coord(p); //~ ERROR cannot root assert!(*xc == 3); return xc; } diff --git a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs index bf8f227b573..d23e20130f7 100644 --- a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs +++ b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs @@ -17,7 +17,7 @@ fn foo(cond: &fn() -> bool, box: &fn() -> @int) { // Here we complain because the resulting region // of this borrow is the fn body as a whole. - y = borrow(x); //~ ERROR illegal borrow: cannot root managed value long enough + y = borrow(x); //~ ERROR cannot root assert!(*x == *y); if cond() { break; } diff --git a/src/test/compile-fail/regions-nested-fns-2.rs b/src/test/compile-fail/regions-nested-fns-2.rs index 2e9a4eb1410..fe995052c52 100644 --- a/src/test/compile-fail/regions-nested-fns-2.rs +++ b/src/test/compile-fail/regions-nested-fns-2.rs @@ -13,7 +13,7 @@ fn ignore(_f: &fn<'z>(&'z int) -> &'z int) {} fn nested() { let y = 3; ignore(|z| { - if false { &y } else { z } //~ ERROR illegal borrow + if false { &y } else { z } //~ ERROR borrowed value does not live long enough }); } diff --git a/src/test/compile-fail/regions-nested-fns.rs b/src/test/compile-fail/regions-nested-fns.rs index 3089c362a50..74399967446 100644 --- a/src/test/compile-fail/regions-nested-fns.rs +++ b/src/test/compile-fail/regions-nested-fns.rs @@ -16,7 +16,7 @@ fn nested<'x>(x: &'x int) { ignore::<&fn<'z>(&'z int)>(|z| { ay = x; - ay = &y; //~ ERROR cannot infer an appropriate lifetime + ay = &y; ay = z; }); diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index f916b0d95c2..f600f6f6edd 100644 --- a/src/test/compile-fail/regions-ret-borrowed-1.rs +++ b/src/test/compile-fail/regions-ret-borrowed-1.rs @@ -19,6 +19,7 @@ fn with<'a, R>(f: &fn(x: &'a int) -> R) -> R { fn return_it<'a>() -> &'a int { with(|o| o) //~ ERROR mismatched types //~^ ERROR reference is not valid outside of its lifetime + //~^^ ERROR reference is not valid outside of its lifetime } fn main() { diff --git a/src/test/compile-fail/regions-ret-borrowed.rs b/src/test/compile-fail/regions-ret-borrowed.rs index 157b99de9e8..a3540f8f931 100644 --- a/src/test/compile-fail/regions-ret-borrowed.rs +++ b/src/test/compile-fail/regions-ret-borrowed.rs @@ -22,6 +22,7 @@ fn with(f: &fn(x: &int) -> R) -> R { fn return_it() -> &int { with(|o| o) //~ ERROR mismatched types //~^ ERROR reference is not valid outside of its lifetime + //~^^ ERROR reference is not valid outside of its lifetime } fn main() { diff --git a/src/test/compile-fail/regions-ret.rs b/src/test/compile-fail/regions-ret.rs index be7b28f6ef4..f1a7bdf2281 100644 --- a/src/test/compile-fail/regions-ret.rs +++ b/src/test/compile-fail/regions-ret.rs @@ -9,7 +9,7 @@ // except according to those terms. fn f<'a>(_x : &'a int) -> &'a int { - return &3; //~ ERROR illegal borrow + return &3; //~ ERROR borrowed value does not live long enough } fn main() { diff --git a/src/test/compile-fail/regions-var-type-out-of-scope.rs b/src/test/compile-fail/regions-var-type-out-of-scope.rs index 7d75ac74349..addf20fd702 100644 --- a/src/test/compile-fail/regions-var-type-out-of-scope.rs +++ b/src/test/compile-fail/regions-var-type-out-of-scope.rs @@ -14,7 +14,7 @@ fn foo(cond: bool) { let mut x; if cond { - x = &3; //~ ERROR illegal borrow: borrowed value does not live long enough + x = &3; //~ ERROR borrowed value does not live long enough assert!((*x == 3)); } } diff --git a/src/test/compile-fail/swap-no-lval.rs b/src/test/compile-fail/swap-no-lval.rs index 4fe30792e4b..eca5fb0d315 100644 --- a/src/test/compile-fail/swap-no-lval.rs +++ b/src/test/compile-fail/swap-no-lval.rs @@ -10,6 +10,6 @@ fn main() { 5 <-> 3; - //~^ ERROR swapping to and from non-lvalue - //~^^ ERROR swapping to and from non-lvalue + //~^ ERROR cannot assign + //~^^ ERROR cannot assign } diff --git a/src/test/compile-fail/writing-to-immutable-vec.rs b/src/test/compile-fail/writing-to-immutable-vec.rs index 3f4c8ccef81..faa3d6cfe47 100644 --- a/src/test/compile-fail/writing-to-immutable-vec.rs +++ b/src/test/compile-fail/writing-to-immutable-vec.rs @@ -8,5 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:assigning to immutable vec content -fn main() { let v: ~[int] = ~[1, 2, 3]; v[1] = 4; } +fn main() { + let v: ~[int] = ~[1, 2, 3]; + v[1] = 4; //~ ERROR cannot assign +} diff --git a/src/test/run-pass/borrowck-nested-calls.rs b/src/test/run-pass/borrowck-nested-calls.rs new file mode 100644 index 00000000000..4494f5f2fa3 --- /dev/null +++ b/src/test/run-pass/borrowck-nested-calls.rs @@ -0,0 +1,32 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// xfail-test #5074 nested method calls + +// Test that (safe) nested calls with `&mut` receivers are permitted. + +struct Foo {a: uint, b: uint} + +pub impl Foo { + fn inc_a(&mut self, v: uint) { self.a += v; } + + fn next_b(&mut self) -> uint { + let b = self.b; + self.b += 1; + b + } +} + +fn main() { + let mut f = Foo {a: 22, b: 23}; + f.inc_a(f.next_b()); + assert_eq!(f.a, 22+23); + assert_eq!(f.b, 24); +} diff --git a/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs b/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs index 0e67532d7a1..b0d06dae10d 100644 --- a/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs @@ -1,10 +1,10 @@ trait Reverser { - fn reverse(&self); + fn reverse(self); } impl<'self> Reverser for &'self mut [uint] { - fn reverse(&self) { - vec::reverse(*self); + fn reverse(self) { + vec::reverse(self); } } diff --git a/src/test/run-pass/issue-2735-2.rs b/src/test/run-pass/issue-2735-2.rs index 96f76b0fd6b..ca584e1a6e3 100644 --- a/src/test/run-pass/issue-2735-2.rs +++ b/src/test/run-pass/issue-2735-2.rs @@ -9,27 +9,25 @@ // except according to those terms. // This test should behave exactly like issue-2735-3 -struct defer<'self> { - b: &'self mut bool, +struct defer { + b: @mut bool, } #[unsafe_destructor] -impl<'self> Drop for defer<'self> { +impl Drop for defer { fn finalize(&self) { - unsafe { - *(self.b) = true; - } + *self.b = true; } } -fn defer<'r>(b: &'r mut bool) -> defer<'r> { +fn defer(b: @mut bool) -> defer { defer { b: b } } pub fn main() { - let mut dtor_ran = false; - let _ = defer(&mut dtor_ran); - assert!((dtor_ran)); + let dtor_ran = @mut false; + let _ = defer(dtor_ran); + assert!(*dtor_ran); } diff --git a/src/test/run-pass/issue-2735-3.rs b/src/test/run-pass/issue-2735-3.rs index 50e3c946f50..44ca5d6929b 100644 --- a/src/test/run-pass/issue-2735-3.rs +++ b/src/test/run-pass/issue-2735-3.rs @@ -9,27 +9,25 @@ // except according to those terms. // This test should behave exactly like issue-2735-2 -struct defer<'self> { - b: &'self mut bool, +struct defer { + b: @mut bool, } #[unsafe_destructor] -impl<'self> Drop for defer<'self> { +impl Drop for defer { fn finalize(&self) { - unsafe { - *(self.b) = true; - } + *self.b = true; } } -fn defer<'r>(b: &'r mut bool) -> defer<'r> { +fn defer(b: @mut bool) -> defer { defer { b: b } } pub fn main() { - let mut dtor_ran = false; - defer(&mut dtor_ran); - assert!((dtor_ran)); + let dtor_ran = @mut false; + defer(dtor_ran); + assert!(*dtor_ran); } -- cgit 1.4.1-3-g733a5