diff options
| author | Flavio Percoco <flaper87@gmail.com> | 2014-04-17 00:58:55 +0200 |
|---|---|---|
| committer | Flavio Percoco <flaper87@gmail.com> | 2014-04-23 18:19:36 +0200 |
| commit | fa43f6a7a651f57fb0ca65a704cbaa3d75e727a9 (patch) | |
| tree | 2de0d38c7fafaf20cba457582af49d67a77b7822 | |
| parent | bea94993d2f3534caefb3bc1a53255869c0796e0 (diff) | |
| download | rust-fa43f6a7a651f57fb0ca65a704cbaa3d75e727a9.tar.gz rust-fa43f6a7a651f57fb0ca65a704cbaa3d75e727a9.zip | |
Update tests and move other tests around
| -rw-r--r-- | src/test/compile-fail/borrowck-managed-pointer-deref-scope.rs | 33 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-infer-borrow-scope-too-big.rs | 28 | ||||
| -rw-r--r-- | src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs | 30 | ||||
| -rw-r--r-- | src/test/compile-fail/struct-field-assignability.rs (renamed from src/test/run-pass/struct-field-assignability.rs) | 2 | ||||
| -rw-r--r-- | src/test/run-pass/borrowck-preserve-box-in-field.rs | 37 | ||||
| -rw-r--r-- | src/test/run-pass/borrowck-preserve-box-in-uniq.rs | 37 | ||||
| -rw-r--r-- | src/test/run-pass/borrowck-preserve-box.rs | 35 | ||||
| -rw-r--r-- | src/test/run-pass/borrowck-preserve-cond-box.rs | 45 | ||||
| -rw-r--r-- | src/test/run-pass/borrowck-preserve-expl-deref.rs | 37 |
9 files changed, 283 insertions, 1 deletions
diff --git a/src/test/compile-fail/borrowck-managed-pointer-deref-scope.rs b/src/test/compile-fail/borrowck-managed-pointer-deref-scope.rs new file mode 100644 index 00000000000..4695360a688 --- /dev/null +++ b/src/test/compile-fail/borrowck-managed-pointer-deref-scope.rs @@ -0,0 +1,33 @@ +// Copyright 2014 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Verify that managed pointers scope is treated like ownoed pointers. +// regresion test for #11586 + +#![feature(managed_boxes)] + +fn foo<'a>(x: &'a @int) -> &'a int { + match x { + &ref y => { + &**y // Do not expect an error here + } + } +} + +fn bar() { + let a = 3; + let mut y = &a; + if true { + let x = @3; + y = &*x; //~ ERROR `*x` does not live long enough + } +} + +fn main() {} 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 new file mode 100644 index 00000000000..1508349344c --- /dev/null +++ b/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs @@ -0,0 +1,28 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(managed_boxes)] + +struct point { + x: int, + y: int, +} + +fn x_coord<'r>(p: &'r point) -> &'r int { + return &p.x; +} + +fn foo(p: @point) -> &int { + let xc = x_coord(p); //~ ERROR `*p` does not live long enough + assert_eq!(*xc, 3); + return xc; +} + +fn main() {} 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 new file mode 100644 index 00000000000..3cd70ce6c8a --- /dev/null +++ b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs @@ -0,0 +1,30 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(managed_boxes)] + +fn borrow<'r, T>(x: &'r T) -> &'r T {x} + +fn foo(cond: || -> bool, make_box: || -> @int) { + let mut y: ∫ + loop { + let x = make_box(); + + // Here we complain because the resulting region + // of this borrow is the fn body as a whole. + y = borrow(x); //~ ERROR `*x` does not live long enough + + assert_eq!(*x, *y); + if cond() { break; } + } + assert!(*y != 0); +} + +fn main() {} diff --git a/src/test/run-pass/struct-field-assignability.rs b/src/test/compile-fail/struct-field-assignability.rs index 3469936c05b..68a17266106 100644 --- a/src/test/run-pass/struct-field-assignability.rs +++ b/src/test/compile-fail/struct-field-assignability.rs @@ -15,6 +15,6 @@ struct Foo<'a> { } pub fn main() { - let f = Foo { x: @3 }; + let f = Foo { x: @3 }; //~ ERROR borrowed value does not live long enough assert_eq!(*f.x, 3); } diff --git a/src/test/run-pass/borrowck-preserve-box-in-field.rs b/src/test/run-pass/borrowck-preserve-box-in-field.rs new file mode 100644 index 00000000000..f05b8c67d77 --- /dev/null +++ b/src/test/run-pass/borrowck-preserve-box-in-field.rs @@ -0,0 +1,37 @@ +// ignore-pretty + +// Copyright 2012-2014 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn borrow(x: &int, f: |x: &int|) { + let before = *x; + f(x); + let after = *x; + assert_eq!(before, after); +} + +struct F { f: ~int } + +pub fn main() { + let mut x = @F {f: ~3}; + borrow(x.f, |b_x| { + assert_eq!(*b_x, 3); + assert_eq!(&(*x.f) as *int, &(*b_x) as *int); + x = @F {f: ~4}; + + println!("&*b_x = {:p}", &(*b_x)); + assert_eq!(*b_x, 3); + assert!(&(*x.f) as *int != &(*b_x) as *int); + }) +} diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs new file mode 100644 index 00000000000..0896d4de625 --- /dev/null +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -0,0 +1,37 @@ +// ignore-pretty + +// Copyright 2012-2014 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn borrow(x: &int, f: |x: &int|) { + let before = *x; + f(x); + let after = *x; + assert_eq!(before, after); +} + +struct F { f: ~int } + +pub fn main() { + let mut x = ~@F{f: ~3}; + borrow(x.f, |b_x| { + assert_eq!(*b_x, 3); + assert_eq!(&(*x.f) as *int, &(*b_x) as *int); + *x = @F{f: ~4}; + + println!("&*b_x = {:p}", &(*b_x)); + assert_eq!(*b_x, 3); + assert!(&(*x.f) as *int != &(*b_x) as *int); + }) +} diff --git a/src/test/run-pass/borrowck-preserve-box.rs b/src/test/run-pass/borrowck-preserve-box.rs new file mode 100644 index 00000000000..cfb9a4b91df --- /dev/null +++ b/src/test/run-pass/borrowck-preserve-box.rs @@ -0,0 +1,35 @@ +// ignore-pretty + +// Copyright 2012-2014 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn borrow(x: &int, f: |x: &int|) { + let before = *x; + f(x); + let after = *x; + assert_eq!(before, after); +} + +pub fn main() { + let mut x = @3; + borrow(x, |b_x| { + assert_eq!(*b_x, 3); + assert_eq!(&(*x) as *int, &(*b_x) as *int); + x = @22; + + println!("&*b_x = {:p}", &(*b_x)); + assert_eq!(*b_x, 3); + assert!(&(*x) as *int != &(*b_x) as *int); + }) +} diff --git a/src/test/run-pass/borrowck-preserve-cond-box.rs b/src/test/run-pass/borrowck-preserve-cond-box.rs new file mode 100644 index 00000000000..52ea474dbf5 --- /dev/null +++ b/src/test/run-pass/borrowck-preserve-cond-box.rs @@ -0,0 +1,45 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn testfn(cond: bool) { + let mut x = @3; + let mut y = @4; + + // borrow x and y + let r_x = &*x; + let r_y = &*y; + let mut r = r_x; + let mut exp = 3; + + if cond { + r = r_y; + exp = 4; + } + + println!("*r = {}, exp = {}", *r, exp); + assert_eq!(*r, exp); + + x = @5; + y = @6; + + println!("*r = {}, exp = {}", *r, exp); + assert_eq!(*r, exp); + assert_eq!(x, @5); + assert_eq!(y, @6); +} + +pub fn main() { + testfn(true); + testfn(false); +} diff --git a/src/test/run-pass/borrowck-preserve-expl-deref.rs b/src/test/run-pass/borrowck-preserve-expl-deref.rs new file mode 100644 index 00000000000..749c8063950 --- /dev/null +++ b/src/test/run-pass/borrowck-preserve-expl-deref.rs @@ -0,0 +1,37 @@ +// ignore-pretty + +// Copyright 2012-2014 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn borrow(x: &int, f: |x: &int|) { + let before = *x; + f(x); + let after = *x; + assert_eq!(before, after); +} + +struct F { f: ~int } + +pub fn main() { + let mut x = @F {f: ~3}; + borrow((*x).f, |b_x| { + assert_eq!(*b_x, 3); + assert_eq!(&(*x.f) as *int, &(*b_x) as *int); + x = @F {f: ~4}; + + println!("&*b_x = {:p}", &(*b_x)); + assert_eq!(*b_x, 3); + assert!(&(*x.f) as *int != &(*b_x) as *int); + }) +} |
