test: Remove most uses of &fn()
from the tests.
This commit is contained in:
parent
ef70b7666e
commit
406813957b
145 changed files with 249 additions and 256 deletions
|
@ -11,12 +11,12 @@
|
||||||
#[link(name="cci_impl_lib", vers="0.0")];
|
#[link(name="cci_impl_lib", vers="0.0")];
|
||||||
|
|
||||||
trait uint_helpers {
|
trait uint_helpers {
|
||||||
fn to(&self, v: uint, f: &fn(uint));
|
fn to(&self, v: uint, f: |uint|);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl uint_helpers for uint {
|
impl uint_helpers for uint {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to(&self, v: uint, f: &fn(uint)) {
|
fn to(&self, v: uint, f: |uint|) {
|
||||||
let mut i = *self;
|
let mut i = *self;
|
||||||
while i < v {
|
while i < v {
|
||||||
f(i);
|
f(i);
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#[link(name="cci_iter_lib", vers="0.0")];
|
#[link(name="cci_iter_lib", vers="0.0")];
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter<T>(v: &[T], f: &fn(&T)) {
|
pub fn iter<T>(v: &[T], f: |&T|) {
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
let n = v.len();
|
let n = v.len();
|
||||||
while i < n {
|
while i < n {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#[link(name="cci_no_inline_lib", vers="0.0")];
|
#[link(name="cci_no_inline_lib", vers="0.0")];
|
||||||
|
|
||||||
// same as cci_iter_lib, more-or-less, but not marked inline
|
// 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 mut i = 0u;
|
||||||
let n = v.len();
|
let n = v.len();
|
||||||
while i < n {
|
while i < n {
|
||||||
|
|
|
@ -19,7 +19,7 @@ use std::trie::TrieMap;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
fn timed(label: &str, f: &fn()) {
|
fn timed(label: &str, f: ||) {
|
||||||
let start = time::precise_time_s();
|
let start = time::precise_time_s();
|
||||||
f();
|
f();
|
||||||
let end = time::precise_time_s();
|
let end = time::precise_time_s();
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct Results {
|
||||||
delete_strings: f64
|
delete_strings: f64
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timed(result: &mut f64, op: &fn()) {
|
fn timed(result: &mut f64, op: ||) {
|
||||||
let start = extra::time::precise_time_s();
|
let start = extra::time::precise_time_s();
|
||||||
op();
|
op();
|
||||||
let end = extra::time::precise_time_s();
|
let end = extra::time::precise_time_s();
|
||||||
|
@ -36,13 +36,12 @@ fn timed(result: &mut f64, op: &fn()) {
|
||||||
|
|
||||||
impl Results {
|
impl Results {
|
||||||
pub fn bench_int<T:MutableSet<uint>,
|
pub fn bench_int<T:MutableSet<uint>,
|
||||||
R: rand::Rng>(
|
R: rand::Rng>(
|
||||||
&mut self,
|
&mut self,
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
num_keys: uint,
|
num_keys: uint,
|
||||||
rand_cap: uint,
|
rand_cap: uint,
|
||||||
f: &fn() -> T) {
|
f: || -> T) { {
|
||||||
{
|
|
||||||
let mut set = f();
|
let mut set = f();
|
||||||
do timed(&mut self.sequential_ints) {
|
do timed(&mut self.sequential_ints) {
|
||||||
for i in range(0u, num_keys) {
|
for i in range(0u, num_keys) {
|
||||||
|
@ -79,11 +78,11 @@ impl Results {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bench_str<T:MutableSet<~str>,
|
pub fn bench_str<T:MutableSet<~str>,
|
||||||
R:rand::Rng>(
|
R:rand::Rng>(
|
||||||
&mut self,
|
&mut self,
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
num_keys: uint,
|
num_keys: uint,
|
||||||
f: &fn() -> T) {
|
f: || -> T) {
|
||||||
{
|
{
|
||||||
let mut set = f();
|
let mut set = f();
|
||||||
do timed(&mut self.sequential_strings) {
|
do timed(&mut self.sequential_strings) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ fn main() {
|
||||||
bench!(argv, is_utf8_multibyte);
|
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;
|
let mut run_test = false;
|
||||||
|
|
||||||
if os::getenv("RUST_BENCH").is_some() {
|
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
|
// given a ~[u8], for each window call a function
|
||||||
// i.e., for "hello" and windows of size four,
|
// i.e., for "hello" and windows of size four,
|
||||||
// run it("hell") and it("ello"), then return "llo"
|
// run it("hell") and it("ello"), then return "llo"
|
||||||
fn windows_with_carry(bb: &[u8], nn: uint,
|
fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> ~[u8] {
|
||||||
it: &fn(window: &[u8])) -> ~[u8] {
|
|
||||||
let mut ii = 0u;
|
let mut ii = 0u;
|
||||||
|
|
||||||
let len = bb.len();
|
let len = bb.len();
|
||||||
|
|
|
@ -154,7 +154,7 @@ impl Table {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn each(&self, f: &fn(entry: &Entry) -> bool) {
|
fn each(&self, f: |entry: &Entry| -> bool) {
|
||||||
for self.items.each |item| {
|
for self.items.each |item| {
|
||||||
match *item {
|
match *item {
|
||||||
None => {}
|
None => {}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
struct sty(~[int]);
|
struct sty(~[int]);
|
||||||
|
|
||||||
fn unpack(_unpack: &fn(v: &sty) -> ~[int]) {}
|
fn unpack(_unpack: |v: &sty| -> ~[int]) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _foo = unpack(|s| {
|
let _foo = unpack(|s| {
|
||||||
|
|
|
@ -15,7 +15,7 @@ fn main() {
|
||||||
fn f(f: extern fn(extern fn(extern fn()))) {
|
fn f(f: extern fn(extern fn(extern fn()))) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn g(f: extern fn(&fn())) {
|
fn g(f: extern fn(||)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
f(g);
|
f(g);
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
// Make sure that fn-to-block coercion isn't incorrectly lifted over
|
// Make sure that fn-to-block coercion isn't incorrectly lifted over
|
||||||
// other tycons.
|
// other tycons.
|
||||||
|
|
||||||
fn coerce(b: &fn()) -> extern fn() {
|
fn coerce(b: ||) -> extern fn() {
|
||||||
fn lol(f: extern fn(v: &fn()) -> extern fn(),
|
fn lol(f: extern fn(v: ||) -> extern fn(),
|
||||||
g: &fn()) -> extern fn() { return f(g); }
|
g: ||) -> extern fn() { return f(g); }
|
||||||
fn fn_id(f: extern fn()) -> extern fn() { return f }
|
fn fn_id(f: extern fn()) -> extern fn() { return f }
|
||||||
return lol(fn_id, b);
|
return lol(fn_id, b);
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
|
|
|
@ -24,7 +24,7 @@ fn a() {
|
||||||
info!("{}", *q);
|
info!("{}", *q);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrow(_x: &[int], _f: &fn()) {}
|
fn borrow(_x: &[int], _f: ||) {}
|
||||||
|
|
||||||
fn b() {
|
fn b() {
|
||||||
// here we alias the mutable vector into an imm slice and try to
|
// here we alias the mutable vector into an imm slice and try to
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
struct X(Either<(uint,uint),extern fn()>);
|
struct X(Either<(uint,uint),extern fn()>);
|
||||||
|
|
||||||
impl X {
|
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)
|
blk(&**self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ struct Foo {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Foo {
|
impl Foo {
|
||||||
pub fn foo(&mut self, fun: &fn(&int)) {
|
pub fn foo(&mut self, fun: |&int|) {
|
||||||
for f in self.n.iter() {
|
for f in self.n.iter() {
|
||||||
fun(f);
|
fun(f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
fn borrow(_v: &int) {}
|
fn borrow(_v: &int) {}
|
||||||
fn borrow_mut(_v: &mut int) {}
|
fn borrow_mut(_v: &mut int) {}
|
||||||
fn cond() -> bool { fail!() }
|
fn cond() -> bool { fail!() }
|
||||||
fn for_func(_f: &fn() -> bool) { fail!() }
|
fn for_func(_f: || -> bool) { fail!() }
|
||||||
fn produce<T>() -> T { fail!(); }
|
fn produce<T>() -> T { fail!(); }
|
||||||
|
|
||||||
fn inc(v: &mut ~int) {
|
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
|
// 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
|
// borrows that go out of scope as you exit the inner loop are
|
||||||
// removed from the bitset.
|
// 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
|
// Similar to `loop_break_pops_scopes` but for the `loop` keyword
|
||||||
|
|
||||||
while cond() {
|
while cond() {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
fn borrow(_v: &int) {}
|
fn borrow(_v: &int) {}
|
||||||
fn borrow_mut(_v: &mut int) {}
|
fn borrow_mut(_v: &mut int) {}
|
||||||
fn cond() -> bool { fail!() }
|
fn cond() -> bool { fail!() }
|
||||||
fn for_func(_f: &fn() -> bool) { fail!() }
|
fn for_func(_f: || -> bool) { fail!() }
|
||||||
fn produce<T>() -> T { fail!(); }
|
fn produce<T>() -> T { fail!(); }
|
||||||
|
|
||||||
fn inc(v: &mut ~int) {
|
fn inc(v: &mut ~int) {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
use std::task;
|
use std::task;
|
||||||
|
|
||||||
fn borrow(v: &int, f: &fn(x: &int)) {
|
fn borrow(v: &int, f: |x: &int|) {
|
||||||
f(v);
|
f(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 borrow(v: &int, f: &fn(x: &int)) {
|
fn borrow(v: &int, f: |x: &int|) {
|
||||||
f(v);
|
f(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,14 @@ struct point { x: int, y: int }
|
||||||
|
|
||||||
trait methods {
|
trait methods {
|
||||||
fn impurem(&self);
|
fn impurem(&self);
|
||||||
fn blockm(&self, f: &fn());
|
fn blockm(&self, f: ||);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl methods for point {
|
impl methods for point {
|
||||||
fn impurem(&self) {
|
fn impurem(&self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn blockm(&self, f: &fn()) { f() }
|
fn blockm(&self, f: ||) { f() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn a() {
|
fn a() {
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// (locally rooted) mutable, unique vector, and that we then prevent
|
// (locally rooted) mutable, unique vector, and that we then prevent
|
||||||
// modifications to the contents.
|
// modifications to the contents.
|
||||||
|
|
||||||
fn takes_imm_elt(_v: &int, f: &fn()) {
|
fn takes_imm_elt(_v: &int, f: ||) {
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
fn with(f: &fn(&~str)) {}
|
fn with(f: |&~str|) {}
|
||||||
|
|
||||||
fn arg_item(&_x: &~str) {}
|
fn arg_item(&_x: &~str) {}
|
||||||
//~^ ERROR cannot move out of dereference of & pointer
|
//~^ ERROR cannot move out of dereference of & pointer
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
trait Foo {}
|
trait Foo {}
|
||||||
|
|
||||||
fn take(f: &fn:Foo()) {
|
fn take(f: ||:Foo) {
|
||||||
//~^ ERROR only the builtin traits can be used as closure or object bounds
|
//~^ 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
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn bar(blk: &fn:'static()) {
|
fn bar(blk: ||:'static) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo(x: &()) {
|
fn foo(x: &()) {
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
|
|
||||||
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);
|
take_any(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn give_owned(f: &fn:Send()) {
|
fn give_owned(f: ||:Send) {
|
||||||
take_any(f);
|
take_any(f);
|
||||||
take_const_owned(f); //~ ERROR expected bounds `Send+Freeze` but found bounds `Send`
|
take_const_owned(f); //~ ERROR expected bounds `Send+Freeze` but found bounds `Send`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
fn foo(f: &fn() -> !) {}
|
fn foo(f: || -> !) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Type inference didn't use to be able to handle this:
|
// 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
|
// 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: |int| -> bool) -> bool { f(10i) }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
assert!(do f() |i| { i == 10i } == 10i);
|
assert!(do f() |i| { i == 10i } == 10i);
|
||||||
|
|
|
@ -14,5 +14,5 @@ extern fn f() {
|
||||||
fn main() {
|
fn main() {
|
||||||
// extern functions are extern "C" fn
|
// extern functions are extern "C" fn
|
||||||
let _x: extern "C" fn() = f; // OK
|
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_mut(x: @mut int) { }
|
||||||
fn takes_imm(x: @int) { }
|
fn takes_imm(x: @int) { }
|
||||||
|
|
||||||
fn apply<T>(t: T, f: &fn(T)) {
|
fn apply<T>(t: T, f: |T|) {
|
||||||
f(t)
|
f(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn f(y: ~int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn g() {
|
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
|
// xfail-test
|
||||||
fn main() {
|
fn main() {
|
||||||
let one: &fn() -> uint = || {
|
let one: || -> uint = || {
|
||||||
enum r { a };
|
enum r { a };
|
||||||
a as uint
|
a as uint
|
||||||
};
|
};
|
||||||
let two = &fn() -> uint = || {
|
let two = || -> uint = || {
|
||||||
enum r { a };
|
enum r { a };
|
||||||
a as uint
|
a as uint
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
trait vec_monad<A> {
|
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] {
|
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!();
|
let mut r = fail!();
|
||||||
for elt in self.iter() { r = r + f(*elt); }
|
for elt in self.iter() { r = r + f(*elt); }
|
||||||
//~^ ERROR the type of this value must be known
|
//~^ ERROR the type of this value must be known
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn f() { }
|
fn f() { }
|
||||||
struct S(&fn()); //~ ERROR missing lifetime specifier
|
struct S(||); //~ ERROR missing lifetime specifier
|
||||||
pub static C: S = S(f);
|
pub static C: S = S(f);
|
||||||
|
|
||||||
|
|
||||||
fn g() { }
|
fn g() { }
|
||||||
type T = &fn(); //~ ERROR missing lifetime specifier
|
type T = ||; //~ ERROR missing lifetime specifier
|
||||||
pub static D: T = g;
|
pub static D: T = g;
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -11,5 +11,5 @@
|
||||||
// Regression test for issue #5239
|
// Regression test for issue #5239
|
||||||
|
|
||||||
fn main() {
|
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
|
// transferring ownership of the owned box before invoking the stack
|
||||||
// closure results in a crash.
|
// closure results in a crash.
|
||||||
|
|
||||||
fn twice(x: ~uint) -> uint
|
fn twice(x: ~uint) -> uint {
|
||||||
{
|
|
||||||
*x * 2
|
*x * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invoke(f : &fn() -> uint)
|
fn invoke(f: || -> uint) {
|
||||||
{
|
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main()
|
fn main() {
|
||||||
{
|
|
||||||
let x : ~uint = ~9;
|
let x : ~uint = ~9;
|
||||||
let sq : &fn() -> uint = || { *x * *x };
|
let sq : || -> uint = || { *x * *x };
|
||||||
|
|
||||||
twice(x);
|
twice(x);
|
||||||
invoke(sq);
|
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"];
|
let stuff = ["foo", "bar"];
|
||||||
|
|
||||||
for l in stuff.iter() {
|
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`
|
assert_freeze::<&'a mut Dummy:Freeze>(); //~ ERROR does not fulfill `Freeze`
|
||||||
|
|
||||||
// closures are like an `&mut` object
|
// 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
|
// unsafe ptrs are ok unless they point at unfreezeable things
|
||||||
assert_freeze::<*int>();
|
assert_freeze::<*int>();
|
||||||
|
|
|
@ -55,7 +55,7 @@ fn main() {
|
||||||
let mut _allowed = 1;
|
let mut _allowed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn callback(f: &fn()) {}
|
fn callback(f: ||) {}
|
||||||
|
|
||||||
// make sure the lint attribute can be turned off
|
// make sure the lint attribute can be turned off
|
||||||
#[allow(unused_mut)]
|
#[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() {}
|
unsafe fn unsf() {}
|
||||||
|
|
||||||
fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
|
fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
|
||||||
|
|
|
@ -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 force(f: &fn()) { f(); }
|
fn force(f: ||) { f(); }
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: int;
|
let x: int;
|
||||||
force(|| {
|
force(|| {
|
||||||
|
|
|
@ -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 force(f: &fn() -> int) -> int { f() }
|
fn force(f: || -> int) -> int { f() }
|
||||||
fn main() { info!("{:?}", force(|| {})); } //~ ERROR mismatched types
|
fn main() { info!("{:?}", force(|| {})); } //~ ERROR mismatched types
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let j: &fn() -> int = || {
|
let j: || -> int = || {
|
||||||
let i: int;
|
let i: int;
|
||||||
i //~ ERROR use of possibly uninitialized variable: `i`
|
i //~ ERROR use of possibly uninitialized variable: `i`
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let f: &fn() -> int = || {
|
let f: || -> int = || {
|
||||||
let i: int;
|
let i: int;
|
||||||
i //~ ERROR use of possibly uninitialized variable: `i`
|
i //~ ERROR use of possibly uninitialized variable: `i`
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
// Regression test for issue #2783
|
// Regression test for issue #2783
|
||||||
|
|
||||||
fn foo(f: &fn()) { f() }
|
fn foo(f: ||) { f() }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
~"" || 42; //~ ERROR binary operation || cannot be applied to type
|
~"" || 42; //~ ERROR binary operation || cannot be applied to type
|
||||||
|
|
|
@ -8,7 +8,7 @@ enum E {
|
||||||
Baz
|
Baz
|
||||||
}
|
}
|
||||||
|
|
||||||
fn f(s: &S, g: &fn(&S)) {
|
fn f(s: &S, g: |&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};
|
let r = R {c: f};
|
||||||
f(&r, false) //~ ERROR use of moved value
|
f(&r, false) //~ ERROR use of moved value
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// 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: |T|) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let_in(3u, |i| { assert!(i == 3); });
|
let_in(3u, |i| { assert!(i == 3); });
|
||||||
|
|
|
@ -15,7 +15,7 @@ extern mod extra;
|
||||||
use extra::arc;
|
use extra::arc;
|
||||||
use std::util;
|
use std::util;
|
||||||
|
|
||||||
fn foo(blk: &fn()) {
|
fn foo(blk: ||) {
|
||||||
blk();
|
blk();
|
||||||
blk();
|
blk();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#[feature(once_fns)];
|
#[feature(once_fns)];
|
||||||
fn main() {
|
fn main() {
|
||||||
let f: &once fn() = ||();
|
let f: &once fn() = ||();
|
||||||
let g: &fn() = f; //~ ERROR mismatched types
|
let g: || = f; //~ ERROR mismatched types
|
||||||
let h: &fn() = ||();
|
let h: || = ||();
|
||||||
let i: &once fn() = h; // ok
|
let i: &once fn() = h; // ok
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,6 @@ fn main() {
|
||||||
check_pp(expr3, pprust::print_expr, "2 - 23 + 7");
|
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!();
|
fail!();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,6 @@ fn main() {
|
||||||
check_pp(*stmt, pprust::print_stmt, "");
|
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!();
|
fail!();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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
|
// Test that the closure here cannot be assigned
|
||||||
// the lifetime `'a`, which outlives the current
|
// the lifetime `'a`, which outlives the current
|
||||||
// block.
|
// block.
|
||||||
|
@ -21,7 +21,7 @@ fn env<'a>(_: &'a uint, blk: &fn(p: &'a fn())) {
|
||||||
blk(|| *statep = 1); //~ ERROR cannot infer an appropriate lifetime
|
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
|
// Test that a closure with no free variables CAN
|
||||||
// outlive the block in which it is created.
|
// 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 {
|
match *x {
|
||||||
num(x) => {
|
num(x) => {
|
||||||
return &num(f(x)); //~ ERROR borrowed value does not live long enough
|
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
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn with_int(f: &fn(x: &int)) {
|
fn with_int(f: |x: &int|) {
|
||||||
let x = 3;
|
let x = 3;
|
||||||
f(&x);
|
f(&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.
|
||||||
|
|
||||||
fn with_int(f: &fn(x: &int)) {
|
fn with_int(f: |x: &int|) {
|
||||||
let x = 3;
|
let x = 3;
|
||||||
f(&x);
|
f(&x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl<'self> deref for &'self int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with<R:deref>(f: &fn(x: &int) -> R) -> int {
|
fn with<R:deref>(f: |x: &int| -> R) -> int {
|
||||||
f(&3).get()
|
f(&3).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
// 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 of<T>() -> &fn(T) { fail!(); }
|
fn of<T>() -> |T| { fail!(); }
|
||||||
fn subtype<T>(x: &fn(T)) { fail!(); }
|
fn subtype<T>(x: |T|) { fail!(); }
|
||||||
|
|
||||||
fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) {
|
fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) {
|
||||||
// Here, x, y, and z are free. Other letters
|
// 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.
|
// iff T1 <: T2.
|
||||||
|
|
||||||
// should be the default:
|
// should be the default:
|
||||||
subtype::<&'static fn()>(of::<&fn()>());
|
subtype::<'static ||>(of::<||>());
|
||||||
subtype::<&fn()>(of::<&'static fn()>());
|
subtype::<||>(of::<'static ||>());
|
||||||
|
|
||||||
//
|
//
|
||||||
subtype::<&'x fn()>(of::<&fn()>()); //~ ERROR mismatched types
|
subtype::<'x ||>(of::<||>()); //~ ERROR mismatched types
|
||||||
subtype::<&'x fn()>(of::<&'y fn()>()); //~ ERROR mismatched types
|
subtype::<'x ||>(of::<'y ||>()); //~ ERROR mismatched types
|
||||||
|
|
||||||
subtype::<&'x fn()>(of::<&'static fn()>()); //~ ERROR mismatched types
|
subtype::<'x ||>(of::<'static ||>()); //~ ERROR mismatched types
|
||||||
subtype::<&'static fn()>(of::<&'x fn()>());
|
subtype::<'static ||>(of::<'x ||>());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
// 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 of<T>() -> &fn(T) { fail!(); }
|
fn of<T>() -> |T| { fail!(); }
|
||||||
fn subtype<T>(x: &fn(T)) { fail!(); }
|
fn subtype<T>(x: |T|) { fail!(); }
|
||||||
|
|
||||||
fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
|
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
|
// 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
|
// subtype::<T1>(of::<T2>()) will typecheck
|
||||||
// iff T1 <: T2.
|
// iff T1 <: T2.
|
||||||
|
|
||||||
subtype::<&fn<'a>(&'a T)>(
|
subtype::< <'a>|&'a T|>(
|
||||||
of::<&fn<'a>(&'a T)>());
|
of::< <'a>|&'a T|>());
|
||||||
|
|
||||||
subtype::<&fn<'a>(&'a T)>(
|
subtype::< <'a>|&'a T|>(
|
||||||
of::<&fn<'b>(&'b T)>());
|
of::< <'b>|&'b T|>());
|
||||||
|
|
||||||
subtype::<&fn<'b>(&'b T)>(
|
subtype::< <'b>|&'b T|>(
|
||||||
of::<&fn(&'x T)>());
|
of::<|&'x T|>());
|
||||||
|
|
||||||
subtype::<&fn(&'x T)>(
|
subtype::<|&'x T|>(
|
||||||
of::<&fn<'b>(&'b T)>()); //~ ERROR mismatched types
|
of::< <'b>|&'b T|>()); //~ ERROR mismatched types
|
||||||
|
|
||||||
subtype::<&fn<'a,'b>(&'a T, &'b T)>(
|
subtype::< <'a,'b>|&'a T, &'b T|>(
|
||||||
of::<&fn<'a>(&'a T, &'a T)>());
|
of::< <'a>|&'a T, &'a T|>());
|
||||||
|
|
||||||
subtype::<&fn<'a>(&'a T, &'a T)>(
|
subtype::< <'a>|&'a T, &'a T|>(
|
||||||
of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
|
of::< <'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types
|
||||||
|
|
||||||
subtype::<&fn<'a,'b>(&'a T, &'b T)>(
|
subtype::< <'a,'b>|&'a T, &'b T|>(
|
||||||
of::<&fn(&'x T, &'y T)>());
|
of::<|&'x T, &'y T|>());
|
||||||
|
|
||||||
subtype::<&fn(&'x T, &'y T)>(
|
subtype::<|&'x T, &'y T|>(
|
||||||
of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
|
of::< <'a,'b>|&'a T, &'b T|>()); //~ ERROR mismatched types
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// we reported errors in this case:
|
// we reported errors in this case:
|
||||||
|
|
||||||
fn not_ok<'b>(a: &uint, b: &'b uint) {
|
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
|
//~^ ERROR mismatched types
|
||||||
g(a);
|
g(a);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint {
|
||||||
fail!();
|
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;
|
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) {
|
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
|
//~^ 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 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: ∫
|
let mut y: ∫
|
||||||
loop {
|
loop {
|
||||||
let x = box();
|
let x = box();
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
fn select<'r>(x: &'r int, y: &'r int) -> &'r int { x }
|
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)
|
f(&20)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,16 +43,16 @@ fn bar<'a>(x: &'a int) {
|
||||||
|
|
||||||
// &'a CAN be declared on functions and used then:
|
// &'a CAN be declared on functions and used then:
|
||||||
fn g<'a>(a: &'a int) { } // OK
|
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
|
// Test nesting of lifetimes in fn type declarations
|
||||||
fn fn_types(a: &'a int, //~ ERROR undeclared lifetime
|
fn fn_types(a: &'a int, //~ ERROR undeclared lifetime
|
||||||
b: &fn<'a>(a: &'a int,
|
b: <'a>|a: &'a int,
|
||||||
b: &'b int, //~ ERROR undeclared lifetime
|
b: &'b int, //~ ERROR undeclared lifetime
|
||||||
c: &fn<'b>(a: &'a int,
|
c: <'b>|a: &'a int,
|
||||||
b: &'b int),
|
b: &'b int|,
|
||||||
d: &'b int), //~ ERROR undeclared lifetime
|
d: &'b int|, //~ ERROR undeclared lifetime
|
||||||
c: &'a int) //~ ERROR undeclared lifetime
|
c: &'a int) //~ ERROR undeclared lifetime
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 ignore(_f: &fn<'z>(&'z int) -> &'z int) {}
|
fn ignore(_f: <'z>|&'z int| -> &'z int) {}
|
||||||
|
|
||||||
fn nested() {
|
fn nested() {
|
||||||
let y = 3;
|
let y = 3;
|
||||||
|
|
|
@ -14,13 +14,13 @@ fn nested<'x>(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)>(|z| {
|
ignore::< <'z>|&'z int|>(|z| {
|
||||||
ay = x;
|
ay = x;
|
||||||
ay = &y;
|
ay = &y;
|
||||||
ay = z;
|
ay = z;
|
||||||
});
|
});
|
||||||
|
|
||||||
ignore::<&fn<'z>(&'z int) -> &'z int>(|z| {
|
ignore::< <'z>|&'z int| -> &'z int>(|z| {
|
||||||
if false { return x; } //~ ERROR mismatched types
|
if false { return x; } //~ ERROR mismatched types
|
||||||
//~^ ERROR cannot infer an appropriate lifetime
|
//~^ ERROR cannot infer an appropriate lifetime
|
||||||
if false { return ay; }
|
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
|
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 {
|
fn arg_closure() -> &'static int {
|
||||||
with(|~ref x| x) //~ ERROR borrowed value does not live long enough
|
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
|
// some point regions-ret-borrowed reported an error but this file did
|
||||||
// not, due to special hardcoding around the anonymous region.
|
// 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)
|
f(&3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// used to successfully compile because we failed to account for the
|
// used to successfully compile because we failed to account for the
|
||||||
// fact that fn(x: &int) rebound the region &.
|
// 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)
|
f(&3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
|
|
||||||
// error-pattern:attempt to use a type argument out of scope
|
// error-pattern:attempt to use a type argument out of scope
|
||||||
fn foo<T>(x: T) {
|
fn foo<T>(x: T) {
|
||||||
fn bar(f: &fn(T) -> T) { }
|
fn bar(f: |T| -> T) { }
|
||||||
}
|
}
|
||||||
fn main() { foo(1); }
|
fn main() { foo(1); }
|
||||||
|
|
|
@ -51,7 +51,7 @@ fn main() {
|
||||||
zzz();
|
zzz();
|
||||||
sentinel();
|
sentinel();
|
||||||
|
|
||||||
let stack_closure: &fn(int) = |x| {
|
let stack_closure: |int| = |x| {
|
||||||
zzz();
|
zzz();
|
||||||
sentinel();
|
sentinel();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#[allow(unreachable_code)];
|
#[allow(unreachable_code)];
|
||||||
#[allow(unused_variable)];
|
#[allow(unused_variable)];
|
||||||
|
|
||||||
fn x(it: &fn(int)) {
|
fn x(it: |int|) {
|
||||||
fail!();
|
fail!();
|
||||||
it(0);
|
it(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
// error-pattern:fail
|
// error-pattern:fail
|
||||||
|
|
||||||
fn x(it: &fn(int)) {
|
fn x(it: |int|) {
|
||||||
let _a = @0;
|
let _a = @0;
|
||||||
it(1);
|
it(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,13 @@ fn main() {
|
||||||
let cheese = ~"roquefort";
|
let cheese = ~"roquefort";
|
||||||
let carrots = @~"crunchy";
|
let carrots = @~"crunchy";
|
||||||
|
|
||||||
let result: &'static fn(@~str, &fn(~str)) = (|tasties, macerate| {
|
let result: &'static fn(@~str, |~str|) = (|tasties, macerate| {
|
||||||
macerate((*tasties).clone());
|
macerate((*tasties).clone());
|
||||||
});
|
});
|
||||||
result(carrots, |food| {
|
result(carrots, |food| {
|
||||||
let mush = food + cheese;
|
let mush = food + cheese;
|
||||||
let cheese = cheese.clone();
|
let cheese = cheese.clone();
|
||||||
let f: &fn() = || {
|
let f: || = || {
|
||||||
let _chew = mush + cheese;
|
let _chew = mush + cheese;
|
||||||
fail!("so yummy")
|
fail!("so yummy")
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,7 +74,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pp<T>(cx: fake_ext_ctxt,
|
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 s = do io::with_str_writer |wr| {
|
||||||
let pp = pprust::rust_printer(wr, cx.parse_sess().interner);
|
let pp = pprust::rust_printer(wr, cx.parse_sess().interner);
|
||||||
f(pp, expr);
|
f(pp, expr);
|
||||||
|
|
|
@ -21,7 +21,7 @@ fn f1(a: &mut X, b: &mut int, c: int) -> int {
|
||||||
return r;
|
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() {
|
pub fn main() {
|
||||||
let mut a = X {x: 1};
|
let mut a = X {x: 1};
|
||||||
|
|
|
@ -13,17 +13,17 @@
|
||||||
// it.
|
// it.
|
||||||
|
|
||||||
trait iterable<A> {
|
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] {
|
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)
|
self.iter().advance(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A> iterable<A> for ~[A] {
|
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)
|
self.iter().advance(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
|
|
||||||
fn f<T>(x: ~[T]) -> T { return x[0]; }
|
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() {
|
pub fn main() {
|
||||||
assert_eq!(g(f), 1);
|
assert_eq!(g(f), 1);
|
||||||
let f1: &fn(~[~str]) -> ~str = f;
|
let f1: |~[~str]| -> ~str = f;
|
||||||
assert_eq!(f1(~[~"x", ~"y", ~"z"]), ~"x");
|
assert_eq!(f1(~[~"x", ~"y", ~"z"]), ~"x");
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
|
|
||||||
extern mod extra;
|
extern mod extra;
|
||||||
|
|
||||||
fn asSendfn( f : proc()->uint ) -> uint {
|
fn asSendfn(f: proc() -> uint) -> uint {
|
||||||
return f();
|
return f();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn asBlock( f : &fn()->uint ) -> uint {
|
fn asBlock(f: || -> uint) -> uint {
|
||||||
return f();
|
return f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub fn main() {
|
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 v = ~[-1.0, 0.0, 1.0, 2.0, 3.0];
|
||||||
let z = do do v.iter().fold(f) |x, _y| { x } { 22u };
|
let z = do do v.iter().fold(f) |x, _y| { x } { 22u };
|
||||||
assert_eq!(z, 22u);
|
assert_eq!(z, 22u);
|
||||||
|
|
|
@ -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 call_any(f: &fn() -> uint) -> uint {
|
fn call_any(f: || -> uint) -> uint {
|
||||||
return f();
|
return f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub fn main() {
|
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) );
|
as_buf(~"foo", |foo: ~str| -> () error!("{}", foo) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 force(f: &fn() -> int) -> int { return f(); }
|
fn force(f: || -> int) -> int { return f(); }
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
fn f() -> int { return 7; }
|
fn f() -> int { return 7; }
|
||||||
assert_eq!(force(f), 7);
|
assert_eq!(force(f), 7);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
// xfail-fast
|
// 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() {
|
pub fn main() {
|
||||||
let v = ~[1, 2, 3, 4, 5, 6, 7];
|
let v = ~[1, 2, 3, 4, 5, 6, 7];
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
// xfail-fast
|
// 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() {
|
pub fn main() {
|
||||||
let v = ~[1, 2, 3, 4, 5];
|
let v = ~[1, 2, 3, 4, 5];
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
use std::borrow;
|
use std::borrow;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
fn borrow(x: &int, f: &fn(x: &int)) {
|
fn borrow(x: &int, f: |x: &int|) {
|
||||||
f(x)
|
f(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ fn add_int(x: &mut Ints, v: int) {
|
||||||
util::swap(&mut values, &mut x.values);
|
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();
|
let l = x.values.len();
|
||||||
range(0u, l).advance(|i| f(&x.values[i]))
|
range(0u, l).advance(|i| f(&x.values[i]))
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
fn borrow(x: &int, f: &fn(x: &int)) {
|
fn borrow(x: &int, f: |x: &int|) {
|
||||||
let before = *x;
|
let before = *x;
|
||||||
f(x);
|
f(x);
|
||||||
let after = *x;
|
let after = *x;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
fn borrow(x: &int, f: &fn(x: &int)) {
|
fn borrow(x: &int, f: |x: &int|) {
|
||||||
let before = *x;
|
let before = *x;
|
||||||
f(x);
|
f(x);
|
||||||
let after = *x;
|
let after = *x;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
fn borrow(x: &int, f: &fn(x: &int)) {
|
fn borrow(x: &int, f: |x: &int|) {
|
||||||
let before = *x;
|
let before = *x;
|
||||||
f(x);
|
f(x);
|
||||||
let after = *x;
|
let after = *x;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
fn borrow(x: &int, f: &fn(x: &int)) {
|
fn borrow(x: &int, f: |x: &int|) {
|
||||||
let before = *x;
|
let before = *x;
|
||||||
f(x);
|
f(x);
|
||||||
let after = *x;
|
let after = *x;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
fn foo(i: int) -> int { i + 1 }
|
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() {
|
pub fn main() {
|
||||||
let f = {|i| foo(i)};
|
let f = {|i| foo(i)};
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// no-reformat
|
// no-reformat
|
||||||
// Testing various forms of `do` with empty arg lists
|
// Testing various forms of `do` with empty arg lists
|
||||||
|
|
||||||
fn f(_f: &fn() -> bool) -> bool {
|
fn f(_f: || -> bool) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
|
|
||||||
// Testing that we can drop the || in do exprs
|
// 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() {
|
pub fn main() {
|
||||||
do d { }
|
do d { }
|
||||||
|
|
|
@ -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()) {
|
fn f(_f: ||) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn g() {
|
fn g() {
|
||||||
|
|
|
@ -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: |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: |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: |int| -> int) -> int { f(10) }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
assert_eq!(do f() |i| { i }, 10);
|
assert_eq!(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: |int| -> int) -> int { f(10) }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
assert_eq!(do f |i| { i }, 10);
|
assert_eq!(do f |i| { i }, 10);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
fn bare() {}
|
fn bare() {}
|
||||||
|
|
||||||
fn likes_block(f: &fn()) { f() }
|
fn likes_block(f: ||) { f() }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
likes_block(bare);
|
likes_block(bare);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue