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