Tests for #1896
This commit is contained in:
parent
b269ac13cd
commit
768247f393
8
src/test/compile-fail/issue-1896.rs
Normal file
8
src/test/compile-fail/issue-1896.rs
Normal file
@ -0,0 +1,8 @@
|
||||
type t<T> = { f: fn() -> T };
|
||||
|
||||
fn f<T>(_x: t<T>) {}
|
||||
|
||||
fn main() {
|
||||
let x: t<()> = { f: { || () } };
|
||||
f(x); //~ ERROR copying a noncopyable value
|
||||
}
|
13
src/test/run-pass/issue-1896-1.rs
Normal file
13
src/test/run-pass/issue-1896-1.rs
Normal file
@ -0,0 +1,13 @@
|
||||
type boxedFn = { theFn: fn () -> uint };
|
||||
|
||||
fn createClosure (closedUint: uint) -> boxedFn {
|
||||
{ theFn: fn@ () -> uint { closedUint } }
|
||||
}
|
||||
|
||||
fn main () {
|
||||
let aFn: boxedFn = createClosure(10);
|
||||
|
||||
let myInt: uint = aFn.theFn();
|
||||
|
||||
assert myInt == 10;
|
||||
}
|
10
src/test/run-pass/issue-1896-2.rs
Normal file
10
src/test/run-pass/issue-1896-2.rs
Normal file
@ -0,0 +1,10 @@
|
||||
fn add(n: int) -> fn@(int) -> int {
|
||||
fn@(m: int) -> int { m + n }
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
assert add(3)(4) == 7;
|
||||
let add3 : fn(int)->int = add(3);
|
||||
assert add3(4) == 7;
|
||||
}
|
17
src/test/run-pass/issue-1896-3.rs
Normal file
17
src/test/run-pass/issue-1896-3.rs
Normal file
@ -0,0 +1,17 @@
|
||||
fn add(n: int) -> fn@(int) -> int {
|
||||
fn@(m: int) -> int { m + n }
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
assert add(3)(4) == 7;
|
||||
|
||||
let add1 : fn@(int)->int = add(1);
|
||||
assert add1(6) == 7;
|
||||
|
||||
let add2 : &(fn@(int)->int) = &add(2);
|
||||
assert (*add2)(5) == 7;
|
||||
|
||||
let add3 : fn(int)->int = add(3);
|
||||
assert add3(4) == 7;
|
||||
}
|
Loading…
Reference in New Issue
Block a user