Allow ~fn:Copy() to be copied.
This commit is contained in:
parent
c454e95fac
commit
1ffcc6fc82
3 changed files with 73 additions and 7 deletions
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2013 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.
|
||||
|
||||
// xfail-pretty
|
||||
|
||||
// Tests correct copying of heap closures' environments.
|
||||
|
||||
fn foo(x: ~fn:Copy()) -> (~fn(), ~fn()) {
|
||||
(copy x, x)
|
||||
}
|
||||
fn main() {
|
||||
let v = ~[~[1,2,3],~[4,5,6]]; // shouldn't get double-freed
|
||||
let (f1,f2) = do foo {
|
||||
assert!(v.len() == 2);
|
||||
};
|
||||
f1();
|
||||
f2();
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2013 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.
|
||||
|
||||
// xfail-pretty
|
||||
|
||||
// Tests correct copying of heap closures' environments.
|
||||
|
||||
fn bar<T: Copy>(x: T) -> (T, T) {
|
||||
(copy x, x)
|
||||
}
|
||||
fn foo(x: ~fn:Copy()) -> (~fn(), ~fn()) {
|
||||
bar(x)
|
||||
}
|
||||
fn main() {
|
||||
let v = ~[~[1,2,3],~[4,5,6]]; // shouldn't get double-freed
|
||||
let (f1,f2) = do foo {
|
||||
assert!(v.len() == 2);
|
||||
};
|
||||
f1();
|
||||
f2();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue