#[link(name="cci_impl_lib", vers="0.0")];
trait uint_helpers {
- fn to(&self, v: uint, f: &fn(uint));
+ fn to(&self, v: uint, f: |uint|);
}
impl uint_helpers for uint {
#[inline]
- fn to(&self, v: uint, f: &fn(uint)) {
+ fn to(&self, v: uint, f: |uint|) {
let mut i = *self;
while i < v {
f(i);
#[link(name="cci_iter_lib", vers="0.0")];
#[inline]
-pub fn iter<T>(v: &[T], f: &fn(&T)) {
+pub fn iter<T>(v: &[T], f: |&T|) {
let mut i = 0u;
let n = v.len();
while i < n {
#[link(name="cci_no_inline_lib", vers="0.0")];
// same as cci_iter_lib, more-or-less, but not marked inline
-pub fn iter(v: ~[uint], f: &fn(uint)) {
+pub fn iter(v: ~[uint], f: |uint|) {
let mut i = 0u;
let n = v.len();
while i < n {
use std::uint;
use std::vec;
-fn timed(label: &str, f: &fn()) {
+fn timed(label: &str, f: ||) {
let start = time::precise_time_s();
f();
let end = time::precise_time_s();
delete_strings: f64
}
-fn timed(result: &mut f64, op: &fn()) {
+fn timed(result: &mut f64, op: ||) {
let start = extra::time::precise_time_s();
op();
let end = extra::time::precise_time_s();
impl Results {
pub fn bench_int<T:MutableSet<uint>,
- R: rand::Rng>(
- &mut self,
- rng: &mut R,
- num_keys: uint,
- rand_cap: uint,
- f: &fn() -> T) {
- {
+ R: rand::Rng>(
+ &mut self,
+ rng: &mut R,
+ num_keys: uint,
+ rand_cap: uint,
+ f: || -> T) { {
let mut set = f();
do timed(&mut self.sequential_ints) {
for i in range(0u, num_keys) {
}
pub fn bench_str<T:MutableSet<~str>,
- R:rand::Rng>(
- &mut self,
- rng: &mut R,
- num_keys: uint,
- f: &fn() -> T) {
+ R:rand::Rng>(
+ &mut self,
+ rng: &mut R,
+ num_keys: uint,
+ f: || -> T) {
{
let mut set = f();
do timed(&mut self.sequential_strings) {
bench!(argv, is_utf8_multibyte);
}
-fn maybe_run_test(argv: &[~str], name: ~str, test: &fn()) {
+fn maybe_run_test(argv: &[~str], name: ~str, test: ||) {
let mut run_test = false;
if os::getenv("RUST_BENCH").is_some() {
// given a ~[u8], for each window call a function
// i.e., for "hello" and windows of size four,
// run it("hell") and it("ello"), then return "llo"
-fn windows_with_carry(bb: &[u8], nn: uint,
- it: &fn(window: &[u8])) -> ~[u8] {
+fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> ~[u8] {
let mut ii = 0u;
let len = bb.len();
}
}
- fn each(&self, f: &fn(entry: &Entry) -> bool) {
+ fn each(&self, f: |entry: &Entry| -> bool) {
for self.items.each |item| {
match *item {
None => {}
struct sty(~[int]);
-fn unpack(_unpack: &fn(v: &sty) -> ~[int]) {}
+fn unpack(_unpack: |v: &sty| -> ~[int]) {}
fn main() {
let _foo = unpack(|s| {
fn f(f: extern fn(extern fn(extern fn()))) {
}
- fn g(f: extern fn(&fn())) {
+ fn g(f: extern fn(||)) {
}
f(g);
// Make sure that fn-to-block coercion isn't incorrectly lifted over
// other tycons.
-fn coerce(b: &fn()) -> extern fn() {
- fn lol(f: extern fn(v: &fn()) -> extern fn(),
- g: &fn()) -> extern fn() { return f(g); }
+fn coerce(b: ||) -> extern fn() {
+ fn lol(f: extern fn(v: ||) -> extern fn(),
+ g: ||) -> extern fn() { return f(g); }
fn fn_id(f: extern fn()) -> extern fn() { return f }
return lol(fn_id, b);
//~^ ERROR mismatched types
info!("{}", *q);
}
-fn borrow(_x: &[int], _f: &fn()) {}
+fn borrow(_x: &[int], _f: ||) {}
fn b() {
// here we alias the mutable vector into an imm slice and try to
struct X(Either<(uint,uint),extern fn()>);
impl X {
- pub fn with(&self, blk: &fn(x: &Either<(uint,uint),extern fn()>)) {
+ pub fn with(&self, blk: |x: &Either<(uint,uint),extern fn()>|) {
blk(&**self)
}
}
}
impl Foo {
- pub fn foo(&mut self, fun: &fn(&int)) {
+ pub fn foo(&mut self, fun: |&int|) {
for f in self.n.iter() {
fun(f);
}
fn borrow(_v: &int) {}
fn borrow_mut(_v: &mut int) {}
fn cond() -> bool { fail!() }
-fn for_func(_f: &fn() -> bool) { fail!() }
+fn for_func(_f: || -> bool) { fail!() }
fn produce<T>() -> T { fail!(); }
fn inc(v: &mut ~int) {
}
}
-fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: &fn(&'r mut uint) -> bool) {
+fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) {
// Here we check that when you break out of an inner loop, the
// borrows that go out of scope as you exit the inner loop are
// removed from the bitset.
}
}
-fn loop_loop_pops_scopes<'r>(_v: &'r mut [uint], f: &fn(&'r mut uint) -> bool) {
+fn loop_loop_pops_scopes<'r>(_v: &'r mut [uint], f: |&'r mut uint| -> bool) {
// Similar to `loop_break_pops_scopes` but for the `loop` keyword
while cond() {
fn borrow(_v: &int) {}
fn borrow_mut(_v: &mut int) {}
fn cond() -> bool { fail!() }
-fn for_func(_f: &fn() -> bool) { fail!() }
+fn for_func(_f: || -> bool) { fail!() }
fn produce<T>() -> T { fail!(); }
fn inc(v: &mut ~int) {
use std::task;
-fn borrow(v: &int, f: &fn(x: &int)) {
+fn borrow(v: &int, f: |x: &int|) {
f(v);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn borrow(v: &int, f: &fn(x: &int)) {
+fn borrow(v: &int, f: |x: &int|) {
f(v);
}
trait methods {
fn impurem(&self);
- fn blockm(&self, f: &fn());
+ fn blockm(&self, f: ||);
}
impl methods for point {
fn impurem(&self) {
}
- fn blockm(&self, f: &fn()) { f() }
+ fn blockm(&self, f: ||) { f() }
}
fn a() {
// (locally rooted) mutable, unique vector, and that we then prevent
// modifications to the contents.
-fn takes_imm_elt(_v: &int, f: &fn()) {
+fn takes_imm_elt(_v: &int, f: ||) {
f();
}
-fn with(f: &fn(&~str)) {}
+fn with(f: |&~str|) {}
fn arg_item(&_x: &~str) {}
//~^ ERROR cannot move out of dereference of & pointer
trait Foo {}
-fn take(f: &fn:Foo()) {
+fn take(f: ||:Foo) {
//~^ ERROR only the builtin traits can be used as closure or object bounds
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn bar(blk: &fn:'static()) {
+fn bar(blk: ||:'static) {
}
fn foo(x: &()) {
-fn take_any(_: &fn:()) {
+fn take_any(_: ||:) {
}
-fn take_const_owned(_: &fn:Freeze+Send()) {
+fn take_const_owned(_: ||:Freeze+Send) {
}
-fn give_any(f: &fn:()) {
+fn give_any(f: ||:) {
take_any(f);
}
-fn give_owned(f: &fn:Send()) {
+fn give_owned(f: ||:Send) {
take_any(f);
take_const_owned(f); //~ ERROR expected bounds `Send+Freeze` but found bounds `Send`
}
-fn foo(f: &fn() -> !) {}
+fn foo(f: || -> !) {}
fn main() {
// Type inference didn't use to be able to handle this:
// 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: |int| -> bool) -> bool { f(10i) }
fn main() {
assert!(do f() |i| { i == 10i } == 10i);
fn main() {
// extern functions are extern "C" fn
let _x: extern "C" fn() = f; // OK
- let _x: &fn() = f; //~ ERROR mismatched types
+ let _x: || = f; //~ ERROR mismatched types
}
fn takes_mut(x: @mut int) { }
fn takes_imm(x: @int) { }
-fn apply<T>(t: T, f: &fn(T)) {
+fn apply<T>(t: T, f: |T|) {
f(t)
}
}
fn g() {
- let _frob: &fn(~int) = |q| { *q = 2; }; //~ ERROR cannot assign
+ let _frob: |~int| = |q| { *q = 2; }; //~ ERROR cannot assign
}
// xfail-test
fn main() {
- let one: &fn() -> uint = || {
+ let one: || -> uint = || {
enum r { a };
a as uint
};
- let two = &fn() -> uint = || {
+ let two = || -> uint = || {
enum r { a };
a as uint
};
// except according to those terms.
trait vec_monad<A> {
- fn bind<B>(&self, f: &fn(A) -> ~[B]);
+ fn bind<B>(&self, f: |A| -> ~[B]);
}
impl<A> vec_monad<A> for ~[A] {
- fn bind<B>(&self, f: &fn(A) -> ~[B]) {
+ fn bind<B>(&self, f: |A| -> ~[B]) {
let mut r = fail!();
for elt in self.iter() { r = r + f(*elt); }
//~^ ERROR the type of this value must be known
// except according to those terms.
fn f() { }
-struct S(&fn()); //~ ERROR missing lifetime specifier
+struct S(||); //~ ERROR missing lifetime specifier
pub static C: S = S(f);
fn g() { }
-type T = &fn(); //~ ERROR missing lifetime specifier
+type T = ||; //~ ERROR missing lifetime specifier
pub static D: T = g;
fn main() {}
// Regression test for issue #5239
fn main() {
- let x: &fn(int) -> int = |ref x| { x += 1; }; //~ ERROR binary operation + cannot be applied to type `&int`
+ let x: |int| -> int = |ref x| { x += 1; }; //~ ERROR binary operation + cannot be applied to type `&int`
}
// transferring ownership of the owned box before invoking the stack
// closure results in a crash.
-fn twice(x: ~uint) -> uint
-{
+fn twice(x: ~uint) -> uint {
*x * 2
}
-fn invoke(f : &fn() -> uint)
-{
+fn invoke(f: || -> uint) {
f();
}
-fn main()
-{
+fn main() {
let x : ~uint = ~9;
- let sq : &fn() -> uint = || { *x * *x };
+ let sq : || -> uint = || { *x * *x };
twice(x);
invoke(sq);
}
-pub fn list_database(f: &fn(&PkgId)) {
+pub fn list_database(f: |&PkgId|) {
let stuff = ["foo", "bar"];
for l in stuff.iter() {
assert_freeze::<&'a mut Dummy:Freeze>(); //~ ERROR does not fulfill `Freeze`
// closures are like an `&mut` object
- assert_freeze::<&fn()>(); //~ ERROR does not fulfill `Freeze`
+ assert_freeze::<||>(); //~ ERROR does not fulfill `Freeze`
// unsafe ptrs are ok unless they point at unfreezeable things
assert_freeze::<*int>();
let mut _allowed = 1;
}
-fn callback(f: &fn()) {}
+fn callback(f: ||) {}
// make sure the lint attribute can be turned off
#[allow(unused_mut)]
}
}
-fn callback<T>(_f: &fn() -> T) -> T { fail!() }
+fn callback<T>(_f: || -> T) -> T { fail!() }
unsafe fn unsf() {}
fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn force(f: &fn()) { f(); }
+fn force(f: ||) { f(); }
fn main() {
let x: int;
force(|| {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn force(f: &fn() -> int) -> int { f() }
+fn force(f: || -> int) -> int { f() }
fn main() { info!("{:?}", force(|| {})); } //~ ERROR mismatched types
// except according to those terms.
fn main() {
- let j: &fn() -> int = || {
+ let j: || -> int = || {
let i: int;
i //~ ERROR use of possibly uninitialized variable: `i`
};
// except according to those terms.
fn main() {
- let f: &fn() -> int = || {
+ let f: || -> int = || {
let i: int;
i //~ ERROR use of possibly uninitialized variable: `i`
};
// Regression test for issue #2783
-fn foo(f: &fn()) { f() }
+fn foo(f: ||) { f() }
fn main() {
~"" || 42; //~ ERROR binary operation || cannot be applied to type
Baz
}
-fn f(s: &S, g: &fn(&S)) {
+fn f(s: &S, g: |&S|) {
g(s)
}
}
}
-fn conspirator(f: &fn(&R, bool)) {
+fn conspirator(f: |&R, bool|) {
let r = R {c: f};
f(&r, false) //~ ERROR use of moved value
}
// except according to those terms.
// xfail-test - #2093
-fn let_in<T>(x: T, f: &fn(T)) {}
+fn let_in<T>(x: T, f: |T|) {}
fn main() {
let_in(3u, |i| { assert!(i == 3); });
use extra::arc;
use std::util;
-fn foo(blk: &fn()) {
+fn foo(blk: ||) {
blk();
blk();
}
#[feature(once_fns)];
fn main() {
let f: &once fn() = ||();
- let g: &fn() = f; //~ ERROR mismatched types
- let h: &fn() = ||();
+ let g: || = f; //~ ERROR mismatched types
+ let h: || = ||();
let i: &once fn() = h; // ok
}
check_pp(expr3, pprust::print_expr, "2 - 23 + 7");
}
-fn check_pp<T>(expr: T, f: &fn(pprust::ps, T), expect: str) {
+fn check_pp<T>(expr: T, f: |pprust::ps, T|, expect: str) {
fail!();
}
check_pp(*stmt, pprust::print_stmt, "");
}
-fn check_pp<T>(expr: T, f: &fn(pprust::ps, T), expect: str) {
+fn check_pp<T>(expr: T, f: |pprust::ps, T|, expect: str) {
fail!();
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn env<'a>(_: &'a uint, blk: &fn(p: &'a fn())) {
+fn env<'a>(_: &'a uint, blk: |p: 'a |||) {
// Test that the closure here cannot be assigned
// the lifetime `'a`, which outlives the current
// block.
blk(|| *statep = 1); //~ ERROR cannot infer an appropriate lifetime
}
-fn no_env_no_for<'a>(_: &'a uint, blk: &fn(p: &'a fn())) {
+fn no_env_no_for<'a>(_: &'a uint, blk: |p: 'a |||) {
// Test that a closure with no free variables CAN
// outlive the block in which it is created.
//
}
}
-fn map_nums(x: &ast, f: &fn(uint) -> uint) -> &ast {
+fn map_nums(x: &ast, f: |uint| -> uint) -> &ast {
match *x {
num(x) => {
return &num(f(x)); //~ ERROR borrowed value does not live long enough
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn with_int(f: &fn(x: &int)) {
+fn with_int(f: |x: &int|) {
let x = 3;
f(&x);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn with_int(f: &fn(x: &int)) {
+fn with_int(f: |x: &int|) {
let x = 3;
f(&x);
}
}
}
-fn with<R:deref>(f: &fn(x: &int) -> R) -> int {
+fn with<R:deref>(f: |x: &int| -> R) -> int {
f(&3).get()
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn of<T>() -> &fn(T) { fail!(); }
-fn subtype<T>(x: &fn(T)) { fail!(); }
+fn of<T>() -> |T| { fail!(); }
+fn subtype<T>(x: |T|) { fail!(); }
fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) {
// Here, x, y, and z are free. Other letters
// iff T1 <: T2.
// should be the default:
- subtype::<&'static fn()>(of::<&fn()>());
- subtype::<&fn()>(of::<&'static fn()>());
+ subtype::<'static ||>(of::<||>());
+ subtype::<||>(of::<'static ||>());
//
- subtype::<&'x fn()>(of::<&fn()>()); //~ ERROR mismatched types
- subtype::<&'x fn()>(of::<&'y fn()>()); //~ ERROR mismatched types
+ subtype::<'x ||>(of::<||>()); //~ ERROR mismatched types
+ subtype::<'x ||>(of::<'y ||>()); //~ ERROR mismatched types
- subtype::<&'x fn()>(of::<&'static fn()>()); //~ ERROR mismatched types
- subtype::<&'static fn()>(of::<&'x fn()>());
+ subtype::<'x ||>(of::<'static ||>()); //~ ERROR mismatched types
+ subtype::<'static ||>(of::<'x ||>());
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn of<T>() -> &fn(T) { fail!(); }
-fn subtype<T>(x: &fn(T)) { fail!(); }
+fn of<T>() -> |T| { fail!(); }
+fn subtype<T>(x: |T|) { fail!(); }
fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
// Here, x, y, and z are free. Other letters
// subtype::<T1>(of::<T2>()) will typecheck
// iff T1 <: T2.
- subtype::<&fn<'a>(&'a T)>(
- of::<&fn<'a>(&'a T)>());
+ subtype::< <'a>|&'a T|>(
+ of::< <'a>|&'a T|>());
- subtype::<&fn<'a>(&'a T)>(
- of::<&fn<'b>(&'b T)>());
+ subtype::< <'a>|&'a T|>(
+ of::< <'b>|&'b T|>());
- subtype::<&fn<'b>(&'b T)>(
- of::<&fn(&'x T)>());
+ subtype::< <'b>|&'b T|>(
+ of::<|&'x T|>());
- subtype::<&fn(&'x T)>(
- of::<&fn<'b>(&'b T)>()); //~ ERROR mismatched types
+ subtype::<|&'x T|>(
+ of::< <'b>|&'b T|>()); //~ ERROR mismatched types
- subtype::<&fn<'a,'b>(&'a T, &'b T)>(
- of::<&fn<'a>(&'a T, &'a T)>());
+ subtype::< <'a,'b>|&'a T, &'b T|>(
+ of::< <'a>|&'a T, &'a T|>());
- subtype::<&fn<'a>(&'a T, &'a T)>(
- of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
+ subtype::< <'a>|&'a T, &'a T|>(
+ of::< <'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types
- subtype::<&fn<'a,'b>(&'a T, &'b T)>(
- of::<&fn(&'x T, &'y T)>());
+ subtype::< <'a,'b>|&'a T, &'b T|>(
+ of::<|&'x T, &'y T|>());
- subtype::<&fn(&'x T, &'y T)>(
- of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
+ subtype::<|&'x T, &'y T|>(
+ of::< <'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types
}
fn main() {}
// we reported errors in this case:
fn not_ok<'b>(a: &uint, b: &'b uint) {
- let mut g: &fn(x: &uint) = |x: &'b uint| {};
+ let mut g: |x: &uint| = |x: &'b uint| {};
//~^ ERROR mismatched types
g(a);
}
fail!();
}
-fn ordering4<'a, 'b>(a: &'a uint, b: &'b uint, x: &fn(&'a &'b uint)) {
+fn ordering4<'a, 'b>(a: &'a uint, b: &'b uint, x: |&'a &'b uint|) {
let z: Option<&'a &'b uint> = None;
}
}
fn call4<'a, 'b>(a: &'a uint, b: &'b uint) {
- let z: Option<&fn(&'a &'b uint)> = None;
+ let z: Option<|&'a &'b uint|> = None;
//~^ ERROR pointer has a longer lifetime than the data it references
}
fn borrow<'r, T>(x: &'r T) -> &'r T {x}
-fn foo(cond: &fn() -> bool, box: &fn() -> @int) {
+fn foo(cond: || -> bool, box: || -> @int) {
let mut y: ∫
loop {
let x = box();
fn select<'r>(x: &'r int, y: &'r int) -> &'r int { x }
-fn with<T>(f: &fn(x: &int) -> T) -> T {
+fn with<T>(f: |x: &int| -> T) -> T {
f(&20)
}
// &'a CAN be declared on functions and used then:
fn g<'a>(a: &'a int) { } // OK
- fn h(a: &fn<'a>(&'a int)) { } // OK
+ fn h(a: <'a>|&'a int|) { } // OK
}
// Test nesting of lifetimes in fn type declarations
fn fn_types(a: &'a int, //~ ERROR undeclared lifetime
- b: &fn<'a>(a: &'a int,
- b: &'b int, //~ ERROR undeclared lifetime
- c: &fn<'b>(a: &'a int,
- b: &'b int),
- d: &'b int), //~ ERROR undeclared lifetime
+ b: <'a>|a: &'a int,
+ b: &'b int, //~ ERROR undeclared lifetime
+ c: <'b>|a: &'a int,
+ b: &'b int|,
+ d: &'b int|, //~ ERROR undeclared lifetime
c: &'a int) //~ ERROR undeclared lifetime
{
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn ignore(_f: &fn<'z>(&'z int) -> &'z int) {}
+fn ignore(_f: <'z>|&'z int| -> &'z int) {}
fn nested() {
let y = 3;
let y = 3;
let mut ay = &y; //~ ERROR cannot infer an appropriate lifetime
- ignore::<&fn<'z>(&'z int)>(|z| {
+ ignore::< <'z>|&'z int|>(|z| {
ay = x;
ay = &y;
ay = z;
});
- ignore::<&fn<'z>(&'z int) -> &'z int>(|z| {
+ ignore::< <'z>|&'z int| -> &'z int>(|z| {
if false { return x; } //~ ERROR mismatched types
//~^ ERROR cannot infer an appropriate lifetime
if false { return ay; }
x //~^ ERROR borrowed value does not live long enough
}
-fn with<R>(f: &fn(~int) -> R) -> R { f(~3) }
+fn with<R>(f: |~int| -> R) -> R { f(~3) }
fn arg_closure() -> &'static int {
with(|~ref x| x) //~ ERROR borrowed value does not live long enough
// some point regions-ret-borrowed reported an error but this file did
// not, due to special hardcoding around the anonymous region.
-fn with<R>(f: &fn<'a>(x: &'a int) -> R) -> R {
+fn with<R>(f: <'a>|x: &'a int| -> R) -> R {
f(&3)
}
// used to successfully compile because we failed to account for the
// fact that fn(x: &int) rebound the region &.
-fn with<R>(f: &fn(x: &int) -> R) -> R {
+fn with<R>(f: |x: &int| -> R) -> R {
f(&3)
}
// error-pattern:attempt to use a type argument out of scope
fn foo<T>(x: T) {
- fn bar(f: &fn(T) -> T) { }
+ fn bar(f: |T| -> T) { }
}
fn main() { foo(1); }
zzz();
sentinel();
- let stack_closure: &fn(int) = |x| {
+ let stack_closure: |int| = |x| {
zzz();
sentinel();
#[allow(unreachable_code)];
#[allow(unused_variable)];
-fn x(it: &fn(int)) {
+fn x(it: |int|) {
fail!();
it(0);
}
// error-pattern:fail
-fn x(it: &fn(int)) {
+fn x(it: |int|) {
let _a = @0;
it(1);
}
let cheese = ~"roquefort";
let carrots = @~"crunchy";
- let result: &'static fn(@~str, &fn(~str)) = (|tasties, macerate| {
+ let result: &'static fn(@~str, |~str|) = (|tasties, macerate| {
macerate((*tasties).clone());
});
result(carrots, |food| {
let mush = food + cheese;
let cheese = cheese.clone();
- let f: &fn() = || {
+ let f: || = || {
let _chew = mush + cheese;
fail!("so yummy")
};
}
fn check_pp<T>(cx: fake_ext_ctxt,
- expr: T, f: &fn(pprust::ps, T), expect: ~str) {
+ expr: T, f: |pprust::ps, T|, expect: ~str) {
let s = do io::with_str_writer |wr| {
let pp = pprust::rust_printer(wr, cx.parse_sess().interner);
f(pp, expr);
return r;
}
-fn f2(a: int, f: &fn(int)) -> int { f(1); return a; }
+fn f2(a: int, f: |int|) -> int { f(1); return a; }
pub fn main() {
let mut a = X {x: 1};
// it.
trait iterable<A> {
- fn iterate(&self, blk: &fn(x: &A) -> bool) -> bool;
+ fn iterate(&self, blk: |x: &A| -> bool) -> bool;
}
impl<'self,A> iterable<A> for &'self [A] {
- fn iterate(&self, f: &fn(x: &A) -> bool) -> bool {
+ fn iterate(&self, f: |x: &A| -> bool) -> bool {
self.iter().advance(f)
}
}
impl<A> iterable<A> for ~[A] {
- fn iterate(&self, f: &fn(x: &A) -> bool) -> bool {
+ fn iterate(&self, f: |x: &A| -> bool) -> bool {
self.iter().advance(f)
}
}
fn f<T>(x: ~[T]) -> T { return x[0]; }
-fn g(act: &fn(~[int]) -> int) -> int { return act(~[1, 2, 3]); }
+fn g(act: |~[int]| -> int) -> int { return act(~[1, 2, 3]); }
pub fn main() {
assert_eq!(g(f), 1);
- let f1: &fn(~[~str]) -> ~str = f;
+ let f1: |~[~str]| -> ~str = f;
assert_eq!(f1(~[~"x", ~"y", ~"z"]), ~"x");
}
extern mod extra;
-fn asSendfn( f : proc()->uint ) -> uint {
+fn asSendfn(f: proc() -> uint) -> uint {
return f();
}
-fn asBlock( f : &fn()->uint ) -> uint {
+fn asBlock(f: || -> uint) -> uint {
return f();
}
// except according to those terms.
pub fn main() {
- fn f(i: &fn() -> uint) -> uint { i() }
+ fn f(i: || -> uint) -> uint { i() }
let v = ~[-1.0, 0.0, 1.0, 2.0, 3.0];
let z = do do v.iter().fold(f) |x, _y| { x } { 22u };
assert_eq!(z, 22u);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn call_any(f: &fn() -> uint) -> uint {
+fn call_any(f: || -> uint) -> uint {
return f();
}
// except according to those terms.
pub fn main() {
- fn as_buf<T>(s: ~str, f: &fn(~str) -> T) -> T { f(s) }
+ fn as_buf<T>(s: ~str, f: |~str| -> T) -> T { f(s) }
as_buf(~"foo", |foo: ~str| -> () error!("{}", foo) );
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn force(f: &fn() -> int) -> int { return f(); }
+fn force(f: || -> int) -> int { return f(); }
pub fn main() {
fn f() -> int { return 7; }
assert_eq!(force(f), 7);
// xfail-fast
-fn iter_vec<T>(v: ~[T], f: &fn(&T)) { for x in v.iter() { f(x); } }
+fn iter_vec<T>(v: ~[T], f: |&T|) { for x in v.iter() { f(x); } }
pub fn main() {
let v = ~[1, 2, 3, 4, 5, 6, 7];
// xfail-fast
-fn iter_vec<T>(v: ~[T], f: &fn(&T)) { for x in v.iter() { f(x); } }
+fn iter_vec<T>(v: ~[T], f: |&T|) { for x in v.iter() { f(x); } }
pub fn main() {
let v = ~[1, 2, 3, 4, 5];
use std::borrow;
use std::ptr;
-fn borrow(x: &int, f: &fn(x: &int)) {
+fn borrow(x: &int, f: |x: &int|) {
f(x)
}
util::swap(&mut values, &mut x.values);
}
-fn iter_ints(x: &Ints, f: &fn(x: &int) -> bool) -> bool {
+fn iter_ints(x: &Ints, f: |x: &int| -> bool) -> bool {
let l = x.values.len();
range(0u, l).advance(|i| f(&x.values[i]))
}
use std::ptr;
-fn borrow(x: &int, f: &fn(x: &int)) {
+fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let after = *x;
use std::ptr;
-fn borrow(x: &int, f: &fn(x: &int)) {
+fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let after = *x;
use std::ptr;
-fn borrow(x: &int, f: &fn(x: &int)) {
+fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let after = *x;
use std::ptr;
-fn borrow(x: &int, f: &fn(x: &int)) {
+fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
let after = *x;
fn foo(i: int) -> int { i + 1 }
-fn apply<A>(f: &fn(A) -> A, v: A) -> A { f(v) }
+fn apply<A>(f: |A| -> A, v: A) -> A { f(v) }
pub fn main() {
let f = {|i| foo(i)};
// no-reformat
// Testing various forms of `do` with empty arg lists
-fn f(_f: &fn() -> bool) -> bool {
+fn f(_f: || -> bool) -> bool {
true
}
// Testing that we can drop the || in do exprs
-fn f(_f: &fn() -> bool) -> bool { true }
+fn f(_f: || -> bool) -> bool { true }
-fn d(_f: &fn()) { }
+fn d(_f: ||) { }
pub fn main() {
do d { }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn f(_f: &fn()) {
+fn f(_f: ||) {
}
fn g() {
// 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: |int|) { f(10) }
pub fn main() {
do f() |i| { assert!(i == 10) }
// 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: |int|) { f(10) }
pub fn main() {
do f() |i| { assert!(i == 10) }
// 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: |int| -> int) -> int { f(10) }
pub fn main() {
assert_eq!(do f() |i| { i }, 10);
// 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: |int| -> int) -> int { f(10) }
pub fn main() {
assert_eq!(do f |i| { i }, 10);
fn bare() {}
-fn likes_block(f: &fn()) { f() }
+fn likes_block(f: ||) { f() }
pub fn main() {
likes_block(bare);
// except according to those terms.
pub fn main() {
- let f: &fn((int,int)) = |(x, y)| {
+ let f: |(int,int)| = |(x, y)| {
assert_eq!(x, 1);
assert_eq!(y, 2);
};
#[allow(unused_variable)];
pub fn main() {
- // We should be able to type infer inside of &fns.
+ // We should be able to type infer inside of ||s.
let _f = || {
let i = 10;
};
-fn two(it: &fn(int)) { it(0); it(1); }
+fn two(it: |int|) { it(0); it(1); }
pub fn main() {
let mut a: ~[int] = ~[-1, -1, -1, -1];
-fn pairs(it: &fn((int, int))) {
+fn pairs(it: |(int, int)|) {
let mut i: int = 0;
let mut j: int = 0;
while i < 10 { it((i, j)); i += 1; j += i; }
assert_eq!(sum, 45);
}
-fn first_ten(it: &fn(int)) {
+fn first_ten(it: |int|) {
let mut i: int = 0;
while i < 10 { info!("first_ten"); it(i); i = i + 1; }
}
// 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: |int| -> int) -> int { let n: int = f(3); return n; }
fn direct(x: int) -> int { return x + 1; }
// except according to those terms.
trait vec_utils<T> {
- fn map_<U>(x: &Self, f: &fn(&T) -> U) -> ~[U];
+ fn map_<U>(x: &Self, f: |&T| -> U) -> ~[U];
}
impl<T> vec_utils<T> for ~[T] {
- fn map_<U>(x: &~[T], f: &fn(&T) -> U) -> ~[U] {
+ fn map_<U>(x: &~[T], f: |&T| -> U) -> ~[U] {
let mut r = ~[];
for elt in x.iter() {
r.push(f(elt));
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn plus_one(f: &fn() -> int) -> int {
+fn plus_one(f: || -> int) -> int {
return f() + 1;
}
-fn ret_plus_one() -> extern fn(&fn() -> int) -> int {
+fn ret_plus_one() -> extern fn(|| -> int) -> int {
return plus_one;
}
//
// Running /usr/local/bin/rustc:
// issue-2185.rs:24:0: 26:1 error: conflicting implementations for a trait
-// issue-2185.rs:24 impl iterable<uint> for &'static fn(&fn(uint)) {
-// issue-2185.rs:25 fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) }
+// issue-2185.rs:24 impl iterable<uint> for &'static fn(|uint|) {
+// issue-2185.rs:25 fn iter(&self, blk: |v: uint|) { self( |i| blk(i) ) }
// issue-2185.rs:26 }
// issue-2185.rs:20:0: 22:1 note: note conflicting implementation here
-// issue-2185.rs:20 impl<A> iterable<A> for &'static fn(&fn(A)) {
-// issue-2185.rs:21 fn iter(&self, blk: &fn(A)) { self(blk); }
+// issue-2185.rs:20 impl<A> iterable<A> for 'static ||A|| {
+// issue-2185.rs:21 fn iter(&self, blk: |A|) { self(blk); }
// issue-2185.rs:22 }
//
// … so it looks like it's just not possible to implement both the generic iterable<uint> and iterable<A> for the type iterable<uint>. Is it okay if I just remove this test?
// warrant still having a test, so I inlined the old definitions.
trait iterable<A> {
- fn iter(&self, blk: &fn(A));
+ fn iter(&self, blk: |A|);
}
-impl<A> iterable<A> for &'static fn(&fn(A)) {
- fn iter(&self, blk: &fn(A)) { self(blk); }
+impl<A> iterable<A> for 'static ||A|| {
+ fn iter(&self, blk: |A|) { self(blk); }
}
-impl iterable<uint> for &'static fn(&fn(uint)) {
- fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) }
+impl iterable<uint> for 'static ||uint|| {
+ fn iter(&self, blk: |v: uint|) { self( |i| blk(i) ) }
}
-fn filter<A,IA:iterable<A>>(self: IA,
- prd: &'static fn(A) -> bool,
- blk: &fn(A)) {
+fn filter<A,IA:iterable<A>>(self: IA, prd: 'static |A| -> bool, blk: |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: |B, A| -> B) -> B {
let mut b = b0;
do self.iter |a| {
b = blk(b, a);
b
}
-fn range(lo: uint, hi: uint, it: &fn(uint)) {
+fn range(lo: uint, hi: uint, it: |uint|) {
let mut i = lo;
while i < hi {
it(i);
}
pub fn main() {
- let range: &'static fn(&fn(uint)) = |a| range(0u, 1000u, a);
- let filt: &'static fn(&fn(v: uint)) = |a| filter(
+ let range: 'static ||uint|| = |a| range(0u, 1000u, a);
+ let filt: 'static ||v: uint|| = |a| filter(
range,
|&&n: uint| n % 3u != 0u && n % 5u != 0u,
a);
// xfail-test FIXME #2190
mod a {
- fn foo(f: &fn()) { f() }
+ fn foo(f: ||) { f() }
fn bar() {}
pub fn main() { foo(||bar()); }
}
mod b {
- fn foo(f: Option<&fn()>) { f.iter(|x|x()) }
+ fn foo(f: Option<||>) { f.iter(|x|x()) }
fn bar() {}
pub fn main() { foo(Some(bar)); }
}
mod c {
- fn foo(f: Option<&fn()>) { f.iter(|x|x()) }
+ fn foo(f: Option<||>) { f.iter(|x|x()) }
fn bar() {}
pub fn main() { foo(Some(||bar())); }
}
}
}
-fn closure(f: &fn()) { f() }
+fn closure(f: ||) { f() }
fn setsockopt_bytes(_sock: int) { }
pub fn main() {
let x = 1;
- let y: &fn() -> int = || x;
+ let y: || -> int = || x;
let _z = y();
}
#[deny(dead_assignment)];
fn main() {
let mut x = 1;
- let f: &fn() -> int = || { x + 20 };
+ let f: || -> int = || { x + 20 };
assert_eq!(f(), 21);
x += 1;
assert_eq!(f(), 22);
enum PureCounter { PureCounter(uint) }
-fn each(thing: PureCounter, blk: &fn(v: &uint)) {
+fn each(thing: PureCounter, blk: |v: &uint|) {
let PureCounter(ref x) = thing;
blk(x);
}
// except according to those terms.
// xfail-test
-type ErrPrinter = &fn(&str, &str);
+type ErrPrinter = |&str, &str|;
fn example_err(prog: &str, arg: &str) {
println!("{}: {}", prog, arg)
// Regression test for issue #5239
pub fn main() {
- let _f: &fn(int) -> int = |ref x: int| { *x };
+ let _f: |int| -> int = |ref x: int| { *x };
let foo = 10;
assert!(_f(foo) == 10);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn swap(f: &fn(~[int]) -> ~[int]) -> ~[int] {
+fn swap(f: |~[int]| -> ~[int]) -> ~[int] {
let x = ~[1, 2, 3];
f(x)
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn f<T>(g: &fn() -> T) -> T { g() }
+fn f<T>(g: || -> T) -> T { g() }
pub fn main() {
let _x = f( | | { 10 });
-fn range_(a: int, b: int, it: &fn(int)) {
+fn range_(a: int, b: int, it: |int|) {
assert!((a < b));
let mut i: int = a;
while i < b { it(i); i += 1; }
// except according to those terms.
// This should typecheck even though the type of e is not fully
-// resolved when we finish typechecking the &fn.
+// resolved when we finish typechecking the ||.
struct Refs { refs: ~[int], n: int }
pub fn main() {
let e = @mut Refs{refs: ~[], n: 0};
- let _f: &fn() = || error!("{}", e.n);
+ let _f: || = || error!("{}", e.n);
e.refs.push(1);
}
// Issue #1818
-fn lp<T>(s: ~str, f: &fn(~str) -> T) -> T {
+fn lp<T>(s: ~str, f: |~str| -> T) -> T {
while false {
let r = f(s);
return (r);
fail!();
}
-fn apply<T>(s: ~str, f: &fn(~str) -> T) -> T {
- fn g<T>(s: ~str, f: &fn(~str) -> T) -> T {f(s)}
+fn apply<T>(s: ~str, f: |~str| -> T) -> T {
+ fn g<T>(s: ~str, f: |~str| -> T) -> T {f(s)}
g(s, |v| { let r = f(v); r })
}
struct A { a: ~int }
pub fn main() {
- fn invoke(f: &fn()) { f(); }
+ fn invoke(f: ||) { f(); }
let k = ~22;
let _u = A {a: k.clone()};
invoke(|| error!("{:?}", k.clone()) )
enum thing { a, b, c, }
-fn foo(it: &fn(int)) { it(10); }
+fn foo(it: |int|) { it(10); }
pub fn main() {
let mut x = true;
// xfail-fast
trait vec_monad<A> {
- fn bind<B>(&self, f: &fn(&A) -> ~[B]) -> ~[B];
+ fn bind<B>(&self, f: |&A| -> ~[B]) -> ~[B];
}
impl<A> vec_monad<A> for ~[A] {
- fn bind<B>(&self, f: &fn(&A) -> ~[B]) -> ~[B] {
+ fn bind<B>(&self, f: |&A| -> ~[B]) -> ~[B] {
let mut r = ~[];
for elt in self.iter() {
r.push_all_move(f(elt));
}
trait option_monad<A> {
- fn bind<B>(&self, f: &fn(&A) -> Option<B>) -> Option<B>;
+ fn bind<B>(&self, f: |&A| -> Option<B>) -> Option<B>;
}
impl<A> option_monad<A> for Option<A> {
- fn bind<B>(&self, f: &fn(&A) -> Option<B>) -> Option<B> {
+ fn bind<B>(&self, f: |&A| -> Option<B>) -> Option<B> {
match *self {
Some(ref a) => { f(a) }
None => { None }
// except according to those terms.
// Issue #922
-fn f2(_thing: &fn()) { }
+fn f2(_thing: ||) { }
-fn f(thing: &fn()) {
+fn f(thing: ||) {
f2(thing);
}
}
fn g() {
- let frob: &fn(~int) = |mut q| { *q = 2; assert!(*q == 2); };
+ let frob: |~int| = |mut q| { *q = 2; assert!(*q == 2); };
let w = ~37;
frob(w);
// Tests for the new |args| expr lambda syntax
-fn f(i: int, f: &fn(int) -> int) -> int { f(i) }
+fn f(i: int, f: |int| -> int) -> int { f(i) }
-fn g(_g: &fn()) { }
+fn g(_g: ||) { }
pub fn main() {
assert_eq!(f(10, |a| a), 10);
repr: int
}
-fn apply<T>(x: T, f: &fn(T)) {
+fn apply<T>(x: T, f: |T|) {
f(x);
}
// except according to those terms.
-fn something(f: &fn()) { f(); }
+fn something(f: ||) { f(); }
pub fn main() {
something(|| error!("hi!") );
}
/// Trait for visitor that wishes to reflect on data.
trait movable_ptr {
- fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void);
+ fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void);
}
/// Helper function for alignment calculation.
}
impl my_visitor {
- pub fn get<T:Clone>(&mut self, f: &fn(T)) {
+ pub fn get<T:Clone>(&mut self, f: |T|) {
unsafe {
f((*(self.ptr1 as *T)).clone());
}
struct Inner<V> { inner: V }
impl movable_ptr for my_visitor {
- fn move_ptr(&mut self, adjustment: &fn(*c_void) -> *c_void) {
+ fn move_ptr(&mut self, adjustment: |*c_void| -> *c_void) {
self.ptr1 = adjustment(self.ptr1);
self.ptr2 = adjustment(self.ptr2);
}
// Here, `f` is a function that takes a pointer `x` and a function
// `g`, where `g` requires its argument `y` to be in the same region
// that `x` is in.
-fn has_same_region(f: &fn<'a>(x: &'a int, g: &fn(y: &'a int))) {
+fn has_same_region(f: <'a>|x: &'a int, g: |y: &'a int||) {
// `f` should be the type that `wants_same_region` wants, but
// right now the compiler complains that it isn't.
wants_same_region(f);
}
-fn wants_same_region(_f: &fn<'b>(x: &'b int, g: &fn(y: &'b int))) {
+fn wants_same_region(_f: <'b>|x: &'b int, g: |y: &'b int||) {
}
pub fn main() {
#[allow(unused_variable)];
// Should pass region checking.
-fn ok(f: &fn(x: &uint)) {
+fn ok(f: |x: &uint|) {
// Here, g is a function that can accept a uint pointer with
// lifetime r, and f is a function that can accept a uint pointer
// with any lifetime. The assignment g = f should be OK (i.e.,
// f's type should be a subtype of g's type), because f can be
// used in any context that expects g's type. But this currently
// fails.
- let mut g: &fn<'r>(y: &'r uint) = |x| { };
+ let mut g: <'r>|y: &'r uint| = |x| { };
g = f;
}
// This version is the same as above, except that here, g's type is
// inferred.
-fn ok_inferred(f: &fn(x: &uint)) {
- let mut g: &fn<'r>(x: &'r uint) = |_| {};
+fn ok_inferred(f: |x: &uint|) {
+ let mut g: <'r>|x: &'r uint| = |_| {};
g = f;
}
fn takes_two(x: &int, y: &int) -> int { *x + *y }
-fn with<T>(f: &fn(x: &int) -> T) -> T {
+fn with<T>(f: |x: &int| -> T) -> T {
f(&20)
}
fn region_identity<'r>(x: &'r uint) -> &'r uint { x }
-fn apply<T>(t: T, f: &fn(T) -> T) -> T { f(t) }
+fn apply<T>(t: T, f: |T| -> T) -> T { f(t) }
fn parameterized(x: &uint) -> uint {
let z = apply(x, ({|y|
// xfail-fast
-fn test(f: &fn(uint) -> uint) -> uint {
+fn test(f: |uint| -> uint) -> uint {
return f(22u);
}
trait uint_utils {
fn str(&self) -> ~str;
- fn multi(&self, f: &fn(uint));
+ fn multi(&self, f: |uint|);
}
impl uint_utils for uint {
fn str(&self) -> ~str { self.to_str() }
- fn multi(&self, f: &fn(uint)) {
+ fn multi(&self, f: |uint|) {
let mut c = 0u;
while c < *self { f(c); c += 1u; }
}
trait vec_utils<T> {
fn length_(&self, ) -> uint;
- fn iter_(&self, f: &fn(&T));
- fn map_<U>(&self, f: &fn(&T) -> U) -> ~[U];
+ fn iter_(&self, f: |&T|);
+ fn map_<U>(&self, f: |&T| -> U) -> ~[U];
}
impl<T> vec_utils<T> for ~[T] {
fn length_(&self) -> uint { self.len() }
- fn iter_(&self, f: &fn(&T)) { for x in self.iter() { f(x); } }
- fn map_<U>(&self, f: &fn(&T) -> U) -> ~[U] {
+ fn iter_(&self, f: |&T|) { for x in self.iter() { f(x); } }
+ fn map_<U>(&self, f: |&T| -> U) -> ~[U] {
let mut r = ~[];
for elt in self.iter() {
r.push(f(elt));
}
fn joinable(f: proc()) -> Port<bool> {
- fn wrapper(c: Chan<bool>, f: &fn()) {
+ fn wrapper(c: Chan<bool>, f: ||) {
let b = @mut false;
error!("wrapper: task=%? allocated v=%x",
0,
assert!(!root.join("bar").join("blat").exists());
}
-fn in_tmpdir(f: &fn()) {
+fn in_tmpdir(f: ||) {
let tmpdir = TempDir::new("test").expect("can't make tmpdir");
assert!(os::change_dir(tmpdir.path()));
use std::cell;
trait Pet {
- fn name(&self, blk: &fn(&str));
+ fn name(&self, blk: |&str|);
fn num_legs(&self) -> uint;
fn of_good_pedigree(&self) -> bool;
}
}
impl Pet for Catte {
- fn name(&self, blk: &fn(&str)) { blk(self.name) }
+ fn name(&self, blk: |&str|) { blk(self.name) }
fn num_legs(&self) -> uint { 4 }
fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 }
}
impl Pet for Dogge {
- fn name(&self, blk: &fn(&str)) { blk(self.name) }
+ fn name(&self, blk: |&str|) { blk(self.name) }
fn num_legs(&self) -> uint { 4 }
fn of_good_pedigree(&self) -> bool {
self.bark_decibels < 70 || self.tricks_known > 20
}
}
impl Pet for Goldfyshe {
- fn name(&self, blk: &fn(&str)) { blk(self.name) }
+ fn name(&self, blk: |&str|) { blk(self.name) }
fn num_legs(&self) -> uint { 0 }
fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 }
}
}
trait map<T> {
- fn map<U>(&self, f: &fn(&T) -> U) -> ~[U];
+ fn map<U>(&self, f: |&T| -> U) -> ~[U];
}
impl<T> map<T> for ~[T] {
- fn map<U>(&self, f: &fn(&T) -> U) -> ~[U] {
+ fn map<U>(&self, f: |&T| -> U) -> ~[U] {
let mut r = ~[];
// FIXME: #7355 generates bad code with VecIterator
for i in range(0u, self.len()) {
b: uint,
}
-fn range_(lo: uint, hi: uint, it: &fn(uint)) {
+fn range_(lo: uint, hi: uint, it: |uint|) {
let mut lo_ = lo;
while lo_ < hi { it(lo_); lo_ += 1u; }
}
// unnamed argument &int is now parse x: &int
-fn called(_f: &fn(&int)) {
+fn called(_f: |&int|) {
}
pub fn main() {
pub fn main() {
let _x = ~1;
- let lam_move: &fn() = || {};
+ let lam_move: || = || {};
lam_move();
}
fn sprintf(s: *mut c_char, format: *c_char, ...) -> c_int;
}
-unsafe fn check<T>(expected: &str, f: &fn(*mut c_char) -> T) {
+unsafe fn check<T>(expected: &str, f: |*mut c_char| -> T) {
let mut x = [0i8, ..50];
f(&mut x[0] as *mut c_char);
let res = CString::new(&x[0], false);
fn foldl<T,U:Clone>(values: &[T],
initial: U,
- function: &fn(partial: U, element: &T) -> U)
+ function: |partial: U, element: &T| -> U)
-> U {
match values {
[ref head, ..tail] =>
fn foldr<T,U:Clone>(values: &[T],
initial: U,
- function: &fn(element: &T, partial: U) -> U)
+ function: |element: &T, partial: U| -> U)
-> U {
match values {
[..head, ref tail] =>