Skip to content

Commit 32304b8

Browse files
committed
---
yaml --- r: 142522 b: refs/heads/try2 c: 1670a8c h: refs/heads/master v: v3
1 parent d5c001b commit 32304b8

10 files changed

+157
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 17b3712487a4cf2be30e6bd43e89a736a7d86908
8+
refs/heads/try2: 1670a8cfb13fd384d9fd4ca47034cef99118c7a7
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
fn with(f: &fn(&~str)) {}
2+
3+
fn arg_item(&_x: &~str) {}
4+
//~^ ERROR cannot move out of dereference of & pointer
5+
6+
fn arg_closure() {
7+
with(|&_x| ())
8+
//~^ ERROR cannot move out of dereference of & pointer
9+
}
10+
11+
fn let_pat() {
12+
let &_x = &~"hi";
13+
//~^ ERROR cannot move out of dereference of & pointer
14+
}
15+
16+
pub fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
struct S {f:~str}
2+
impl Drop for S {
3+
fn finalize(&self) { println(self.f); }
4+
}
5+
6+
fn move_in_match() {
7+
match S {f:~"foo"} {
8+
S {f:_s} => {}
9+
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
10+
}
11+
}
12+
13+
fn move_in_let() {
14+
let S {f:_s} = S {f:~"foo"};
15+
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
16+
}
17+
18+
fn move_in_fn_arg(S {f:_s}: S) {
19+
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
20+
}
21+
22+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
struct S(~str);
2+
impl Drop for S {
3+
fn finalize(&self) { println(**self); }
4+
}
5+
6+
fn move_in_match() {
7+
match S(~"foo") {
8+
S(_s) => {}
9+
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
10+
}
11+
}
12+
13+
fn move_in_let() {
14+
let S(_s) = S(~"foo");
15+
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
16+
}
17+
18+
fn move_in_fn_arg(S(_s): S) {
19+
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
20+
}
21+
22+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn arg_item(~ref x: ~int) -> &'static int {
2+
x //~^ ERROR borrowed value does not live long enough
3+
}
4+
5+
fn with<R>(f: &fn(~int) -> R) -> R { f(~3) }
6+
7+
fn arg_closure() -> &'static int {
8+
with(|~ref x| x) //~ ERROR borrowed value does not live long enough
9+
}
10+
11+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Test that we do not leak when the arg pattern must drop part of the
2+
// argument (in this case, the `y` field).
3+
4+
struct Foo {
5+
x: ~uint,
6+
y: ~uint,
7+
}
8+
9+
fn foo(Foo {x, _}: Foo) -> *uint {
10+
let addr: *uint = &*x;
11+
addr
12+
}
13+
14+
fn main() {
15+
let obj = ~1;
16+
let objptr: *uint = &*obj;
17+
let f = Foo {x: obj, y: ~2};
18+
let xptr = foo(f);
19+
assert_eq!(objptr, xptr);
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// exec-env:RUST_POISON_ON_FREE=1
2+
3+
// Test argument patterns where we create refs to the inside of `~`
4+
// boxes. Make sure that we don't free the box as we match the
5+
// pattern.
6+
7+
fn getaddr(~ref x: ~uint) -> *uint {
8+
let addr: *uint = &*x;
9+
addr
10+
}
11+
12+
fn checkval(~ref x: ~uint) -> uint {
13+
*x
14+
}
15+
16+
fn main() {
17+
let obj = ~1;
18+
let objptr: *uint = &*obj;
19+
let xptr = getaddr(obj);
20+
assert_eq!(objptr, xptr);
21+
22+
let obj = ~22;
23+
assert_eq!(checkval(obj), 22);
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Test that we can compile code that uses a `_` in function argument
2+
// patterns.
3+
4+
fn foo((x, _): (int, int)) -> int {
5+
x
6+
}
7+
8+
fn main() {
9+
assert_eq!(foo((22, 23)), 22);
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
let x = ~"hello";
3+
let ref y = x;
4+
assert_eq!(x.slice(0, x.len()), y.slice(0, y.len()));
5+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Tests a tricky scenario involving string matching,
2+
// copying, and moving to ensure that we don't segfault
3+
// or double-free, as we were wont to do in the past.
4+
5+
use std::io;
6+
7+
fn parse_args() -> ~str {
8+
let args = std::os::args();
9+
let mut n = 0;
10+
11+
while n < args.len() {
12+
match copy args[n] {
13+
~"-v" => (),
14+
s => {
15+
return s;
16+
}
17+
}
18+
n += 1;
19+
}
20+
21+
return ~""
22+
}
23+
24+
fn main() {
25+
io::println(parse_args());
26+
}

0 commit comments

Comments
 (0)