提交 30bb09c0 编写于 作者: P Patrick Walton

test: Remove `fn@`, `fn~`, and `fn&` from the test suite. rs=defun

上级 542119f6
......@@ -2291,13 +2291,12 @@ be private. But this encapsulation is at the module level, not the
struct level. Note that fields and methods are _public_ by default.
~~~
mod farm {
# use farm;
pub mod farm {
# pub type Chicken = int;
# type Cow = int;
# enum Human = int;
# impl Human { fn rest(&self) { } }
# pub fn make_me_a_farm() -> farm::Farm { farm::Farm { chickens: ~[], cows: ~[], farmer: Human(0) } }
# pub fn make_me_a_farm() -> Farm { Farm { chickens: ~[], cows: ~[], farmer: Human(0) } }
pub struct Farm {
priv chickens: ~[Chicken],
priv cows: ~[Cow],
......
......@@ -14,7 +14,7 @@
pub struct Entry<A,B> {key: A, value: B}
pub struct alist<A,B> { eq_fn: fn@(A,A) -> bool, data: DVec<Entry<A,B>> }
pub struct alist<A,B> { eq_fn: @fn(A,A) -> bool, data: DVec<Entry<A,B>> }
pub fn alist_add<A:Copy,B:Copy>(lst: alist<A,B>, k: A, v: B) {
lst.data.push(Entry{key:k, value:v});
......
......@@ -9,5 +9,6 @@
// except according to those terms.
pub fn to_closure<A:Durable + Copy>(x: A) -> @fn() -> A {
fn@() -> A { copy x }
let result: @fn() -> A = || copy x;
result
}
......@@ -16,7 +16,7 @@
use std::oldmap;
use std::oldmap::{Map, HashMap};
use io::{Reader, ReaderUtil};
use core::io::{Reader, ReaderUtil};
macro_rules! bench (
($id:ident) => (maybe_run_test(argv, stringify!($id).to_owned(), $id))
......
......@@ -11,8 +11,8 @@
// A raw test of vector appending performance.
extern mod std;
use dvec::DVec;
use io::WriterUtil;
use core::dvec::DVec;
use core::io::WriterUtil;
fn collect_raw(num: uint) -> ~[uint] {
let mut result = ~[];
......
......@@ -267,7 +267,7 @@ fn is_gray_factory() -> ~fn(c: &color) -> bool {
colors = do par::mapi(*color_vec) {
let colors = arc::clone(&color);
let graph = arc::clone(&graph);
fn~(+i: uint, +c: &color) -> color {
let result: ~fn(+x: uint, +y: &color) -> color = |i, c| {
let colors = arc::get(&colors);
let graph = arc::get(&graph);
match *c {
......@@ -290,20 +290,22 @@ fn is_gray_factory() -> ~fn(c: &color) -> bool {
gray(parent) => { black(parent) }
black(parent) => { black(parent) }
}
}
};
result
};
assert(colors.len() == old_len);
}
// Convert the results.
do par::map(colors) {
fn~(c: &color) -> i64 {
let result: ~fn(c: &color) -> i64 = |c| {
match *c {
white => { -1i64 }
black(parent) => { parent }
_ => { fail!(~"Found remaining gray nodes in BFS") }
}
}
};
result
}
}
......@@ -387,14 +389,15 @@ fn validate(edges: ~[(node_id, node_id)],
let status = do par::alli(tree) {
let edges = copy edges;
fn~(+u: uint, v: &i64) -> bool {
let result: ~fn(+x: uint, v: &i64) -> bool = |u, v| {
let u = u as node_id;
if *v == -1i64 || u == root {
true
} else {
edges.contains(&(u, *v)) || edges.contains(&(*v, u))
}
}
};
result
};
if !status { return status }
......
......@@ -21,10 +21,10 @@
#[legacy_modes];
extern mod std;
use io::Writer;
use io::WriterUtil;
use core::io::Writer;
use core::io::WriterUtil;
use comm::{Port, Chan, SharedChan};
use core::comm::{Port, Chan, SharedChan};
macro_rules! move_out (
{ $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } }
......
......@@ -17,10 +17,10 @@
#[legacy_modes];
extern mod std;
use io::Writer;
use io::WriterUtil;
use core::io::Writer;
use core::io::WriterUtil;
use comm::{Port, PortSet, Chan, stream};
use core::comm::{Port, PortSet, Chan, stream};
macro_rules! move_out (
{ $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } }
......
......@@ -16,7 +16,7 @@
* http://shootout.alioth.debian.org/
*/
extern mod std;
use io::WriterUtil;
use core::io::WriterUtil;
fn LINE_LENGTH() -> uint { return 60u; }
......
......@@ -17,9 +17,9 @@
use std::oldmap;
use std::oldmap::HashMap;
use std::sort;
use io::ReaderUtil;
use comm::{stream, Port, Chan};
use cmp::Ord;
use core::io::ReaderUtil;
use core::comm::{stream, Port, Chan};
use core::cmp::Ord;
// given a map, print a sorted version of it
fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
......
......@@ -24,7 +24,7 @@
//
// writes pbm image to output path
use io::WriterUtil;
use core::io::WriterUtil;
use core::hashmap::linear::LinearMap;
struct cmplx {
......
......@@ -45,7 +45,7 @@ fn main() {
io::println(fmt!("%f", NBodySystem::energy(bodies)));
}
mod NBodySystem {
pub mod NBodySystem {
use Body;
pub fn make() -> ~[Body::Props] {
......@@ -162,7 +162,7 @@ pub fn energy(bodies: &[Body::Props]) -> float {
}
}
mod Body {
pub mod Body {
use Body;
pub const PI: float = 3.141592653589793;
......
......@@ -29,7 +29,7 @@
use core::io::WriterUtil;
use core::result;
use result::{Ok, Err};
use core::result::{Ok, Err};
fn fib(n: int) -> int {
fn pfib(c: Chan<int>, n: int) {
......
......@@ -12,7 +12,7 @@
extern mod std;
use std::smallintmap::SmallIntMap;
use io::WriterUtil;
use core::io::WriterUtil;
fn append_sequential(min: uint, max: uint, map: &mut SmallIntMap<uint>) {
for uint::range(min, max) |i| {
......
......@@ -13,7 +13,8 @@
extern mod std;
use std::bitv;
use io::{ReaderUtil, WriterUtil};
use core::io::{ReaderUtil, WriterUtil};
use core::io;
// Computes a single solution to a given 9x9 sudoku
//
......
......@@ -46,7 +46,7 @@ fn run(repeat: int, depth: int) {
struct State {
box: @nillist,
unique: ~nillist,
fn_box: fn@() -> @nillist,
fn_box: @fn() -> @nillist,
tuple: (@nillist, ~nillist),
vec: ~[@nillist],
res: r
......@@ -78,7 +78,7 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
State {
box: @Nil,
unique: ~Nil,
fn_box: fn@() -> @nillist { @Nil::<()> },
fn_box: || @Nil::<()>,
tuple: (@Nil, ~Nil),
vec: ~[@Nil],
res: r(@Nil)
......@@ -90,7 +90,7 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
State {
box: @Cons((), st.box),
unique: ~Cons((), @*st.unique),
fn_box: fn@() -> @nillist { @Cons((), fn_box()) },
fn_box: || @Cons((), fn_box()),
tuple: (@Cons((), st.tuple.first()),
~Cons((), @*st.tuple.second())),
vec: st.vec + ~[@Cons((), st.vec.last())],
......
......@@ -46,7 +46,7 @@ fn grandchild_group(num_tasks: uint) {
// Master grandchild task exits early.
}
fn spawn_supervised_blocking(myname: &str, +f: fn~()) {
fn spawn_supervised_blocking(myname: &str, +f: ~fn()) {
let mut res = None;
task::task().future_result(|+r| res = Some(r)).supervised().spawn(f);
error!("%s group waiting", myname);
......
......@@ -28,5 +28,5 @@ fn cat(in_x : uint, in_y : int) -> cat {
fn main() {
let nyan : cat = cat(52u, 99);
nyan.speak = fn@() { debug!("meow"); }; //~ ERROR attempted to take value of method
nyan.speak = || debug!("meow"); //~ ERROR attempted to take value of method
}
......@@ -8,16 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo(x: @int) -> fn@() -> &static/int {
fn@() -> &static/int {&*x} //~ ERROR illegal borrow
fn foo(x: @int) -> @fn() -> &static/int {
let result: @fn() -> &static/int = || &*x; //~ ERROR illegal borrow
result
}
fn bar(x: @int) -> fn@() -> &int {
fn@() -> &int {&*x} //~ ERROR illegal borrow
fn bar(x: @int) -> @fn() -> &int {
let result: @fn() -> &int = || &*x; //~ ERROR illegal borrow
result
}
fn zed(x: @int) -> fn@() -> int {
fn@() -> int {*&*x}
fn zed(x: @int) -> @fn() -> int {
let result: @fn() -> int = || *&*x;
result
}
fn main() {
......
......@@ -10,7 +10,11 @@
// xfail-test #2978
fn call(x: @{f: fn~()}) {
struct Foo {
f: ~fn()
}
fn call(x: @Foo) {
x.f(); //~ ERROR foo
//~^ NOTE bar
}
......
......@@ -22,7 +22,7 @@ fn box_imm() {
let v = ~3;
let _w = &v; //~ NOTE loan of immutable local variable granted here
task::spawn(fn~() {
task::spawn(|| {
debug!("v=%d", *v);
//~^ ERROR by-move capture of immutable local variable prohibited due to outstanding loan
});
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: fn@(int) -> bool) -> bool { f(10i) }
fn f(f: @fn(int) -> bool) -> bool { f(10i) }
fn main() {
assert do f() |i| { i == 10i } == 10i;
......
......@@ -8,8 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn reproduce<T:Copy>(t: T) -> fn@() -> T {
fn@() -> T { t }
fn reproduce<T:Copy>(t: T) -> @fn() -> T {
let result: @fn() -> T = || t;
result
}
fn main() {
......@@ -17,7 +18,7 @@ fn main() {
// with the lower bound @mut int
let x = @mut 3;
// type of r is fn@() -> X
// type of r is @fn() -> X
let r = reproduce(x);
// Requires that X be a subtype of
......
......@@ -8,12 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn mk_identity<T:Copy>() -> fn@(T) -> T {
fn@(t: T) -> T { t }
fn mk_identity<T:Copy>() -> @fn(T) -> T {
let result: @fn(t: T) -> T = |t| t;
result
}
fn main() {
// type of r is fn@(X) -> X
// type of r is @fn(X) -> X
// for some fresh X
let r = mk_identity();
......
......@@ -9,8 +9,8 @@
// except according to those terms.
// xfail-test
struct T { f: fn@() };
struct S { f: fn@() };
struct T { f: @fn() };
struct S { f: @fn() };
fn fooS(t: S) {
}
......@@ -22,11 +22,11 @@ fn bar() {
}
fn main() {
let x: fn@() = bar;
let x: @fn() = bar;
fooS(S {f: x});
fooS(S {f: bar});
let x: fn@() = bar;
let x: @fn() = bar;
fooT(T {f: x});
fooT(T {f: bar});
}
......
......@@ -8,10 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct boxedFn { theFn: fn~() -> uint }
struct boxedFn { theFn: ~fn() -> uint }
fn createClosure (closedUint: uint) -> boxedFn {
boxedFn {theFn: fn@ () -> uint { closedUint }} //~ ERROR mismatched types
let result: @fn() -> uint = || closedUint;
boxedFn { theFn: result } //~ ERROR mismatched types
}
fn main () {
......
......@@ -10,13 +10,13 @@
// xfail-test
fn main() {
let one = fn@() -> uint {
let one: @fn() -> uint = || {
enum r { a };
return a as uint;
a as uint
};
let two = fn@() -> uint {
let two = @fn() -> uint = || {
enum r { a };
return a as uint;
a as uint
};
one(); two();
}
......@@ -12,7 +12,7 @@ fn foo(_x: @uint) {}
fn main() {
let x = @3u;
let _ = fn~() { foo(x); }; //~ ERROR value has non-owned type `@uint`
let _ = fn~() { foo(x); }; //~ ERROR value has non-owned type `@uint`
let _ = fn~() { foo(x); }; //~ ERROR value has non-owned type `@uint`
let _: ~fn() = || foo(x); //~ ERROR value has non-owned type `@uint`
let _: ~fn() = || foo(x); //~ ERROR value has non-owned type `@uint`
let _: ~fn() = || foo(x); //~ ERROR value has non-owned type `@uint`
}
......@@ -8,12 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn copy1<T:Copy>(t: T) -> fn@() -> T {
fn@() -> T { t } //~ ERROR value may contain borrowed pointers
fn copy1<T:Copy>(t: T) -> @fn() -> T {
let result: @fn() -> T = || t; //~ ERROR value may contain borrowed pointers
result
}
fn copy2<T:Copy + &static>(t: T) -> fn@() -> T {
fn@() -> T { t }
fn copy2<T:Copy + &static>(t: T) -> @fn() -> T {
let result: @fn() -> T = || t;
result
}
fn main() {
......@@ -23,7 +25,10 @@ fn main() {
copy2(@3);
copy2(@&x); //~ ERROR does not fulfill `&static`
copy2(fn@() {});
copy2(fn~() {}); //~ ERROR does not fulfill `Copy`
copy2(fn&() {}); //~ ERROR does not fulfill `&static`
let boxed: @fn() = || {};
copy2(boxed);
let owned: ~fn() = || {};
copy2(owned); //~ ERROR does not fulfill `Copy`
let borrowed: &fn() = || {};
copy2(borrowed); //~ ERROR does not fulfill `&static`
}
......@@ -9,13 +9,13 @@
// except according to those terms.
// error-pattern:assigning to captured outer immutable variable in a stack closure
// Make sure that nesting a block within a fn@ doesn't let us
// mutate upvars from a fn@.
fn f2(x: fn()) { x(); }
// Make sure that nesting a block within a @fn doesn't let us
// mutate upvars from a @fn.
fn f2(x: &fn()) { x(); }
fn main() {
let i = 0;
let ctr = fn@ () -> int { f2(|| i = i + 1 ); return i; };
let ctr: @fn() -> int = || { f2(|| i = i + 1 ); i };
log(error, ctr());
log(error, ctr());
log(error, ctr());
......
......@@ -9,10 +9,10 @@
// except according to those terms.
// error-pattern:assigning to captured outer variable in a heap closure
// Make sure we can't write to upvars from fn@s
// Make sure we can't write to upvars from @fns
fn main() {
let i = 0;
let ctr = fn@ () -> int { i = i + 1; return i; };
let ctr: @fn() -> int = || { i = i + 1; i };
log(error, ctr());
log(error, ctr());
log(error, ctr());
......
......@@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn force(f: fn()) { f(); }
fn force(f: &fn()) { f(); }
fn main() {
let x: int;
force(fn&() {
force(|| {
log(debug, x); //~ ERROR capture of possibly uninitialized variable: `x`
});
}
......@@ -9,9 +9,9 @@
// except according to those terms.
fn main() {
let j = fn@() -> int {
let j: @fn() -> int = || {
let i: int;
return i; //~ ERROR use of possibly uninitialized variable: `i`
i //~ ERROR use of possibly uninitialized variable: `i`
};
j();
}
......@@ -9,9 +9,9 @@
// except according to those terms.
fn main() {
let f = fn@() -> int {
let f: @fn() -> int = || {
let i: int;
return i; //~ ERROR use of possibly uninitialized variable: `i`
i //~ ERROR use of possibly uninitialized variable: `i`
};
log(error, f());
}
......@@ -10,7 +10,7 @@
fn main() {
let a: ~[int] = ~[];
vec::each(a, fn@(_x: &int) -> bool {
//~^ ERROR not all control paths return a value
vec::each(a, |_| -> bool {
//~^ ERROR mismatched types
});
}
......@@ -68,5 +68,5 @@ fn finalize(&self) {}
fn main() {
let x = r { x: () };
fn@() { copy x; }; //~ ERROR copying a value of non-copyable type
|| { copy x; }; //~ ERROR copying a value of non-copyable type
}
......@@ -9,12 +9,12 @@
// except according to those terms.
// xfail-test - #2093
fn let_in<T>(x: T, f: fn(T)) {}
fn let_in<T>(x: T, f: &fn(T)) {}
fn main() {
let_in(3u, fn&(i) { assert i == 3; });
let_in(3u, |i| { assert i == 3; });
//~^ ERROR expected `uint` but found `int`
let_in(3, fn&(i) { assert i == 3u; });
let_in(3, |i| { assert i == 3u; });
//~^ ERROR expected `int` but found `uint`
}
......@@ -12,36 +12,36 @@
fn take<T>(_v: T) {}
fn assign_to_pure(x: pure fn(), y: fn(), z: unsafe fn()) {
take::<pure fn()>(x);
take::<pure fn()>(y); //~ ERROR expected pure fn but found impure fn
take::<pure fn()>(z); //~ ERROR expected pure fn but found unsafe fn
fn assign_to_pure(x: &pure fn(), y: &fn(), z: &unsafe fn()) {
take::<&pure fn()>(x);
take::<&pure fn()>(y); //~ ERROR expected pure fn but found impure fn
take::<&pure fn()>(z); //~ ERROR expected pure fn but found unsafe fn
}
fn assign_to_impure(x: pure fn(), y: fn(), z: unsafe fn()) {
take::<fn()>(x);
take::<fn()>(y);
take::<fn()>(z); //~ ERROR expected impure fn but found unsafe fn
fn assign_to_impure(x: &pure fn(), y: &fn(), z: &unsafe fn()) {
take::<&fn()>(x);
take::<&fn()>(y);
take::<&fn()>(z); //~ ERROR expected impure fn but found unsafe fn
}
fn assign_to_unsafe(x: pure fn(), y: fn(), z: unsafe fn()) {
take::<unsafe fn()>(x);
take::<unsafe fn()>(y);
take::<unsafe fn()>(z);
fn assign_to_unsafe(x: &pure fn(), y: &fn(), z: &unsafe fn()) {
take::<&unsafe fn()>(x);
take::<&unsafe fn()>(y);
take::<&unsafe fn()>(z);
}
fn assign_to_pure2(x: pure fn@(), y: fn@(), z: unsafe fn@()) {
take::<pure fn()>(x);
take::<pure fn()>(y); //~ ERROR expected pure fn but found impure fn
take::<pure fn()>(z); //~ ERROR expected pure fn but found unsafe fn
fn assign_to_pure2(x: @pure fn(), y: @fn(), z: @unsafe fn()) {
take::<&pure fn()>(x);
take::<&pure fn()>(y); //~ ERROR expected pure fn but found impure fn
take::<&pure fn()>(z); //~ ERROR expected pure fn but found unsafe fn
take::<pure fn~()>(x); //~ ERROR expected ~ closure, found @ closure
take::<pure fn~()>(y); //~ ERROR expected ~ closure, found @ closure
take::<pure fn~()>(z); //~ ERROR expected ~ closure, found @ closure
take::<~pure fn()>(x); //~ ERROR expected ~ closure, found @ closure
take::<~pure fn()>(y); //~ ERROR expected ~ closure, found @ closure
take::<~pure fn()>(z); //~ ERROR expected ~ closure, found @ closure
take::<unsafe fn~()>(x); //~ ERROR expected ~ closure, found @ closure
take::<unsafe fn~()>(y); //~ ERROR expected ~ closure, found @ closure
take::<unsafe fn~()>(z); //~ ERROR expected ~ closure, found @ closure
take::<~unsafe fn()>(x); //~ ERROR expected ~ closure, found @ closure
take::<~unsafe fn()>(y); //~ ERROR expected ~ closure, found @ closure
take::<~unsafe fn()>(z); //~ ERROR expected ~ closure, found @ closure
}
fn main() {
......
......@@ -12,7 +12,7 @@
// we reported errors in this case:
fn not_ok(a: &uint, b: &b/uint) {
let mut g: fn@(x: &uint) = fn@(x: &b/uint) {};
let mut g: @fn(x: &uint) = |x: &b/uint| {};
//~^ ERROR mismatched types
g(a);
}
......
......@@ -14,7 +14,7 @@
// the normal case.
struct contravariant {
f: fn@() -> &self/int
f: @fn() -> &self/int
}
fn to_same_lifetime(bi: contravariant/&r) {
......
......@@ -13,7 +13,7 @@
// You can upcast to a *larger region* but not a smaller one.
struct covariant {
f: fn@(x: &self/int) -> int
f: @fn(x: &self/int) -> int
}
fn to_same_lifetime(bi: covariant/&r) {
......
......@@ -9,7 +9,7 @@
// except according to those terms.
struct invariant {
f: fn@(x: @mut &self/int)
f: @fn(x: @mut &self/int)
}
fn to_same_lifetime(bi: invariant/&r) {
......
......@@ -9,7 +9,7 @@
// except according to those terms.
struct invariant {
f: fn@() -> @mut &self/int
f: @fn() -> @mut &self/int
}
fn to_same_lifetime(bi: invariant/&r) {
......
......@@ -13,15 +13,15 @@ struct direct {
}
struct indirect1 {
g: fn@(direct)
g: @fn(direct)
}
struct indirect2 {
g: fn@(direct/&)
g: @fn(direct/&)
}
struct indirect3 {
g: fn@(direct/&self)
g: @fn(direct/&self)
}
fn take_direct(p: direct) -> direct { p } //~ ERROR mismatched types
......
......@@ -11,7 +11,7 @@
// check that the &int here does not cause us to think that `foo`
// contains region pointers
enum foo = fn~(x: &int);
enum foo = ~fn(x: &int);
fn take_foo(x: foo/&) {} //~ ERROR no region bound is allowed on `foo`
......
......@@ -12,9 +12,8 @@ fn ignore<T>(_t: T) {}
fn nested() {
let y = 3;
ignore(fn&(z: &z/int) -> &z/int {
if false { return &y; } //~ ERROR illegal borrow
return z;
ignore(|z: &z/int| -> &z/int {
if false { &y } else { z } //~ ERROR illegal borrow
});
}
......
......@@ -14,13 +14,13 @@ fn nested(x: &x/int) {
let y = 3;
let mut ay = &y; //~ ERROR cannot infer an appropriate lifetime
ignore(fn&(z: &z/int) {
ignore(|z: &z/int| {
ay = x;
ay = &y; //~ ERROR cannot infer an appropriate lifetime
ay = z;
});
ignore(fn&(z: &z/int) -> &z/int {
ignore(|z: &z/int| -> &z/int {
if false { return x; } //~ ERROR mismatched types
if false { return ay; }
return z;
......
......@@ -12,13 +12,12 @@ fn with<T>(t: T, f: fn(T)) { f(t) }
fn nested<'x>(x: &'x int) { // (1)
do with(
fn&(x: &'x int, // Refers to the region `x` at (1)
y: &'y int, // A fresh region `y` (2)
z: fn<'z>(x: &'x int, // Refers to `x` at (1)
y: &'y int, // Refers to `y` at (2)
z: &'z int) -> &'z int) // A fresh region `z` (3)
-> &x/int {
|x: &'x int, // Refers to the region `x` at (1)
y: &'y int, // A fresh region `y` (2)
z: &fn<'z>(x: &'x int, // Refers to `x` at (1)
y: &'y int, // Refers to `y` at (2)
z: &'z int) -> &'z int| // A fresh region `z` (3)
-> &x/int {
if false { return z(x, y, x); }
if false { return z(x, y, y); }
......
......@@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn test(f: fn@(uint) -> uint) -> uint {
fn test(f: @fn(uint) -> uint) -> uint {
return f(22u);
}
fn main() {
let f = fn~(x: uint) -> uint { return 4u; };
let f: ~fn(x: uint) -> uint = |x| 4u;
log(debug, test(f)); //~ ERROR expected @ closure, found ~ closure
}
......@@ -12,4 +12,4 @@
extern mod std;
fn main() { task::spawn(fn~() -> int { 10 }); }
fn main() { task::spawn(|| -> int { 10 }); }
......@@ -8,5 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn blk1(b: fn()) -> fn@() { return fn@() { }; }
fn blk1(b: &fn()) -> @fn() { return || { }; }
fn test1() { (do blk1 { debug!("hi"); })(); }
......@@ -13,7 +13,7 @@
// Don't leak when the landing pads need to request more stack
// than is allowed during normal execution
fn useBlock(f: fn~() -> uint) { useBlock(|| 22u ) }
fn useBlock(f: ~fn() -> uint) { useBlock(|| 22u ) }
fn main() {
useBlock(|| 22u );
}
......@@ -16,9 +16,9 @@ fn failfn() {
fn main() {
let y = ~0;
let x = @fn~() {
let x: @~fn() = @(|| {
log(error, copy y);
};
});
failfn();
log(error, x);
}
......@@ -16,7 +16,7 @@ fn failfn() {
fn main() {
let y = ~0;
let x = @fn@() {
let x: @@fn() = @|| {
log(error, copy y);
};
failfn();
......
......@@ -16,6 +16,6 @@ fn f(a: @int) {
fn main() {
let b = @0;
let g : fn@() = || f(b);
let g: @fn() = || f(b);
g();
}
......@@ -14,12 +14,13 @@ fn main() {
let cheese = ~"roquefort";
let carrots = @~"crunchy";
fn@(tasties: @~str, macerate: fn(~str)) {
let result: @fn(@~str, &fn(~str)) = (|tasties, macerate| {
macerate(copy *tasties);
} (carrots, |food| {
});
result(carrots, |food| {
let mush = food + cheese;
let cheese = copy cheese;
let f = fn@() {
let f: &fn() = || {
let chew = mush + cheese;
fail!(~"so yummy")
};
......
......@@ -12,8 +12,9 @@
a: A, b: B
};
fn f<A:Copy + &static>(a: A, b: u16) -> fn@() -> (A, u16) {
fn@() -> (A, u16) { (a, b) }
fn f<A:Copy + &static>(a: A, b: u16) -> @fn() -> (A, u16) {
let result: @fn() -> (A, u16) = || (a, b);
result
}
pub fn main() {
......
......@@ -23,8 +23,9 @@ fn make_cycle<A:Copy>(a: A) {
g.rec = Some(g);
}
fn f<A:Owned + Copy,B:Owned + Copy>(a: A, b: B) -> fn@() -> (A, B) {
fn@() -> (A, B) { (a, b) }
fn f<A:Owned + Copy,B:Owned + Copy>(a: A, b: B) -> @fn() -> (A, B) {
let result: @fn() -> (A, B) = || (a, b);
result
}
pub fn main() {
......
......@@ -10,19 +10,15 @@
extern mod std;
fn asSendfn( f : fn~()->uint ) -> uint {
fn asSendfn( f : ~fn()->uint ) -> uint {
return f();
}
fn asLambda( f : fn@()->uint ) -> uint {
fn asLambda( f : @fn()->uint ) -> uint {
return f();
}
fn asBlock( f : fn&()->uint ) -> uint {
return f();
}
fn asAny( f : fn()->uint ) -> uint {
fn asBlock( f : &fn()->uint ) -> uint {
return f();
}
......
......@@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn to_lambda(f: fn@(uint) -> uint) -> fn@(uint) -> uint {
fn to_lambda(f: @fn(uint) -> uint) -> @fn(uint) -> uint {
return f;
}
pub fn main() {
let x: fn@(uint) -> uint = to_lambda(|x| x * 2u );
let x: @fn(uint) -> uint = to_lambda(|x| x * 2u );
let y = to_lambda(x);
let x_r = x(22u);
......
......@@ -11,21 +11,21 @@
pub fn main() {
let x = ~1;
let y = ptr::addr_of(&(*x)) as uint;
let lam_move = fn@() -> uint { ptr::addr_of(&(*x)) as uint };
let lam_move: @fn() -> uint = || ptr::addr_of(&(*x)) as uint;
assert lam_move() == y;
let x = ~2;
let y = ptr::addr_of(&(*x)) as uint;
let lam_move: fn@() -> uint = || ptr::addr_of(&(*x)) as uint;
let lam_move: @fn() -> uint = || ptr::addr_of(&(*x)) as uint;
assert lam_move() == y;
let x = ~3;
let y = ptr::addr_of(&(*x)) as uint;
let snd_move = fn~() -> uint { ptr::addr_of(&(*x)) as uint };
let snd_move: ~fn() -> uint = || ptr::addr_of(&(*x)) as uint;
assert snd_move() == y;
let x = ~4;
let y = ptr::addr_of(&(*x)) as uint;
let lam_move: fn~() -> uint = || ptr::addr_of(&(*x)) as uint;
let lam_move: ~fn() -> uint = || ptr::addr_of(&(*x)) as uint;
assert lam_move() == y;
}
......@@ -58,10 +58,8 @@ fn meow() -> uint {
new(in_x : uint, in_y : int, in_name: str)
{ self.meows = @mut in_x; self.how_hungry = @mut in_y;
self.name = in_name; self.scratched = dvec();
let hsher: hashfn<body_part> =
fn@(p: body_part) -> uint { int::hash(p as int) };
let eqer : eqfn<body_part> =
fn@(p: body_part, q: body_part) -> bool { p == q };
let hsher: hashfn<body_part> = |p| int::hash(p as int);
let eqer : eqfn<body_part> = |p, q| p == q;
let t : hashmap<body_part, uint> =
hashmap::<body_part, uint>(hsher, eqer);
self.bite_counts = t;
......
......@@ -16,8 +16,9 @@
a: A, b: B
};
fn f<A:Copy + &static>(a: A, b: u16) -> fn@() -> (A, u16) {
fn@() -> (A, u16) { (a, b) }
fn f<A:Copy + &static>(a: A, b: u16) -> @fn() -> (A, u16) {
let result: @fn() -> (A, u16) = || (a, b);
result
}
pub fn main() {
......
......@@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct foo { z: fn@() }
struct foo { z: @fn() }
fn nop() { }
fn nop_foo(_x : @mut foo) { }
pub fn main() {
let w = @mut foo{ z: || nop() };
let x: fn@() = || nop_foo(w);
let x: @fn() = || nop_foo(w);
w.z = x;
}
......@@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct foo { z : fn@() }
struct foo { z : @fn() }
fn nop() { }
fn nop_foo(_y: ~[int], _x : @mut foo) { }
pub fn main() {
let w = @mut foo{ z: || nop() };
let x : fn@() = || nop_foo(~[], w);
let x : @fn() = || nop_foo(~[], w);
w.z = x;
}
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct foo { z: fn@() }
struct foo { z: @fn() }
fn nop() { }
fn nop_foo(_y: @int, _x: @mut foo) { }
......@@ -17,6 +17,6 @@ fn o() -> @int { @10 }
pub fn main() {
let w = @mut foo { z: || nop() };
let x : fn@() = || nop_foo(o(), w);
let x : @fn() = || nop_foo(o(), w);
w.z = x;
}
......@@ -10,9 +10,9 @@
// Testing that we can drop the || in for/do exprs
fn f(f: fn@() -> bool) { }
fn f(f: @fn() -> bool) { }
fn d(f: fn@()) { }
fn d(f: @fn()) { }
pub fn main() {
for f { }
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: fn&(int)) { f(10) }
fn f(f: &fn(int)) { f(10) }
pub fn main() {
do f() |i| { assert i == 10 }
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: fn@(int)) { f(10) }
fn f(f: @fn(int)) { f(10) }
pub fn main() {
do f() |i| { assert i == 10 }
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: fn@(int) -> int) -> int { f(10) }
fn f(f: @fn(int) -> int) -> int { f(10) }
pub fn main() {
assert do f() |i| { i } == 10;
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: fn@(int) -> int) -> int { f(10) }
fn f(f: @fn(int) -> int) -> int { f(10) }
pub fn main() {
assert do f |i| { i } == 10;
......
......@@ -15,8 +15,8 @@
*
* The hash should concentrate entropy in the lower bits.
*/
type HashFn<K> = pure fn~(K) -> uint;
type EqFn<K> = pure fn~(K, K) -> bool;
type HashFn<K> = ~pure fn(K) -> uint;
type EqFn<K> = ~pure fn(K, K) -> bool;
struct LM { resize_at: uint, size: uint }
......
......@@ -12,7 +12,7 @@
// -*- rust -*-
type compare<T> = fn@(@T, @T) -> bool;
type compare<T> = @fn(@T, @T) -> bool;
fn test_generic<T>(expected: @T, eq: compare<T>) {
let actual: @T = match true { true => { expected }, _ => fail!() };
......
......@@ -11,7 +11,7 @@
// xfail-fast
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = match true { true => { expected }, _ => fail!(~"wat") };
......
......@@ -11,7 +11,7 @@
// -*- rust -*-
type compare<T> = fn@(~T, ~T) -> bool;
type compare<T> = @fn(~T, ~T) -> bool;
fn test_generic<T:Copy>(expected: ~T, eq: compare<T>) {
let actual: ~T = match true {
......
......@@ -11,7 +11,7 @@
// xfail-fast
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = match true {
......
......@@ -11,7 +11,7 @@
// xfail-fast
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = match true { true => { expected }, _ => fail!(~"wat") };
......
......@@ -11,7 +11,7 @@
fn test_fn() {
type t = fn@() -> int;
type t = @fn() -> int;
fn ten() -> int { return 10; }
let rs: t = { ten };
//assert (rs() == 10);
......
......@@ -12,7 +12,7 @@
// -*- rust -*-
type compare<T> = fn@(@T, @T) -> bool;
type compare<T> = @fn(@T, @T) -> bool;
fn test_generic<T>(expected: @T, eq: compare<T>) {
let actual: @T = { expected };
......
......@@ -12,7 +12,7 @@
// xfail-fast
#[legacy_modes];
type compare<T> = fn@(T, T) -> bool;
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = { expected };
......
......@@ -11,7 +11,7 @@
// -*- rust -*-
type compare<T> = fn@(~T, ~T) -> bool;
type compare<T> = @fn(~T, ~T) -> bool;
fn test_generic<T:Copy>(expected: ~T, eq: compare<T>) {
let actual: ~T = { copy expected };
......
......@@ -12,7 +12,7 @@
// -*- rust -*-
#[legacy_modes];
type compare<T> = fn@(T, T) -> bool;
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = { expected };
......
......@@ -13,7 +13,7 @@
// xfail-fast
// Tests for standalone blocks as expressions with dynamic type sizes
type compare<T> = fn@(T, T) -> bool;
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = { expected };
......
......@@ -12,7 +12,7 @@
// -*- rust -*-
type compare<T> = fn@(@T, @T) -> bool;
type compare<T> = @fn(@T, @T) -> bool;
fn test_generic<T>(expected: @T, not_expected: @T, eq: compare<T>) {
let actual: @T = if true { expected } else { not_expected };
......
......@@ -12,7 +12,7 @@
// -*- rust -*-
#[legacy_modes];
type compare<T> = fn@(T, T) -> bool;
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, not_expected: T, eq: compare<T>) {
let actual: T = if true { expected } else { not_expected };
......
......@@ -12,7 +12,7 @@
// -*- rust -*-
// Tests for if as expressions with dynamic type sizes
type compare<T> = fn@(T, T) -> bool;
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, not_expected: T, eq: compare<T>) {
let actual: T = if true { expected } else { not_expected };
......
......@@ -10,15 +10,15 @@
// xfail-fast
fn fix_help<A, B>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
fn fix_help<A, B>(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B {
return f( |a| fix_help(f, a), x);
}
fn fix<A, B>(f: extern fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
fn fix<A, B>(f: extern fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B {
return |a| fix_help(f, a);
}
fn fact_(f: fn@(v: int) -> int, n: int) -> int {
fn fact_(f: @fn(v: int) -> int, n: int) -> int {
// fun fact 0 = 1
return if n == 0 { 1 } else { n * f(n - 1) };
}
......
......@@ -10,15 +10,15 @@
// xfail-fast
fn fix_help<A:&static,B:Owned>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
fn fix_help<A:&static,B:Owned>(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B {
return f(|a| fix_help(f, a), x);
}
fn fix<A:&static,B:Owned>(f: extern fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B {
fn fix<A:&static,B:Owned>(f: extern fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B {
return |a| fix_help(f, a);
}
fn fact_(f: fn@(v: int) -> int, n: int) -> int {
fn fact_(f: @fn(v: int) -> int, n: int) -> int {
// fun fact 0 = 1
return if n == 0 { 1 } else { n * f(n - 1) };
}
......
......@@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn add(n: int) -> fn@(int) -> int {
fn@(m: int) -> int { m + n }
fn add(n: int) -> @fn(int) -> int {
let result: @fn(int) -> int = |m| m + n;
result
}
pub fn main()
{
pub fn main() {
assert add(3)(4) == 7;
let add3 : fn(int)->int = add(3);
assert add3(4) == 7;
......
......@@ -8,20 +8,21 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn add(n: int) -> fn@(int) -> int {
fn@(m: int) -> int { m + n }
fn add(n: int) -> @fn(int) -> int {
let result: @fn(int) -> int = |m| m + n;
result
}
pub fn main()
{
assert add(3)(4) == 7;
let add1 : fn@(int)->int = add(1);
let add1 : @fn(int)->int = add(1);
assert add1(6) == 7;
let add2 : &(fn@(int)->int) = &add(2);
let add2 : &(@fn(int)->int) = &add(2);
assert (*add2)(5) == 7;
let add3 : fn(int)->int = add(3);
let add3 : &fn(int)->int = add(3);
assert add3(4) == 7;
}
......@@ -10,7 +10,7 @@
fn bare() {}
fn likes_shared(f: fn@()) { f() }
fn likes_shared(f: @fn()) { f() }
pub fn main() {
likes_shared(bare);
......
......@@ -9,7 +9,7 @@
// except according to those terms.
struct r {
field: fn@()
field: @fn()
}
pub fn main() {
......
......@@ -9,6 +9,8 @@
// except according to those terms.
pub fn main() {
// We should be able to type infer inside of fn@s.
let f = fn@() { let i = 10; };
// We should be able to type infer inside of @fns.
let f = || {
let i = 10;
};
}
......@@ -9,7 +9,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn ho(f: fn@(int) -> int) -> int { let n: int = f(3); return n; }
fn ho(f: @fn(int) -> int) -> int { let n: int = f(3); return n; }
fn direct(x: int) -> int { return x + 1; }
......
......@@ -29,7 +29,7 @@ mod map_reduce {
use std::oldmap::HashMap;
use core::comm::*;
pub type putter = fn@(~str, ~str);
pub type putter = @fn(~str, ~str);
pub type mapper = extern fn(~str, putter);
......
......@@ -13,7 +13,7 @@
// type must be known in this context' if the passing down doesn't
// happen.)
fn eat_tup(_r: ~@(int, fn@(Pair) -> int)) {}
fn eat_tup(_r: ~@(int, @fn(Pair) -> int)) {}
fn eat_rec(_r: @~Rec) {}
struct Rec { a: int, b: fn(Pair) -> int }
......
......@@ -9,5 +9,5 @@
// except according to those terms.
// xfail-test
pub fn main() { let early_error: fn@(str) -> ! = {|msg| fail!() }; }
pub fn main() { let early_error: @fn(str) -> ! = {|msg| fail!() }; }
......@@ -10,8 +10,7 @@
pub fn main() {
let x = 1;
let y = fn@() -> int {
x
}();
let y: @fn() -> int = || x;
let z = y();
}
......@@ -17,13 +17,13 @@ enum maybe_pointy {
struct Pointy {
a : maybe_pointy,
f : fn@()->(),
f : @fn()->(),
}
fn empty_pointy() -> @mut Pointy {
return @mut Pointy{
a : none,
f : fn@()->(){},
f : || {},
}
}
......
......@@ -18,21 +18,21 @@ trait iterable<A> {
fn iter(blk: fn(A));
}
impl<A> iterable<A> for fn@(fn(A)) {
impl<A> iterable<A> for @fn(&fn(A)) {
fn iter(blk: fn(A)) { self(blk); }
}
impl iterable<uint> for fn@(fn(uint)) {
impl iterable<uint> for @fn(&fn(uint)) {
fn iter(blk: fn(&&v: uint)) { self( |i| blk(i) ) }
}
fn filter<A,IA:iterable<A>>(self: IA, prd: fn@(A) -> bool, blk: fn(A)) {
fn filter<A,IA:iterable<A>>(self: IA, prd: @fn(A) -> bool, blk: &fn(A)) {
do self.iter |a| {
if prd(a) { blk(a) }
}
}
fn foldl<A,B,IA:iterable<A>>(self: IA, b0: B, blk: fn(B, A) -> B) -> B {
fn foldl<A,B,IA:iterable<A>>(self: IA, b0: B, blk: &fn(B, A) -> B) -> B {
let mut b = b0;
do self.iter |a| {
b = blk(b, a);
......@@ -40,7 +40,7 @@ fn foldl<A,B,IA:iterable<A>>(self: IA, b0: B, blk: fn(B, A) -> B) -> B {
b
}
fn range(lo: uint, hi: uint, it: fn(uint)) {
fn range(lo: uint, hi: uint, it: &fn(uint)) {
let mut i = lo;
while i < hi {
it(i);
......@@ -49,8 +49,8 @@ fn range(lo: uint, hi: uint, it: fn(uint)) {
}
pub fn main() {
let range: fn@(fn&(uint)) = |a| range(0u, 1000u, a);
let filt: fn@(fn&(v: uint)) = |a| filter(
let range: @fn(&fn(uint)) = |a| range(0u, 1000u, a);
let filt: @fn(&fn(v: uint)) = |a| filter(
range,
|&&n: uint| n % 3u != 0u && n % 5u != 0u,
a);
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册