Skip to content

Commit fa43f6a

Browse files
committed
Update tests and move other tests around
1 parent bea9499 commit fa43f6a

9 files changed

+283
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Verify that managed pointers scope is treated like ownoed pointers.
12+
// regresion test for #11586
13+
14+
#![feature(managed_boxes)]
15+
16+
fn foo<'a>(x: &'a @int) -> &'a int {
17+
match x {
18+
&ref y => {
19+
&**y // Do not expect an error here
20+
}
21+
}
22+
}
23+
24+
fn bar() {
25+
let a = 3;
26+
let mut y = &a;
27+
if true {
28+
let x = @3;
29+
y = &*x; //~ ERROR `*x` does not live long enough
30+
}
31+
}
32+
33+
fn main() {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(managed_boxes)]
12+
13+
struct point {
14+
x: int,
15+
y: int,
16+
}
17+
18+
fn x_coord<'r>(p: &'r point) -> &'r int {
19+
return &p.x;
20+
}
21+
22+
fn foo(p: @point) -> &int {
23+
let xc = x_coord(p); //~ ERROR `*p` does not live long enough
24+
assert_eq!(*xc, 3);
25+
return xc;
26+
}
27+
28+
fn main() {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(managed_boxes)]
12+
13+
fn borrow<'r, T>(x: &'r T) -> &'r T {x}
14+
15+
fn foo(cond: || -> bool, make_box: || -> @int) {
16+
let mut y: &int;
17+
loop {
18+
let x = make_box();
19+
20+
// Here we complain because the resulting region
21+
// of this borrow is the fn body as a whole.
22+
y = borrow(x); //~ ERROR `*x` does not live long enough
23+
24+
assert_eq!(*x, *y);
25+
if cond() { break; }
26+
}
27+
assert!(*y != 0);
28+
}
29+
30+
fn main() {}

src/test/run-pass/struct-field-assignability.rs renamed to src/test/compile-fail/struct-field-assignability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ struct Foo<'a> {
1515
}
1616

1717
pub fn main() {
18-
let f = Foo { x: @3 };
18+
let f = Foo { x: @3 }; //~ ERROR borrowed value does not live long enough
1919
assert_eq!(*f.x, 3);
2020
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// ignore-pretty
2+
3+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
4+
// file at the top-level directory of this distribution and at
5+
// http://rust-lang.org/COPYRIGHT.
6+
//
7+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10+
// option. This file may not be copied, modified, or distributed
11+
// except according to those terms.
12+
13+
// exec-env:RUST_POISON_ON_FREE=1
14+
15+
#![feature(managed_boxes)]
16+
17+
fn borrow(x: &int, f: |x: &int|) {
18+
let before = *x;
19+
f(x);
20+
let after = *x;
21+
assert_eq!(before, after);
22+
}
23+
24+
struct F { f: ~int }
25+
26+
pub fn main() {
27+
let mut x = @F {f: ~3};
28+
borrow(x.f, |b_x| {
29+
assert_eq!(*b_x, 3);
30+
assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
31+
x = @F {f: ~4};
32+
33+
println!("&*b_x = {:p}", &(*b_x));
34+
assert_eq!(*b_x, 3);
35+
assert!(&(*x.f) as *int != &(*b_x) as *int);
36+
})
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// ignore-pretty
2+
3+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
4+
// file at the top-level directory of this distribution and at
5+
// http://rust-lang.org/COPYRIGHT.
6+
//
7+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10+
// option. This file may not be copied, modified, or distributed
11+
// except according to those terms.
12+
13+
// exec-env:RUST_POISON_ON_FREE=1
14+
15+
#![feature(managed_boxes)]
16+
17+
fn borrow(x: &int, f: |x: &int|) {
18+
let before = *x;
19+
f(x);
20+
let after = *x;
21+
assert_eq!(before, after);
22+
}
23+
24+
struct F { f: ~int }
25+
26+
pub fn main() {
27+
let mut x = ~@F{f: ~3};
28+
borrow(x.f, |b_x| {
29+
assert_eq!(*b_x, 3);
30+
assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
31+
*x = @F{f: ~4};
32+
33+
println!("&*b_x = {:p}", &(*b_x));
34+
assert_eq!(*b_x, 3);
35+
assert!(&(*x.f) as *int != &(*b_x) as *int);
36+
})
37+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ignore-pretty
2+
3+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
4+
// file at the top-level directory of this distribution and at
5+
// http://rust-lang.org/COPYRIGHT.
6+
//
7+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10+
// option. This file may not be copied, modified, or distributed
11+
// except according to those terms.
12+
13+
// exec-env:RUST_POISON_ON_FREE=1
14+
15+
#![feature(managed_boxes)]
16+
17+
fn borrow(x: &int, f: |x: &int|) {
18+
let before = *x;
19+
f(x);
20+
let after = *x;
21+
assert_eq!(before, after);
22+
}
23+
24+
pub fn main() {
25+
let mut x = @3;
26+
borrow(x, |b_x| {
27+
assert_eq!(*b_x, 3);
28+
assert_eq!(&(*x) as *int, &(*b_x) as *int);
29+
x = @22;
30+
31+
println!("&*b_x = {:p}", &(*b_x));
32+
assert_eq!(*b_x, 3);
33+
assert!(&(*x) as *int != &(*b_x) as *int);
34+
})
35+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// exec-env:RUST_POISON_ON_FREE=1
12+
13+
#![feature(managed_boxes)]
14+
15+
fn testfn(cond: bool) {
16+
let mut x = @3;
17+
let mut y = @4;
18+
19+
// borrow x and y
20+
let r_x = &*x;
21+
let r_y = &*y;
22+
let mut r = r_x;
23+
let mut exp = 3;
24+
25+
if cond {
26+
r = r_y;
27+
exp = 4;
28+
}
29+
30+
println!("*r = {}, exp = {}", *r, exp);
31+
assert_eq!(*r, exp);
32+
33+
x = @5;
34+
y = @6;
35+
36+
println!("*r = {}, exp = {}", *r, exp);
37+
assert_eq!(*r, exp);
38+
assert_eq!(x, @5);
39+
assert_eq!(y, @6);
40+
}
41+
42+
pub fn main() {
43+
testfn(true);
44+
testfn(false);
45+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// ignore-pretty
2+
3+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
4+
// file at the top-level directory of this distribution and at
5+
// http://rust-lang.org/COPYRIGHT.
6+
//
7+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10+
// option. This file may not be copied, modified, or distributed
11+
// except according to those terms.
12+
13+
// exec-env:RUST_POISON_ON_FREE=1
14+
15+
#![feature(managed_boxes)]
16+
17+
fn borrow(x: &int, f: |x: &int|) {
18+
let before = *x;
19+
f(x);
20+
let after = *x;
21+
assert_eq!(before, after);
22+
}
23+
24+
struct F { f: ~int }
25+
26+
pub fn main() {
27+
let mut x = @F {f: ~3};
28+
borrow((*x).f, |b_x| {
29+
assert_eq!(*b_x, 3);
30+
assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
31+
x = @F {f: ~4};
32+
33+
println!("&*b_x = {:p}", &(*b_x));
34+
assert_eq!(*b_x, 3);
35+
assert!(&(*x.f) as *int != &(*b_x) as *int);
36+
})
37+
}

0 commit comments

Comments
 (0)