提交 40681395 编写于 作者: P Patrick Walton

test: Remove most uses of `&fn()` from the tests.

上级 ef70b766
......@@ -11,12 +11,12 @@
#[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);
......
......@@ -11,7 +11,7 @@
#[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 {
......
......@@ -11,7 +11,7 @@
#[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 {
......
......@@ -19,7 +19,7 @@
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();
......
......@@ -27,7 +27,7 @@ struct Results {
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();
......@@ -36,13 +36,12 @@ fn timed(result: &mut f64, op: &fn()) {
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) {
......@@ -79,11 +78,11 @@ pub fn bench_int<T:MutableSet<uint>,
}
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) {
......
......@@ -40,7 +40,7 @@ fn main() {
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() {
......
......@@ -104,8 +104,7 @@ fn update_freq(mm: &mut HashMap<~[u8], uint>, key: &[u8]) {
// 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();
......
......@@ -154,7 +154,7 @@ fn lookup<C:TableCallback>(&mut self, key: Code, c: C) {
}
}
fn each(&self, f: &fn(entry: &Entry) -> bool) {
fn each(&self, f: |entry: &Entry| -> bool) {
for self.items.each |item| {
match *item {
None => {}
......
......@@ -11,7 +11,7 @@
struct sty(~[int]);
fn unpack(_unpack: &fn(v: &sty) -> ~[int]) {}
fn unpack(_unpack: |v: &sty| -> ~[int]) {}
fn main() {
let _foo = unpack(|s| {
......
......@@ -15,7 +15,7 @@ fn main() {
fn f(f: extern fn(extern fn(extern fn()))) {
}
fn g(f: extern fn(&fn())) {
fn g(f: extern fn(||)) {
}
f(g);
......
......@@ -11,9 +11,9 @@
// 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
......
......@@ -24,7 +24,7 @@ fn a() {
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
......
......@@ -11,7 +11,7 @@
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)
}
}
......
......@@ -15,7 +15,7 @@ struct Foo {
}
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);
}
......
......@@ -17,7 +17,7 @@
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) {
......
......@@ -111,7 +111,7 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) {
}
}
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.
......@@ -127,7 +127,7 @@ fn loop_break_pops_scopes<'r>(_v: &'r mut [uint], f: &fn(&'r mut uint) -> bool)
}
}
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() {
......
......@@ -17,7 +17,7 @@
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) {
......
......@@ -10,7 +10,7 @@
use std::task;
fn borrow(v: &int, f: &fn(x: &int)) {
fn borrow(v: &int, f: |x: &int|) {
f(v);
}
......
......@@ -8,7 +8,7 @@
// 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);
}
......
......@@ -12,14 +12,14 @@ struct point { x: int, y: int }
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() {
......
......@@ -12,7 +12,7 @@
// (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
}
......
......@@ -8,7 +8,7 @@
// 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:
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: &fn(int) -> bool) -> bool { f(10i) }
fn f(f: |int| -> bool) -> bool { f(10i) }
fn main() {
assert!(do f() |i| { i == 10i } == 10i);
......
......@@ -14,5 +14,5 @@
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
}
......@@ -13,7 +13,7 @@
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)
}
......
......@@ -13,7 +13,7 @@ fn f(y: ~int) {
}
fn g() {
let _frob: &fn(~int) = |q| { *q = 2; }; //~ ERROR cannot assign
let _frob: |~int| = |q| { *q = 2; }; //~ ERROR cannot assign
}
......
......@@ -10,11 +10,11 @@
// 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
};
......
......@@ -9,11 +9,11 @@
// 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
......
......@@ -9,12 +9,12 @@
// 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() {}
......@@ -11,5 +11,5 @@
// 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`
}
......@@ -4,20 +4,17 @@
// 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);
......
......@@ -35,7 +35,7 @@ pub fn remove_package_from_database() {
}
pub fn list_database(f: &fn(&PkgId)) {
pub fn list_database(f: |&PkgId|) {
let stuff = ["foo", "bar"];
for l in stuff.iter() {
......
......@@ -45,7 +45,7 @@ fn test<'a,T,U:Freeze>(_: &'a int) {
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>();
......
......@@ -55,7 +55,7 @@ fn what(mut foo: int) {} //~ ERROR: variable does not need to be mutable
let mut _allowed = 1;
}
fn callback(f: &fn()) {}
fn callback(f: ||) {}
// make sure the lint attribute can be turned off
#[allow(unused_mut)]
......
......@@ -18,7 +18,7 @@ mod foo {
}
}
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
......
......@@ -8,7 +8,7 @@
// 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(|| {
......
......@@ -8,5 +8,5 @@
// 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
......@@ -9,7 +9,7 @@
// 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`
};
......
......@@ -9,7 +9,7 @@
// 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`
};
......
......@@ -10,7 +10,7 @@
// 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
......
......@@ -8,7 +8,7 @@ enum E {
Baz
}
fn f(s: &S, g: &fn(&S)) {
fn f(s: &S, g: |&S|) {
g(s)
}
......
......@@ -36,7 +36,7 @@ fn innocent_looking_victim() {
}
}
fn conspirator(f: &fn(&R, bool)) {
fn conspirator(f: |&R, bool|) {
let r = R {c: f};
f(&r, false) //~ ERROR use of moved value
}
......
......@@ -9,7 +9,7 @@
// 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); });
......
......@@ -15,7 +15,7 @@
use extra::arc;
use std::util;
fn foo(blk: &fn()) {
fn foo(blk: ||) {
blk();
blk();
}
......
......@@ -11,7 +11,7 @@
#[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
}
......@@ -62,6 +62,6 @@ fn main() {
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!();
}
......@@ -57,6 +57,6 @@ fn main() {
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!();
}
......@@ -8,7 +8,7 @@
// 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.
......@@ -21,7 +21,7 @@ fn env<'a>(_: &'a uint, blk: &fn(p: &'a fn())) {
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.
//
......
......@@ -27,7 +27,7 @@ fn compute(x: &ast) -> uint {
}
}
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
......
......@@ -8,7 +8,7 @@
// 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);
}
......
......@@ -8,7 +8,7 @@
// 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);
}
......
......@@ -18,7 +18,7 @@ fn get(self) -> int {
}
}
fn with<R:deref>(f: &fn(x: &int) -> R) -> int {
fn with<R:deref>(f: |x: &int| -> R) -> int {
f(&3).get()
}
......
......@@ -11,8 +11,8 @@
// 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
......@@ -21,14 +21,14 @@ fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) {
// 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 ||>());
}
......@@ -8,8 +8,8 @@
// 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
......@@ -17,29 +17,29 @@ fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
// 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() {}
......@@ -12,7 +12,7 @@
// 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);
}
......
......@@ -30,7 +30,7 @@ fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint {
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;
}
......
......@@ -26,7 +26,7 @@ fn call3<'a, 'b>(a: &'a uint, b: &'b uint) {
}
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
}
......
......@@ -12,7 +12,7 @@
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: &int;
loop {
let x = box();
......
......@@ -10,7 +10,7 @@
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)
}
......
......@@ -43,16 +43,16 @@ fn f(a: &'a int) { } //~ ERROR undeclared lifetime
// &'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
{
}
......
......@@ -8,7 +8,7 @@
// 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;
......
......@@ -14,13 +14,13 @@ fn nested<'x>(x: &'x int) {
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; }
......
......@@ -2,7 +2,7 @@ fn arg_item(~ref x: ~int) -> &'static int {
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
......
......@@ -12,7 +12,7 @@
// 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)
}
......
......@@ -15,7 +15,7 @@
// 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)
}
......
......@@ -10,6 +10,6 @@
// 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); }
......@@ -51,7 +51,7 @@ fn main() {
zzz();
sentinel();
let stack_closure: &fn(int) = |x| {
let stack_closure: |int| = |x| {
zzz();
sentinel();
......
......@@ -13,7 +13,7 @@
#[allow(unreachable_code)];
#[allow(unused_variable)];
fn x(it: &fn(int)) {
fn x(it: |int|) {
fail!();
it(0);
}
......
......@@ -10,7 +10,7 @@
// error-pattern:fail
fn x(it: &fn(int)) {
fn x(it: |int|) {
let _a = @0;
it(1);
}
......
......@@ -16,13 +16,13 @@ fn main() {
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")
};
......
......@@ -74,7 +74,7 @@ fn main() {
}
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);
......
......@@ -21,7 +21,7 @@ fn f1(a: &mut X, b: &mut int, c: int) -> int {
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};
......
......@@ -13,17 +13,17 @@
// 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)
}
}
......
......@@ -10,10 +10,10 @@
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");
}
......@@ -10,11 +10,11 @@
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();
}
......
......@@ -9,7 +9,7 @@
// 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);
......
......@@ -8,7 +8,7 @@
// 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();
}
......
......@@ -9,6 +9,6 @@
// 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) );
}
......@@ -8,7 +8,7 @@
// 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);
......
......@@ -10,7 +10,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];
......
......@@ -10,7 +10,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];
......
......@@ -13,7 +13,7 @@
use std::borrow;
use std::ptr;
fn borrow(x: &int, f: &fn(x: &int)) {
fn borrow(x: &int, f: |x: &int|) {
f(x)
}
......
......@@ -20,7 +20,7 @@ fn add_int(x: &mut Ints, v: int) {
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]))
}
......
......@@ -12,7 +12,7 @@
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;
......
......@@ -12,7 +12,7 @@
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;
......
......@@ -12,7 +12,7 @@
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;
......
......@@ -12,7 +12,7 @@
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;
......
......@@ -12,7 +12,7 @@
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)};
......
......@@ -11,7 +11,7 @@
// no-reformat
// Testing various forms of `do` with empty arg lists
fn f(_f: &fn() -> bool) -> bool {
fn f(_f: || -> bool) -> bool {
true
}
......
......@@ -10,9 +10,9 @@
// 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 { }
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(_f: &fn()) {
fn f(_f: ||) {
}
fn g() {
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: &fn(int)) { f(10) }
fn f(f: |int|) { f(10) }
pub fn main() {
do f() |i| { assert!(i == 10) }
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: &fn(int)) { f(10) }
fn f(f: |int|) { f(10) }
pub fn main() {
do f() |i| { assert!(i == 10) }
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: &fn(int) -> int) -> int { f(10) }
fn f(f: |int| -> int) -> int { f(10) }
pub fn main() {
assert_eq!(do f() |i| { i }, 10);
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(f: &fn(int) -> int) -> int { f(10) }
fn f(f: |int| -> int) -> int { f(10) }
pub fn main() {
assert_eq!(do f |i| { i }, 10);
......
......@@ -10,7 +10,7 @@
fn bare() {}
fn likes_block(f: &fn()) { f() }
fn likes_block(f: ||) { f() }
pub fn main() {
likes_block(bare);
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册