auto merge of #5291 : pcwalton/rust/drop-lint, r=pcwalton

r? @nikomatsakis
This commit is contained in:
bors 2013-03-11 10:15:58 -07:00
commit 2ebb67487c
257 changed files with 1138 additions and 1190 deletions

View File

@ -889,10 +889,10 @@ declared, in an angle-bracket-enclosed, comma-separated list following
the function name.
~~~~ {.xfail-test}
fn iter<T>(seq: &[T], f: fn(T)) {
fn iter<T>(seq: &[T], f: &fn(T)) {
for seq.each |elt| { f(elt); }
}
fn map<T, U>(seq: &[T], f: fn(T) -> U) -> ~[U] {
fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {
let mut acc = ~[];
for seq.each |elt| { acc.push(f(elt)); }
acc
@ -1198,7 +1198,7 @@ These appear after the trait name, using the same syntax used in [generic functi
trait Seq<T> {
fn len() -> uint;
fn elt_at(n: uint) -> T;
fn iter(fn(T));
fn iter(&fn(T));
}
~~~~
@ -2074,7 +2074,7 @@ and moving values from the environment into the lambda expression's captured env
An example of a lambda expression:
~~~~
fn ten_times(f: fn(int)) {
fn ten_times(f: &fn(int)) {
let mut i = 0;
while i < 10 {
f(i);
@ -2177,7 +2177,7 @@ If the `expr` is a [field expression](#field-expressions), it is parsed as thoug
In this example, both calls to `f` are equivalent:
~~~~
# fn f(f: fn(int)) { }
# fn f(f: &fn(int)) { }
# fn g(i: int) { }
f(|j| g(j));
@ -2755,7 +2755,7 @@ and the cast expression in `main`.
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
~~~~~~~
fn map<A: Copy, B: Copy>(f: fn(A) -> B, xs: &[A]) -> ~[B] {
fn map<A: Copy, B: Copy>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
if xs.len() == 0 { return ~[]; }
let first: B = f(xs[0]);
let rest: ~[B] = map(f, xs.slice(1, xs.len()));

View File

@ -681,45 +681,6 @@ the value of `North` is 0, `East` is 1, `South` is 2, and `West` is 3.
When an enum is C-like, you can apply the `as` cast operator to
convert it to its discriminator value as an `int`.
<a name="single_variant_enum"></a>
There is a special case for enums with a single variant, which are
sometimes called "newtype-style enums" (after Haskell's "newtype"
feature). These are used to define new types in such a way that the
new name is not just a synonym for an existing type, but its own
distinct type: `type` creates a structural synonym, while this form of
`enum` creates a nominal synonym. If you say:
~~~~
enum GizmoId = int;
~~~~
That is a shorthand for this:
~~~~
enum GizmoId { GizmoId(int) }
~~~~
You can extract the contents of such an enum type with the
dereference (`*`) unary operator:
~~~~
# enum GizmoId = int;
let my_gizmo_id: GizmoId = GizmoId(10);
let id_int: int = *my_gizmo_id;
~~~~
Types like this can be useful to differentiate between data that have
the same type but must be used in different ways.
~~~~
enum Inches = int;
enum Centimeters = int;
~~~~
The above definitions allow for a simple way for programs to avoid
confusing numbers that correspond to different units.
For enum types with multiple variants, destructuring is the only way to
get at their contents. All variant constructors can be used as
patterns, as in this definition of `area`:
@ -789,10 +750,10 @@ match mytup {
## Tuple structs
Rust also has _nominal tuples_, which behave like both structs and tuples,
except that nominal tuple types have names
(so `Foo(1, 2)` has a different type from `Bar(1, 2)`),
and nominal tuple types' _fields_ do not have names.
Rust also has _tuple structs_, which behave like both structs and tuples,
except that, unlike tuples, tuple structs have names (so `Foo(1, 2)` has a
different type from `Bar(1, 2)`), and tuple structs' _fields_ do not have
names.
For example:
~~~~
@ -803,6 +764,37 @@ match mytup {
}
~~~~
<a name="newtype"></a>
There is a special case for tuple structs with a single field, which are
sometimes called "newtypes" (after Haskell's "newtype" feature). These are
used to define new types in such a way that the new name is not just a
synonym for an existing type but is rather its own distinct type.
~~~~
struct GizmoId(int);
~~~~
For convenience, you can extract the contents of such a struct with the
dereference (`*`) unary operator:
~~~~
# struct GizmoId(int);
let my_gizmo_id: GizmoId = GizmoId(10);
let id_int: int = *my_gizmo_id;
~~~~
Types like this can be useful to differentiate between data that have
the same type but must be used in different ways.
~~~~
struct Inches(int);
struct Centimeters(int);
~~~~
The above definitions allow for a simple way for programs to avoid
confusing numbers that correspond to different units.
# Functions
We've already seen several function definitions. Like all other static
@ -1369,7 +1361,7 @@ the enclosing scope.
~~~~
# use println = core::io::println;
fn call_closure_with_ten(b: fn(int)) { b(10); }
fn call_closure_with_ten(b: &fn(int)) { b(10); }
let captured_var = 20;
let closure = |arg| println(fmt!("captured_var=%d, arg=%d", captured_var, arg));
@ -1455,7 +1447,7 @@ should almost always declare the type of that argument as `fn()`. That way,
callers may pass any kind of closure.
~~~~
fn call_twice(f: fn()) { f(); f(); }
fn call_twice(f: &fn()) { f(); f(); }
let closure = || { "I'm a closure, and it doesn't matter what type I am"; };
fn function() { "I'm a normal function"; }
call_twice(closure);
@ -1475,7 +1467,7 @@ Consider this function that iterates over a vector of
integers, passing in a pointer to each integer in the vector:
~~~~
fn each(v: &[int], op: fn(v: &int)) {
fn each(v: &[int], op: &fn(v: &int)) {
let mut n = 0;
while n < v.len() {
op(&v[n]);
@ -1496,7 +1488,7 @@ argument, we can write it in a way that has a pleasant, block-like
structure.
~~~~
# fn each(v: &[int], op: fn(v: &int)) { }
# fn each(v: &[int], op: &fn(v: &int)) { }
# fn do_some_work(i: &int) { }
each([1, 2, 3], |n| {
do_some_work(n);
@ -1507,7 +1499,7 @@ This is such a useful pattern that Rust has a special form of function
call that can be written more like a built-in control structure:
~~~~
# fn each(v: &[int], op: fn(v: &int)) { }
# fn each(v: &[int], op: &fn(v: &int)) { }
# fn do_some_work(i: &int) { }
do each([1, 2, 3]) |n| {
do_some_work(n);
@ -1554,7 +1546,7 @@ Consider again our `each` function, this time improved to
break early when the iteratee returns `false`:
~~~~
fn each(v: &[int], op: fn(v: &int) -> bool) {
fn each(v: &[int], op: &fn(v: &int) -> bool) {
let mut n = 0;
while n < v.len() {
if !op(&v[n]) {
@ -1778,7 +1770,7 @@ vector consisting of the result of applying `function` to each element
of `vector`:
~~~~
fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
let mut accumulator = ~[];
for vec::each(vector) |element| {
accumulator.push(function(element));
@ -1977,12 +1969,12 @@ types might look like the following:
~~~~
trait Seq<T> {
fn len(&self) -> uint;
fn iter(&self, b: fn(v: &T));
fn iter(&self, b: &fn(v: &T));
}
impl<T> Seq<T> for ~[T] {
fn len(&self) -> uint { vec::len(*self) }
fn iter(&self, b: fn(v: &T)) {
fn iter(&self, b: &fn(v: &T)) {
for vec::each(*self) |elt| { b(elt); }
}
}
@ -2294,7 +2286,7 @@ struct level. Note that fields and methods are _public_ by default.
pub mod farm {
# pub type Chicken = int;
# type Cow = int;
# enum Human = int;
# struct Human(int);
# impl Human { fn rest(&self) { } }
# pub fn make_me_a_farm() -> Farm { Farm { chickens: ~[], cows: ~[], farmer: Human(0) } }
pub struct Farm {

View File

@ -103,7 +103,7 @@ pub fn is_test_ignored(config: config, testfile: &Path) -> bool {
}
}
fn iter_header(testfile: &Path, it: fn(~str) -> bool) -> bool {
fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
let rdr = io::file_reader(testfile).get();
while !rdr.eof() {
let ln = rdr.read_line();

View File

@ -530,7 +530,7 @@ fn compose_and_run(config: config, testfile: &Path,
}
fn make_compile_args(config: config, props: TestProps, extras: ~[~str],
xform: fn(config, (&Path)) -> Path,
xform: &fn(config, (&Path)) -> Path,
testfile: &Path) -> ProcArgs {
let prog = config.rustc_path;
let mut args = ~[testfile.to_str(),

View File

@ -61,7 +61,7 @@ pub pure fn capacity<T>(v: @[const T]) -> uint {
*/
#[inline(always)]
pub pure fn build_sized<A>(size: uint,
builder: &fn(push: pure fn(v: A))) -> @[A] {
builder: &fn(push: &pure fn(v: A))) -> @[A] {
let mut vec: @[const A] = @[];
unsafe { raw::reserve(&mut vec, size); }
builder(|+x| unsafe { raw::push(&mut vec, x) });
@ -79,7 +79,7 @@ pub pure fn build_sized<A>(size: uint,
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build<A>(builder: &fn(push: pure fn(v: A))) -> @[A] {
pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> @[A] {
build_sized(4, builder)
}
@ -97,7 +97,7 @@ pub pure fn build<A>(builder: &fn(push: pure fn(v: A))) -> @[A] {
*/
#[inline(always)]
pub pure fn build_sized_opt<A>(size: Option<uint>,
builder: &fn(push: pure fn(v: A))) -> @[A] {
builder: &fn(push: &pure fn(v: A))) -> @[A] {
build_sized(size.get_or_default(4), builder)
}

View File

@ -67,7 +67,7 @@ pub pure fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
* Iterates over all truth values by passing them to `blk` in an unspecified
* order
*/
pub fn all_values(blk: fn(v: bool)) {
pub fn all_values(blk: &fn(v: bool)) {
blk(true);
blk(false);
}

View File

@ -54,7 +54,7 @@ pub impl<T> Cell<T> {
}
// Calls a closure with a reference to the value.
fn with_ref<R>(&self, op: fn(v: &T) -> R) -> R {
fn with_ref<R>(&self, op: &fn(v: &T) -> R) -> R {
let v = self.take();
let r = op(&v);
self.put_back(v);

View File

@ -124,7 +124,7 @@ struct AnnihilateStats {
n_bytes_freed: uint
}
unsafe fn each_live_alloc(f: fn(box: *mut BoxRepr, uniq: bool) -> bool) {
unsafe fn each_live_alloc(f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) {
use managed;
let task: *Task = transmute(rustrt::rust_get_task());

View File

@ -30,10 +30,10 @@ pub trait Map<K, V>: Mutable {
pure fn contains_key(&self, key: &K) -> bool;
/// Visit all keys
pure fn each_key(&self, f: fn(&K) -> bool);
pure fn each_key(&self, f: &fn(&K) -> bool);
/// Visit all values
pure fn each_value(&self, f: fn(&V) -> bool);
pure fn each_value(&self, f: &fn(&V) -> bool);
/// Return the value corresponding to the key in the map
pure fn find(&self, key: &K) -> Option<&self/V>;
@ -71,14 +71,14 @@ pub trait Set<T>: Mutable {
pure fn is_superset(&self, other: &Self) -> bool;
/// Visit the values representing the difference
pure fn difference(&self, other: &Self, f: fn(&T) -> bool);
pure fn difference(&self, other: &Self, f: &fn(&T) -> bool);
/// Visit the values representing the symmetric difference
pure fn symmetric_difference(&self, other: &Self, f: fn(&T) -> bool);
pure fn symmetric_difference(&self, other: &Self, f: &fn(&T) -> bool);
/// Visit the values representing the intersection
pure fn intersection(&self, other: &Self, f: fn(&T) -> bool);
pure fn intersection(&self, other: &Self, f: &fn(&T) -> bool);
/// Visit the values representing the union
pure fn union(&self, other: &Self, f: fn(&T) -> bool);
pure fn union(&self, other: &Self, f: &fn(&T) -> bool);
}

View File

@ -52,6 +52,7 @@ Implicitly, all crates behave as if they included the following prologue:
#[deny(non_camel_case_types)];
#[allow(deprecated_mutable_fields)];
#[deny(deprecated_self)];
#[allow(deprecated_drop)];
// On Linux, link to the runtime with -lrt.
#[cfg(target_os = "linux")]

View File

@ -399,7 +399,7 @@ pub impl<T> DList<T> {
}
/// Iterate over nodes.
pure fn each_node(@mut self, f: fn(@mut DListNode<T>) -> bool) {
pure fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) {
let mut link = self.peek_n();
while link.is_some() {
let nobe = link.get();
@ -507,7 +507,7 @@ impl<T> BaseIter<T> for @mut DList<T> {
* allow for e.g. breadth-first search with in-place enqueues), but
* removing the current node is forbidden.
*/
pure fn each(&self, f: fn(v: &T) -> bool) {
pure fn each(&self, f: &fn(v: &T) -> bool) {
let mut link = self.peek_n();
while option::is_some(&link) {
let nobe = option::get(link);

View File

@ -24,8 +24,8 @@ pub enum Either<T, U> {
}
#[inline(always)]
pub fn either<T, U, V>(f_left: fn(&T) -> V,
f_right: fn(&U) -> V, value: &Either<T, U>) -> V {
pub fn either<T, U, V>(f_left: &fn(&T) -> V,
f_right: &fn(&U) -> V, value: &Either<T, U>) -> V {
/*!
* Applies a function based on the given either value
*
@ -148,7 +148,7 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
pub impl<T, U> Either<T, U> {
#[inline(always)]
fn either<V>(&self, f_left: fn(&T) -> V, f_right: fn(&U) -> V) -> V {
fn either<V>(&self, f_left: &fn(&T) -> V, f_right: &fn(&U) -> V) -> V {
either(f_left, f_right, self)
}

View File

@ -86,7 +86,7 @@ pub mod linear {
#[inline(always)]
pure fn bucket_sequence(&self, hash: uint,
op: fn(uint) -> bool) -> uint {
op: &fn(uint) -> bool) -> uint {
let start_idx = self.to_bucket(hash);
let len_buckets = self.buckets.len();
let mut idx = start_idx;
@ -263,7 +263,7 @@ pub mod linear {
}
fn search(&self, hash: uint,
op: fn(x: &Option<Bucket<K, V>>) -> bool) {
op: &fn(x: &Option<Bucket<K, V>>) -> bool) {
let _ = self.bucket_sequence(hash, |i| op(&self.buckets[i]));
}
}
@ -272,7 +272,7 @@ pub mod linear {
BaseIter<(&self/K, &self/V)> for LinearMap<K, V>
{
/// Visit all key-value pairs
pure fn each(&self, blk: fn(&(&self/K, &self/V)) -> bool) {
pure fn each(&self, blk: &fn(&(&self/K, &self/V)) -> bool) {
for uint::range(0, self.buckets.len()) |i| {
let mut broke = false;
do self.buckets[i].map |bucket| {
@ -315,12 +315,12 @@ pub mod linear {
}
/// Visit all keys
pure fn each_key(&self, blk: fn(k: &K) -> bool) {
pure fn each_key(&self, blk: &fn(k: &K) -> bool) {
self.each(|&(k, _)| blk(k))
}
/// Visit all values
pure fn each_value(&self, blk: fn(v: &V) -> bool) {
pure fn each_value(&self, blk: &fn(v: &V) -> bool) {
self.each(|&(_, v)| blk(v))
}
@ -428,7 +428,7 @@ pub mod linear {
/// Return the value corresponding to the key in the map, or create,
/// insert, and return a new value if it doesn't exist.
fn find_or_insert_with(&mut self, k: K, f: fn(&K) -> V) -> &self/V {
fn find_or_insert_with(&mut self, k: K, f: &fn(&K) -> V) -> &self/V {
if self.size >= self.resize_at {
// n.b.: We could also do this after searching, so
// that we do not resize if this call to insert is
@ -457,7 +457,7 @@ pub mod linear {
}
}
fn consume(&mut self, f: fn(K, V)) {
fn consume(&mut self, f: &fn(K, V)) {
let mut buckets = ~[];
self.buckets <-> buckets;
self.size = 0;
@ -526,7 +526,7 @@ pub mod linear {
impl<T:Hash + IterBytes + Eq> BaseIter<T> for LinearSet<T> {
/// Visit all values in order
pure fn each(&self, f: fn(&T) -> bool) { self.map.each_key(f) }
pure fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
@ -583,7 +583,7 @@ pub mod linear {
}
/// Visit the values representing the difference
pure fn difference(&self, other: &LinearSet<T>, f: fn(&T) -> bool) {
pure fn difference(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
for self.each |v| {
if !other.contains(v) {
if !f(v) { return }
@ -593,13 +593,15 @@ pub mod linear {
/// Visit the values representing the symmetric difference
pure fn symmetric_difference(&self, other: &LinearSet<T>,
f: fn(&T) -> bool) {
f: &fn(&T) -> bool) {
self.difference(other, f);
other.difference(self, f);
}
/// Visit the values representing the intersection
pure fn intersection(&self, other: &LinearSet<T>, f: fn(&T) -> bool) {
pure fn intersection(&self,
other: &LinearSet<T>,
f: &fn(&T) -> bool) {
for self.each |v| {
if other.contains(v) {
if !f(v) { return }
@ -608,7 +610,7 @@ pub mod linear {
}
/// Visit the values representing the union
pure fn union(&self, other: &LinearSet<T>, f: fn(&T) -> bool) {
pure fn union(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
for self.each |v| {
if !f(v) { return }
}

View File

@ -118,13 +118,13 @@ pub trait ReaderUtil {
fn read_whole_stream(&self) -> ~[u8];
/// Iterate over every byte until the iterator breaks or EOF.
fn each_byte(&self, it: fn(int) -> bool);
fn each_byte(&self, it: &fn(int) -> bool);
/// Iterate over every char until the iterator breaks or EOF.
fn each_char(&self, it: fn(char) -> bool);
fn each_char(&self, it: &fn(char) -> bool);
/// Iterate over every line until the iterator breaks or EOF.
fn each_line(&self, it: fn(&str) -> bool);
fn each_line(&self, it: &fn(&str) -> bool);
/// Read n (between 1 and 8) little-endian unsigned integer bytes.
fn read_le_uint_n(&self, nbytes: uint) -> u64;
@ -315,19 +315,19 @@ impl<T:Reader> ReaderUtil for T {
bytes
}
fn each_byte(&self, it: fn(int) -> bool) {
fn each_byte(&self, it: &fn(int) -> bool) {
while !self.eof() {
if !it(self.read_byte()) { break; }
}
}
fn each_char(&self, it: fn(char) -> bool) {
fn each_char(&self, it: &fn(char) -> bool) {
while !self.eof() {
if !it(self.read_char()) { break; }
}
}
fn each_line(&self, it: fn(s: &str) -> bool) {
fn each_line(&self, it: &fn(s: &str) -> bool) {
while !self.eof() {
if !it(self.read_line()) { break; }
}
@ -618,11 +618,11 @@ impl Reader for BytesReader/&self {
fn tell(&self) -> uint { self.pos }
}
pub pure fn with_bytes_reader<t>(bytes: &[u8], f: fn(@Reader) -> t) -> t {
pub pure fn with_bytes_reader<t>(bytes: &[u8], f: &fn(@Reader) -> t) -> t {
f(@BytesReader { bytes: bytes, pos: 0u } as @Reader)
}
pub pure fn with_str_reader<T>(s: &str, f: fn(@Reader) -> T) -> T {
pub pure fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T {
str::byte_slice(s, |bytes| with_bytes_reader(bytes, f))
}
@ -819,7 +819,7 @@ pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
}
pub fn u64_to_le_bytes<T>(n: u64, size: uint,
f: fn(v: &[u8]) -> T) -> T {
f: &fn(v: &[u8]) -> T) -> T {
fail_unless!(size <= 8u);
match size {
1u => f(&[n as u8]),
@ -851,7 +851,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint,
}
pub fn u64_to_be_bytes<T>(n: u64, size: uint,
f: fn(v: &[u8]) -> T) -> T {
f: &fn(v: &[u8]) -> T) -> T {
fail_unless!(size <= 8u);
match size {
1u => f(&[n as u8]),
@ -1142,14 +1142,14 @@ pub pure fn BytesWriter() -> BytesWriter {
BytesWriter { bytes: ~[], mut pos: 0u }
}
pub pure fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
pub pure fn with_bytes_writer(f: &fn(Writer)) -> ~[u8] {
let wr = @BytesWriter();
f(wr as Writer);
let @BytesWriter{bytes, _} = wr;
return bytes;
}
pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
pub pure fn with_str_writer(f: &fn(Writer)) -> ~str {
let mut v = with_bytes_writer(f);
// FIXME (#3758): This should not be needed.
@ -1251,7 +1251,7 @@ pub mod fsync {
// FIXME (#2004) find better way to create resources within lifetime of
// outer res
pub fn FILE_res_sync(file: &FILERes, opt_level: Option<Level>,
blk: fn(v: Res<*libc::FILE>)) {
blk: &fn(v: Res<*libc::FILE>)) {
unsafe {
blk(Res(Arg {
val: file.f, opt_level: opt_level,
@ -1266,7 +1266,7 @@ pub mod fsync {
// fsync fd after executing blk
pub fn fd_res_sync(fd: &FdRes, opt_level: Option<Level>,
blk: fn(v: Res<fd_t>)) {
blk: &fn(v: Res<fd_t>)) {
blk(Res(Arg {
val: fd.fd, opt_level: opt_level,
fsync_fn: |fd, l| os::fsync_fd(fd, l) as int
@ -1278,7 +1278,7 @@ pub mod fsync {
// Call o.fsync after executing blk
pub fn obj_sync(o: FSyncable, opt_level: Option<Level>,
blk: fn(v: Res<FSyncable>)) {
blk: &fn(v: Res<FSyncable>)) {
blk(Res(Arg {
val: o, opt_level: opt_level,
fsync_fn: |o, l| o.fsync(l)

View File

@ -23,22 +23,22 @@ use vec;
pub type InitOp<T> = &self/fn(uint) -> T;
pub trait BaseIter<A> {
pure fn each(&self, blk: fn(v: &A) -> bool);
pure fn each(&self, blk: &fn(v: &A) -> bool);
pure fn size_hint(&self) -> Option<uint>;
}
pub trait ReverseIter<A>: BaseIter<A> {
pure fn each_reverse(&self, blk: fn(&A) -> bool);
pure fn each_reverse(&self, blk: &fn(&A) -> bool);
}
pub trait ExtendedIter<A> {
pure fn eachi(&self, blk: fn(uint, v: &A) -> bool);
pure fn all(&self, blk: fn(&A) -> bool) -> bool;
pure fn any(&self, blk: fn(&A) -> bool) -> bool;
pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B;
pure fn position(&self, f: fn(&A) -> bool) -> Option<uint>;
pure fn map_to_vec<B>(&self, op: fn(&A) -> B) -> ~[B];
pure fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: fn(&A) -> IB)
pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool);
pure fn all(&self, blk: &fn(&A) -> bool) -> bool;
pure fn any(&self, blk: &fn(&A) -> bool) -> bool;
pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B;
pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint>;
pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B];
pure fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B];
}
@ -48,13 +48,13 @@ pub trait EqIter<A:Eq> {
}
pub trait Times {
pure fn times(&self, it: fn() -> bool);
pure fn times(&self, it: &fn() -> bool);
}
pub trait CopyableIter<A:Copy> {
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A];
pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A];
pure fn to_vec(&self) -> ~[A];
pure fn find(&self, p: fn(&A) -> bool) -> Option<A>;
pure fn find(&self, p: &fn(&A) -> bool) -> Option<A>;
}
pub trait CopyableOrderedIter<A:Copy + Ord> {
@ -86,12 +86,12 @@ pub trait Buildable<A> {
* onto the sequence being constructed.
*/
static pure fn build_sized(size: uint,
builder: fn(push: pure fn(A))) -> Self;
builder: &fn(push: &pure fn(A))) -> Self;
}
#[inline(always)]
pub pure fn eachi<A,IA:BaseIter<A>>(self: &IA,
blk: fn(uint, &A) -> bool) {
blk: &fn(uint, &A) -> bool) {
let mut i = 0;
for self.each |a| {
if !blk(i, a) { break; }
@ -101,7 +101,7 @@ pub pure fn eachi<A,IA:BaseIter<A>>(self: &IA,
#[inline(always)]
pub pure fn all<A,IA:BaseIter<A>>(self: &IA,
blk: fn(&A) -> bool) -> bool {
blk: &fn(&A) -> bool) -> bool {
for self.each |a| {
if !blk(a) { return false; }
}
@ -110,7 +110,7 @@ pub pure fn all<A,IA:BaseIter<A>>(self: &IA,
#[inline(always)]
pub pure fn any<A,IA:BaseIter<A>>(self: &IA,
blk: fn(&A) -> bool) -> bool {
blk: &fn(&A) -> bool) -> bool {
for self.each |a| {
if blk(a) { return true; }
}
@ -119,7 +119,7 @@ pub pure fn any<A,IA:BaseIter<A>>(self: &IA,
#[inline(always)]
pub pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(
self: &IA, prd: fn(&A) -> bool) -> ~[A] {
self: &IA, prd: &fn(&A) -> bool) -> ~[A] {
do vec::build_sized_opt(self.size_hint()) |push| {
for self.each |a| {
if prd(a) { push(*a); }
@ -129,7 +129,7 @@ pub pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(
#[inline(always)]
pub pure fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA,
op: fn(&A) -> B)
op: &fn(&A) -> B)
-> ~[B] {
do vec::build_sized_opt(self.size_hint()) |push| {
for self.each |a| {
@ -140,7 +140,7 @@ pub pure fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA,
#[inline(always)]
pub pure fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(
self: &IA, op: fn(&A) -> IB) -> ~[B] {
self: &IA, op: &fn(&A) -> IB) -> ~[B] {
do vec::build |push| {
for self.each |a| {
for op(a).each |&b| {
@ -152,7 +152,7 @@ pub pure fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(
#[inline(always)]
pub pure fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B,
blk: fn(&B, &A) -> B)
blk: &fn(&B, &A) -> B)
-> B {
let mut b = b0;
for self.each |a| {
@ -186,7 +186,7 @@ pub pure fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
}
#[inline(always)]
pub pure fn position<A,IA:BaseIter<A>>(self: &IA, f: fn(&A) -> bool)
pub pure fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
-> Option<uint>
{
let mut i = 0;
@ -202,7 +202,7 @@ pub pure fn position<A,IA:BaseIter<A>>(self: &IA, f: fn(&A) -> bool)
// it would have to be implemented with foldr, which is too inefficient.
#[inline(always)]
pub pure fn repeat(times: uint, blk: fn() -> bool) {
pub pure fn repeat(times: uint, blk: &fn() -> bool) {
let mut i = 0;
while i < times {
if !blk() { break }
@ -242,7 +242,7 @@ pub pure fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
#[inline(always)]
pub pure fn find<A:Copy,IA:BaseIter<A>>(self: &IA,
f: fn(&A) -> bool) -> Option<A> {
f: &fn(&A) -> bool) -> Option<A> {
for self.each |i| {
if f(i) { return Some(*i) }
}
@ -262,7 +262,7 @@ pub pure fn find<A:Copy,IA:BaseIter<A>>(self: &IA,
* onto the sequence being constructed.
*/
#[inline(always)]
pub pure fn build<A,B: Buildable<A>>(builder: fn(push: pure fn(A)))
pub pure fn build<A,B: Buildable<A>>(builder: &fn(push: &pure fn(A)))
-> B {
Buildable::build_sized(4, builder)
}
@ -283,7 +283,7 @@ pub pure fn build<A,B: Buildable<A>>(builder: fn(push: pure fn(A)))
#[inline(always)]
pub pure fn build_sized_opt<A,B: Buildable<A>>(
size: Option<uint>,
builder: fn(push: pure fn(A))) -> B {
builder: &fn(push: &pure fn(A))) -> B {
Buildable::build_sized(size.get_or_default(4), builder)
}
@ -292,7 +292,7 @@ pub pure fn build_sized_opt<A,B: Buildable<A>>(
/// Applies a function to each element of an iterable and returns the results.
#[inline(always)]
pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: fn(&T) -> U)
pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
-> BU {
do build_sized_opt(v.size_hint()) |push| {
for v.each() |elem| {

View File

@ -100,7 +100,7 @@ pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
*/
#[inline(always)]
/// Iterate over the range [`start`,`start`+`step`..`stop`)
pub pure fn range_step(start: T, stop: T, step: T, it: fn(T) -> bool) {
pub pure fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
let mut i = start;
if step == 0 {
fail!(~"range_step called with step == 0");
@ -119,13 +119,13 @@ pub pure fn range_step(start: T, stop: T, step: T, it: fn(T) -> bool) {
#[inline(always)]
/// Iterate over the range [`lo`..`hi`)
pub pure fn range(lo: T, hi: T, it: fn(T) -> bool) {
pub pure fn range(lo: T, hi: T, it: &fn(T) -> bool) {
range_step(lo, hi, 1 as T, it);
}
#[inline(always)]
/// Iterate over the range [`hi`..`lo`)
pub pure fn range_rev(hi: T, lo: T, it: fn(T) -> bool) {
pub pure fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
range_step(hi, lo, -1 as T, it);
}
@ -237,7 +237,7 @@ impl FromStrRadix for T {
/// Convert to a string as a byte slice in a given base.
#[inline(always)]
pub pure fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
pub pure fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false,
strconv::SignNeg, strconv::DigAll);
f(buf)

View File

@ -67,7 +67,10 @@ pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
* Iterate over the range [`start`,`start`+`step`..`stop`)
*
*/
pub pure fn range_step(start: T, stop: T, step: T_SIGNED, it: fn(T) -> bool) {
pub pure fn range_step(start: T,
stop: T,
step: T_SIGNED,
it: &fn(T) -> bool) {
let mut i = start;
if step == 0 {
fail!(~"range_step called with step == 0");
@ -88,13 +91,13 @@ pub pure fn range_step(start: T, stop: T, step: T_SIGNED, it: fn(T) -> bool) {
#[inline(always)]
/// Iterate over the range [`lo`..`hi`)
pub pure fn range(lo: T, hi: T, it: fn(T) -> bool) {
pub pure fn range(lo: T, hi: T, it: &fn(T) -> bool) {
range_step(lo, hi, 1 as T_SIGNED, it);
}
#[inline(always)]
/// Iterate over the range [`hi`..`lo`)
pub pure fn range_rev(hi: T, lo: T, it: fn(T) -> bool) {
pub pure fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
range_step(hi, lo, -1 as T_SIGNED, it);
}
@ -200,7 +203,7 @@ impl FromStrRadix for T {
/// Convert to a string as a byte slice in a given base.
#[inline(always)]
pub pure fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
pub pure fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false,
strconv::SignNeg, strconv::DigAll);
f(buf)

View File

@ -101,7 +101,7 @@ pub mod inst {
* `true` If execution proceeded correctly, `false` if it was interrupted,
* that is if `it` returned `false` at any point.
*/
pub pure fn iterate(lo: uint, hi: uint, it: fn(uint) -> bool) -> bool {
pub pure fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
let mut i = lo;
while i < hi {
if (!it(i)) { return false; }
@ -122,7 +122,7 @@ pub mod inst {
* use with integer literals of inferred integer-type as
* the self-value (eg. `for 100.times { ... }`).
*/
pure fn times(&self, it: fn() -> bool) {
pure fn times(&self, it: &fn() -> bool) {
let mut i = *self;
while i > 0 {
if !it() { break }

View File

@ -131,7 +131,7 @@ pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
}
#[inline(always)]
pub pure fn map<T, U>(opt: &r/Option<T>, f: fn(x: &r/T) -> U) -> Option<U> {
pub pure fn map<T, U>(opt: &r/Option<T>, f: &fn(x: &r/T) -> U) -> Option<U> {
//! Maps a `some` value by reference from one type to another
match *opt { Some(ref x) => Some(f(x)), None => None }
@ -139,7 +139,7 @@ pub pure fn map<T, U>(opt: &r/Option<T>, f: fn(x: &r/T) -> U) -> Option<U> {
#[inline(always)]
pub pure fn map_consume<T, U>(opt: Option<T>,
f: fn(v: T) -> U) -> Option<U> {
f: &fn(v: T) -> U) -> Option<U> {
/*!
* As `map`, but consumes the option and gives `f` ownership to avoid
* copying.
@ -149,7 +149,7 @@ pub pure fn map_consume<T, U>(opt: Option<T>,
#[inline(always)]
pub pure fn chain<T, U>(opt: Option<T>,
f: fn(t: T) -> Option<U>) -> Option<U> {
f: &fn(t: T) -> Option<U>) -> Option<U> {
/*!
* Update an optional value by optionally running its content through a
* function that returns an option.
@ -163,7 +163,7 @@ pub pure fn chain<T, U>(opt: Option<T>,
#[inline(always)]
pub pure fn chain_ref<T, U>(opt: &Option<T>,
f: fn(x: &T) -> Option<U>) -> Option<U> {
f: &fn(x: &T) -> Option<U>) -> Option<U> {
/*!
* Update an optional value by optionally running its content by reference
* through a function that returns an option.
@ -184,7 +184,7 @@ pub pure fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> {
}
#[inline(always)]
pub pure fn while_some<T>(x: Option<T>, blk: fn(v: T) -> Option<T>) {
pub pure fn while_some<T>(x: Option<T>, blk: &fn(v: T) -> Option<T>) {
//! Applies a function zero or more times until the result is none.
let mut opt = x;
@ -223,7 +223,7 @@ pub pure fn get_or_default<T:Copy>(opt: Option<T>, def: T) -> T {
#[inline(always)]
pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U,
f: fn(&r/T) -> U) -> U {
f: &fn(&r/T) -> U) -> U {
//! Applies a function to the contained value or returns a default
match *opt { None => def, Some(ref t) => f(t) }
@ -279,7 +279,7 @@ pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
impl<T> BaseIter<T> for Option<T> {
/// Performs an operation on the contained value by reference
#[inline(always)]
pure fn each(&self, f: fn(x: &self/T) -> bool) {
pure fn each(&self, f: &fn(x: &self/T) -> bool) {
match *self { None => (), Some(ref t) => { f(t); } }
}
@ -303,43 +303,43 @@ pub impl<T> Option<T> {
* through a function that returns an option.
*/
#[inline(always)]
pure fn chain_ref<U>(&self, f: fn(x: &T) -> Option<U>) -> Option<U> {
pure fn chain_ref<U>(&self, f: &fn(x: &T) -> Option<U>) -> Option<U> {
chain_ref(self, f)
}
/// Maps a `some` value from one type to another by reference
#[inline(always)]
pure fn map<U>(&self, f: fn(&self/T) -> U) -> Option<U> { map(self, f) }
pure fn map<U>(&self, f: &fn(&self/T) -> U) -> Option<U> { map(self, f) }
/// As `map`, but consumes the option and gives `f` ownership to avoid
/// copying.
#[inline(always)]
pure fn map_consume<U>(self, f: fn(v: T) -> U) -> Option<U> {
pure fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> {
map_consume(self, f)
}
/// Applies a function to the contained value or returns a default
#[inline(always)]
pure fn map_default<U>(&self, def: U, f: fn(&self/T) -> U) -> U {
pure fn map_default<U>(&self, def: U, f: &fn(&self/T) -> U) -> U {
map_default(self, def, f)
}
/// As `map_default`, but consumes the option and gives `f`
/// ownership to avoid copying.
#[inline(always)]
pure fn map_consume_default<U>(self, def: U, f: fn(v: T) -> U) -> U {
pure fn map_consume_default<U>(self, def: U, f: &fn(v: T) -> U) -> U {
match self { None => def, Some(v) => f(v) }
}
/// Apply a function to the contained value or do nothing
fn mutate(&mut self, f: fn(T) -> T) {
fn mutate(&mut self, f: &fn(T) -> T) {
if self.is_some() {
*self = Some(f(self.swap_unwrap()));
}
}
/// Apply a function to the contained value or set it to a default
fn mutate_default(&mut self, def: T, f: fn(T) -> T) {
fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
if self.is_some() {
*self = Some(f(self.swap_unwrap()));
} else {
@ -420,7 +420,7 @@ pub impl<T:Copy> Option<T> {
/// Applies a function zero or more times until the result is none.
#[inline(always)]
pure fn while_some(self, blk: fn(v: T) -> Option<T>) {
pure fn while_some(self, blk: &fn(v: T) -> Option<T>) {
while_some(self, blk)
}
}

View File

@ -75,11 +75,11 @@ pub fn getcwd() -> Path {
}
}
pub fn as_c_charp<T>(s: &str, f: fn(*c_char) -> T) -> T {
pub fn as_c_charp<T>(s: &str, f: &fn(*c_char) -> T) -> T {
str::as_c_str(s, |b| f(b as *c_char))
}
pub fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
pub fn fill_charp_buf(f: &fn(*mut c_char, size_t) -> bool)
-> Option<~str> {
let mut buf = vec::from_elem(TMPBUF_SZ, 0u8 as c_char);
do vec::as_mut_buf(buf) |b, sz| {
@ -103,7 +103,7 @@ pub mod win32 {
use os::TMPBUF_SZ;
use libc::types::os::arch::extra::DWORD;
pub fn fill_utf16_buf_and_decode(f: fn(*mut u16, DWORD) -> DWORD)
pub fn fill_utf16_buf_and_decode(f: &fn(*mut u16, DWORD) -> DWORD)
-> Option<~str> {
unsafe {
let mut n = TMPBUF_SZ as DWORD;
@ -133,7 +133,7 @@ pub mod win32 {
}
}
pub fn as_utf16_p<T>(s: &str, f: fn(*u16) -> T) -> T {
pub fn as_utf16_p<T>(s: &str, f: &fn(*u16) -> T) -> T {
let mut t = str::to_utf16(s);
// Null terminate before passing on.
t += ~[0u16];
@ -518,11 +518,11 @@ pub fn tmpdir() -> Path {
}
}
/// Recursively walk a directory structure
pub fn walk_dir(p: &Path, f: fn(&Path) -> bool) {
pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) {
walk_dir_(p, f);
fn walk_dir_(p: &Path, f: fn(&Path) -> bool) -> bool {
fn walk_dir_(p: &Path, f: &fn(&Path) -> bool) -> bool {
let mut keepgoing = true;
do list_dir(p).each |q| {
let path = &p.push(*q);

View File

@ -246,7 +246,7 @@ pub fn packet<T>() -> *Packet<T> {
#[doc(hidden)]
pub fn entangle_buffer<T:Owned,Tstart:Owned>(
buffer: ~Buffer<T>,
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
init: &fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
{
let p = init(unsafe { reinterpret_cast(&buffer) }, &buffer.data);

View File

@ -82,7 +82,7 @@ pub unsafe fn buf_len<T>(buf: **T) -> uint {
/// Return the first offset `i` such that `f(buf[i]) == true`.
#[inline(always)]
pub unsafe fn position<T>(buf: *T, f: fn(&T) -> bool) -> uint {
pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
let mut i = 0;
loop {
if f(&(*offset(buf, i))) { return i; }

View File

@ -26,7 +26,7 @@ use vec;
* then build a MovePtrAdaptor wrapped around your struct.
*/
pub trait MovePtr {
fn move_ptr(&self, adjustment: fn(*c_void) -> *c_void);
fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void);
fn push_ptr(&self);
fn pop_ptr(&self);
}

View File

@ -159,7 +159,7 @@ pub fn ReprVisitor(ptr: *c_void, writer: @Writer) -> ReprVisitor {
impl MovePtr for ReprVisitor {
#[inline(always)]
fn move_ptr(&self, adjustment: fn(*c_void) -> *c_void) {
fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void) {
self.ptr = adjustment(self.ptr);
}
fn push_ptr(&self) {
@ -175,7 +175,7 @@ pub impl ReprVisitor {
// Various helpers for the TyVisitor impl
#[inline(always)]
fn get<T>(&self, f: fn(&T)) -> bool {
fn get<T>(&self, f: &fn(&T)) -> bool {
unsafe {
f(transmute::<*c_void,&T>(copy self.ptr));
}

View File

@ -122,7 +122,7 @@ pub pure fn to_either<T:Copy,U:Copy>(res: &Result<U, T>)
* }
*/
#[inline(always)]
pub pure fn chain<T, U, V>(res: Result<T, V>, op: fn(T)
pub pure fn chain<T, U, V>(res: Result<T, V>, op: &fn(T)
-> Result<U, V>) -> Result<U, V> {
match res {
Ok(t) => op(t),
@ -141,7 +141,7 @@ pub pure fn chain<T, U, V>(res: Result<T, V>, op: fn(T)
#[inline(always)]
pub pure fn chain_err<T, U, V>(
res: Result<T, V>,
op: fn(t: V) -> Result<T, U>)
op: &fn(t: V) -> Result<T, U>)
-> Result<T, U> {
match res {
Ok(t) => Ok(t),
@ -164,7 +164,7 @@ pub pure fn chain_err<T, U, V>(
* }
*/
#[inline(always)]
pub pure fn iter<T, E>(res: &Result<T, E>, f: fn(&T)) {
pub pure fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
match *res {
Ok(ref t) => f(t),
Err(_) => ()
@ -180,7 +180,7 @@ pub pure fn iter<T, E>(res: &Result<T, E>, f: fn(&T)) {
* handling an error.
*/
#[inline(always)]
pub pure fn iter_err<T, E>(res: &Result<T, E>, f: fn(&E)) {
pub pure fn iter_err<T, E>(res: &Result<T, E>, f: &fn(&E)) {
match *res {
Ok(_) => (),
Err(ref e) => f(e)
@ -202,7 +202,7 @@ pub pure fn iter_err<T, E>(res: &Result<T, E>, f: fn(&E)) {
* }
*/
#[inline(always)]
pub pure fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: fn(&T) -> U)
pub pure fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: &fn(&T) -> U)
-> Result<U, E> {
match *res {
Ok(ref t) => Ok(op(t)),
@ -219,7 +219,7 @@ pub pure fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: fn(&T) -> U)
* successful result while handling an error.
*/
#[inline(always)]
pub pure fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: fn(&E) -> F)
pub pure fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F)
-> Result<T, F> {
match *res {
Ok(copy t) => Ok(t),
@ -238,10 +238,10 @@ pub impl<T, E> Result<T, E> {
pure fn is_err(&self) -> bool { is_err(self) }
#[inline(always)]
pure fn iter(&self, f: fn(&T)) { iter(self, f) }
pure fn iter(&self, f: &fn(&T)) { iter(self, f) }
#[inline(always)]
pure fn iter_err(&self, f: fn(&E)) { iter_err(self, f) }
pure fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) }
#[inline(always)]
pure fn unwrap(self) -> T { unwrap(self) }
@ -250,12 +250,12 @@ pub impl<T, E> Result<T, E> {
pure fn unwrap_err(self) -> E { unwrap_err(self) }
#[inline(always)]
pure fn chain<U>(self, op: fn(T) -> Result<U,E>) -> Result<U,E> {
pure fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
chain(self, op)
}
#[inline(always)]
pure fn chain_err<F>(self, op: fn(E) -> Result<T,F>) -> Result<T,F> {
pure fn chain_err<F>(self, op: &fn(E) -> Result<T,F>) -> Result<T,F> {
chain_err(self, op)
}
}
@ -265,7 +265,7 @@ pub impl<T:Copy,E> Result<T, E> {
pure fn get(&self) -> T { get(self) }
#[inline(always)]
pure fn map_err<F:Copy>(&self, op: fn(&E) -> F) -> Result<T,F> {
pure fn map_err<F:Copy>(&self, op: &fn(&E) -> F) -> Result<T,F> {
map_err(self, op)
}
}
@ -275,7 +275,7 @@ pub impl<T, E: Copy> Result<T, E> {
pure fn get_err(&self) -> E { get_err(self) }
#[inline(always)]
pure fn map<U:Copy>(&self, op: fn(&T) -> U) -> Result<U,E> {
pure fn map<U:Copy>(&self, op: &fn(&T) -> U) -> Result<U,E> {
map(self, op)
}
}
@ -299,7 +299,7 @@ pub impl<T, E: Copy> Result<T, E> {
*/
#[inline(always)]
pub fn map_vec<T,U:Copy,V:Copy>(
ts: &[T], op: fn(&T) -> Result<V,U>) -> Result<~[V],U> {
ts: &[T], op: &fn(&T) -> Result<V,U>) -> Result<~[V],U> {
let mut vs: ~[V] = vec::with_capacity(vec::len(ts));
for vec::each(ts) |t| {
@ -313,7 +313,7 @@ pub fn map_vec<T,U:Copy,V:Copy>(
#[inline(always)]
pub fn map_opt<T,U:Copy,V:Copy>(
o_t: &Option<T>, op: fn(&T) -> Result<V,U>) -> Result<Option<V>,U> {
o_t: &Option<T>, op: &fn(&T) -> Result<V,U>) -> Result<Option<V>,U> {
match *o_t {
None => Ok(None),
@ -335,7 +335,7 @@ pub fn map_opt<T,U:Copy,V:Copy>(
*/
#[inline(always)]
pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
op: fn(&S,&T) -> Result<V,U>) -> Result<~[V],U> {
op: &fn(&S,&T) -> Result<V,U>) -> Result<~[V],U> {
fail_unless!(vec::same_length(ss, ts));
let n = vec::len(ts);
@ -358,7 +358,7 @@ pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
*/
#[inline(always)]
pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
op: fn(&S,&T) -> Result<(),U>) -> Result<(),U> {
op: &fn(&S,&T) -> Result<(),U>) -> Result<(),U> {
fail_unless!(vec::same_length(ss, ts));
let n = vec::len(ts);

View File

@ -102,7 +102,7 @@ pub fn spawn_process(prog: &str, args: &[~str],
}
fn with_argv<T>(prog: &str, args: &[~str],
cb: fn(**libc::c_char) -> T) -> T {
cb: &fn(**libc::c_char) -> T) -> T {
let mut argptrs = str::as_c_str(prog, |b| ~[b]);
let mut tmps = ~[];
for vec::each(args) |arg| {
@ -116,7 +116,7 @@ fn with_argv<T>(prog: &str, args: &[~str],
#[cfg(unix)]
fn with_envp<T>(env: &Option<~[(~str,~str)]>,
cb: fn(*c_void) -> T) -> T {
cb: &fn(*c_void) -> T) -> T {
// On posixy systems we can pass a char** for envp, which is
// a null-terminated array of "k=v\n" strings.
match *env {
@ -141,7 +141,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
#[cfg(windows)]
fn with_envp<T>(env: &Option<~[(~str,~str)]>,
cb: fn(*c_void) -> T) -> T {
cb: &fn(*c_void) -> T) -> T {
// On win32 we pass an "environment block" which is not a char**, but
// rather a concatenation of null-terminated k=v\0 sequences, with a final
// \0 to terminate.
@ -165,7 +165,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
}
fn with_dirp<T>(d: &Option<~str>,
cb: fn(*libc::c_char) -> T) -> T {
cb: &fn(*libc::c_char) -> T) -> T {
match *d {
Some(ref dir) => str::as_c_str(*dir, cb),
None => cb(ptr::null())

View File

@ -24,7 +24,7 @@ pub fn Frame(fp: *Word) -> Frame {
}
}
pub fn walk_stack(visit: fn(Frame) -> bool) {
pub fn walk_stack(visit: &fn(Frame) -> bool) {
debug!("beginning stack walk");
@ -80,7 +80,7 @@ fn breakpoint() {
}
}
fn frame_address(f: fn(++x: *u8)) {
fn frame_address(f: &fn(++x: *u8)) {
unsafe {
rusti::frame_address(f)
}

View File

@ -382,7 +382,7 @@ pub pure fn to_bytes(s: &str) -> ~[u8] {
/// Work with the string as a byte slice, not including trailing null.
#[inline(always)]
pub pure fn byte_slice<T>(s: &str, f: fn(v: &[u8]) -> T) -> T {
pub pure fn byte_slice<T>(s: &str, f: &fn(v: &[u8]) -> T) -> T {
do as_buf(s) |p,n| {
unsafe { vec::raw::buf_as_slice(p, n-1u, f) }
}
@ -483,7 +483,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool)
/// Splits a string into substrings using a character function
pub pure fn split(s: &str, sepfn: fn(char) -> bool) -> ~[~str] {
pub pure fn split(s: &str, sepfn: &fn(char) -> bool) -> ~[~str] {
split_inner(s, sepfn, len(s), true)
}
@ -491,16 +491,19 @@ pub pure fn split(s: &str, sepfn: fn(char) -> bool) -> ~[~str] {
* Splits a string into substrings using a character function, cutting at
* most `count` times.
*/
pub pure fn splitn(s: &str, sepfn: fn(char) -> bool, count: uint) -> ~[~str] {
pub pure fn splitn(s: &str,
sepfn: &fn(char) -> bool,
count: uint)
-> ~[~str] {
split_inner(s, sepfn, count, true)
}
/// Like `split`, but omits empty strings from the returned vector
pub pure fn split_nonempty(s: &str, sepfn: fn(char) -> bool) -> ~[~str] {
pub pure fn split_nonempty(s: &str, sepfn: &fn(char) -> bool) -> ~[~str] {
split_inner(s, sepfn, len(s), false)
}
pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
pure fn split_inner(s: &str, sepfn: &fn(cc: char) -> bool, count: uint,
allow_empty: bool) -> ~[~str] {
let l = len(s);
let mut result = ~[], i = 0u, start = 0u, done = 0u;
@ -526,7 +529,7 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
}
// See Issue #1932 for why this is a naive search
pure fn iter_matches(s: &a/str, sep: &b/str, f: fn(uint, uint)) {
pure fn iter_matches(s: &a/str, sep: &b/str, f: &fn(uint, uint)) {
let sep_len = len(sep), l = len(s);
fail_unless!(sep_len > 0u);
let mut i = 0u, match_start = 0u, match_i = 0u;
@ -553,7 +556,7 @@ pure fn iter_matches(s: &a/str, sep: &b/str, f: fn(uint, uint)) {
}
}
pure fn iter_between_matches(s: &a/str, sep: &b/str, f: fn(uint, uint)) {
pure fn iter_between_matches(s: &a/str, sep: &b/str, f: &fn(uint, uint)) {
let mut last_end = 0u;
do iter_matches(s, sep) |from, to| {
f(last_end, from);
@ -912,7 +915,7 @@ Section: Iterating through strings
* Return true if a predicate matches all characters or if the string
* contains no characters
*/
pub pure fn all(s: &str, it: fn(char) -> bool) -> bool {
pub pure fn all(s: &str, it: &fn(char) -> bool) -> bool {
all_between(s, 0u, len(s), it)
}
@ -920,12 +923,12 @@ pub pure fn all(s: &str, it: fn(char) -> bool) -> bool {
* Return true if a predicate matches any character (and false if it
* matches none or there are no characters)
*/
pub pure fn any(ss: &str, pred: fn(char) -> bool) -> bool {
pub pure fn any(ss: &str, pred: &fn(char) -> bool) -> bool {
!all(ss, |cc| !pred(cc))
}
/// Apply a function to each character
pub pure fn map(ss: &str, ff: fn(char) -> char) -> ~str {
pub pure fn map(ss: &str, ff: &fn(char) -> char) -> ~str {
let mut result = ~"";
unsafe {
reserve(&mut result, len(ss));
@ -937,7 +940,7 @@ pub pure fn map(ss: &str, ff: fn(char) -> char) -> ~str {
}
/// Iterate over the bytes in a string
pub pure fn bytes_each(ss: &str, it: fn(u8) -> bool) {
pub pure fn bytes_each(ss: &str, it: &fn(u8) -> bool) {
let mut pos = 0u;
let len = len(ss);
@ -949,13 +952,13 @@ pub pure fn bytes_each(ss: &str, it: fn(u8) -> bool) {
/// Iterate over the bytes in a string
#[inline(always)]
pub pure fn each(s: &str, it: fn(u8) -> bool) {
pub pure fn each(s: &str, it: &fn(u8) -> bool) {
eachi(s, |_i, b| it(b) )
}
/// Iterate over the bytes in a string, with indices
#[inline(always)]
pub pure fn eachi(s: &str, it: fn(uint, u8) -> bool) {
pub pure fn eachi(s: &str, it: &fn(uint, u8) -> bool) {
let mut i = 0u, l = len(s);
while (i < l) {
if !it(i, s[i]) { break; }
@ -965,13 +968,13 @@ pub pure fn eachi(s: &str, it: fn(uint, u8) -> bool) {
/// Iterates over the chars in a string
#[inline(always)]
pub pure fn each_char(s: &str, it: fn(char) -> bool) {
pub pure fn each_char(s: &str, it: &fn(char) -> bool) {
each_chari(s, |_i, c| it(c))
}
/// Iterates over the chars in a string, with indices
#[inline(always)]
pub pure fn each_chari(s: &str, it: fn(uint, char) -> bool) {
pub pure fn each_chari(s: &str, it: &fn(uint, char) -> bool) {
let mut pos = 0u, ch_pos = 0u;
let len = len(s);
while pos < len {
@ -983,7 +986,7 @@ pub pure fn each_chari(s: &str, it: fn(uint, char) -> bool) {
}
/// Iterate over the characters in a string
pub pure fn chars_each(s: &str, it: fn(char) -> bool) {
pub pure fn chars_each(s: &str, it: &fn(char) -> bool) {
let mut pos = 0u;
let len = len(s);
while (pos < len) {
@ -994,7 +997,7 @@ pub pure fn chars_each(s: &str, it: fn(char) -> bool) {
}
/// Apply a function to each substring after splitting by character
pub pure fn split_char_each(ss: &str, cc: char, ff: fn(v: &str) -> bool) {
pub pure fn split_char_each(ss: &str, cc: char, ff: &fn(v: &str) -> bool) {
vec::each(split_char(ss, cc), |s| ff(*s))
}
@ -1003,19 +1006,19 @@ pub pure fn split_char_each(ss: &str, cc: char, ff: fn(v: &str) -> bool) {
* `count` times
*/
pub pure fn splitn_char_each(ss: &str, sep: char, count: uint,
ff: fn(v: &str) -> bool) {
ff: &fn(v: &str) -> bool) {
vec::each(splitn_char(ss, sep, count), |s| ff(*s))
}
/// Apply a function to each word
pub pure fn words_each(ss: &str, ff: fn(v: &str) -> bool) {
pub pure fn words_each(ss: &str, ff: &fn(v: &str) -> bool) {
vec::each(words(ss), |s| ff(*s))
}
/**
* Apply a function to each line (by '\n')
*/
pub pure fn lines_each(ss: &str, ff: fn(v: &str) -> bool) {
pub pure fn lines_each(ss: &str, ff: &fn(v: &str) -> bool) {
vec::each(lines(ss), |s| ff(*s))
}
@ -1195,7 +1198,7 @@ pub pure fn rfind_char_between(s: &str, c: char, start: uint, end: uint)
* An `option` containing the byte index of the first matching character
* or `none` if there is no match
*/
pub pure fn find(s: &str, f: fn(char) -> bool) -> Option<uint> {
pub pure fn find(s: &str, f: &fn(char) -> bool) -> Option<uint> {
find_between(s, 0u, len(s), f)
}
@ -1219,7 +1222,7 @@ pub pure fn find(s: &str, f: fn(char) -> bool) -> Option<uint> {
* `start` must be less than or equal to `len(s)`. `start` must be the
* index of a character boundary, as defined by `is_char_boundary`.
*/
pub pure fn find_from(s: &str, start: uint, f: fn(char)
pub pure fn find_from(s: &str, start: uint, f: &fn(char)
-> bool) -> Option<uint> {
find_between(s, start, len(s), f)
}
@ -1246,7 +1249,10 @@ pub pure fn find_from(s: &str, start: uint, f: fn(char)
* or equal to `len(s)`. `start` must be the index of a character
* boundary, as defined by `is_char_boundary`.
*/
pub pure fn find_between(s: &str, start: uint, end: uint, f: fn(char) -> bool)
pub pure fn find_between(s: &str,
start: uint,
end: uint,
f: &fn(char) -> bool)
-> Option<uint> {
fail_unless!(start <= end);
fail_unless!(end <= len(s));
@ -1274,7 +1280,7 @@ pub pure fn find_between(s: &str, start: uint, end: uint, f: fn(char) -> bool)
* An option containing the byte index of the last matching character
* or `none` if there is no match
*/
pub pure fn rfind(s: &str, f: fn(char) -> bool) -> Option<uint> {
pub pure fn rfind(s: &str, f: &fn(char) -> bool) -> Option<uint> {
rfind_between(s, len(s), 0u, f)
}
@ -1298,7 +1304,7 @@ pub pure fn rfind(s: &str, f: fn(char) -> bool) -> Option<uint> {
* `start` must be less than or equal to `len(s)', `start` must be the
* index of a character boundary, as defined by `is_char_boundary`
*/
pub pure fn rfind_from(s: &str, start: uint, f: fn(char) -> bool)
pub pure fn rfind_from(s: &str, start: uint, f: &fn(char) -> bool)
-> Option<uint> {
rfind_between(s, start, 0u, f)
}
@ -1326,7 +1332,7 @@ pub pure fn rfind_from(s: &str, start: uint, f: fn(char) -> bool)
* boundary, as defined by `is_char_boundary`
*/
pub pure fn rfind_between(s: &str, start: uint, end: uint,
f: fn(char) -> bool)
f: &fn(char) -> bool)
-> Option<uint> {
fail_unless!(start >= end);
fail_unless!(start <= len(s));
@ -1589,7 +1595,7 @@ pub pure fn to_utf16(s: &str) -> ~[u16] {
u
}
pub pure fn utf16_chars(v: &[u16], f: fn(char)) {
pub pure fn utf16_chars(v: &[u16], f: &fn(char)) {
let len = vec::len(v);
let mut i = 0u;
while (i < len && v[i] != 0u16) {
@ -1815,7 +1821,7 @@ pure fn char_range_at_reverse(ss: &str, start: uint) -> CharRange {
* that is if `it` returned `false` at any point.
*/
pub pure fn all_between(s: &str, start: uint, end: uint,
it: fn(char) -> bool) -> bool {
it: &fn(char) -> bool) -> bool {
fail_unless!(is_char_boundary(s, start));
let mut i = start;
while i < end {
@ -1848,7 +1854,7 @@ pub pure fn all_between(s: &str, start: uint, end: uint,
* `true` if `it` returns `true` for any character
*/
pub pure fn any_between(s: &str, start: uint, end: uint,
it: fn(char) -> bool) -> bool {
it: &fn(char) -> bool) -> bool {
!all_between(s, start, end, |c| !it(c))
}
@ -1886,7 +1892,7 @@ pub const nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8];
* let i = str::as_bytes("Hello World") { |bytes| vec::len(bytes) };
* ~~~
*/
pub pure fn as_bytes<T>(s: &const ~str, f: fn(&~[u8]) -> T) -> T {
pub pure fn as_bytes<T>(s: &const ~str, f: &fn(&~[u8]) -> T) -> T {
unsafe {
let v: *~[u8] = cast::transmute(copy s);
f(&*v)
@ -1921,7 +1927,7 @@ pub pure fn as_bytes_slice(s: &a/str) -> &a/[u8] {
* let s = str::as_c_str("PATH", { |path| libc::getenv(path) });
* ~~~
*/
pub pure fn as_c_str<T>(s: &str, f: fn(*libc::c_char) -> T) -> T {
pub pure fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T {
do as_buf(s) |buf, len| {
// NB: len includes the trailing null.
fail_unless!(len > 0);
@ -1943,7 +1949,7 @@ pub pure fn as_c_str<T>(s: &str, f: fn(*libc::c_char) -> T) -> T {
* to full strings, or suffixes of them.
*/
#[inline(always)]
pub pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
pub pure fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
unsafe {
let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::addr_of(&s));
let (buf,len) = *v;
@ -2088,7 +2094,7 @@ pub mod raw {
/// Form a slice from a *u8 buffer of the given length without copying.
pub unsafe fn buf_as_slice<T>(buf: *u8, len: uint,
f: fn(v: &str) -> T) -> T {
f: &fn(v: &str) -> T) -> T {
let v = (buf, len + 1);
fail_unless!(is_utf8(::cast::reinterpret_cast(&v)));
f(::cast::transmute(v))
@ -2238,21 +2244,21 @@ pub mod traits {
pub mod traits {}
pub trait StrSlice {
pure fn all(&self, it: fn(char) -> bool) -> bool;
pure fn any(&self, it: fn(char) -> bool) -> bool;
pure fn all(&self, it: &fn(char) -> bool) -> bool;
pure fn any(&self, it: &fn(char) -> bool) -> bool;
pure fn contains(&self, needle: &a/str) -> bool;
pure fn contains_char(&self, needle: char) -> bool;
pure fn each(&self, it: fn(u8) -> bool);
pure fn eachi(&self, it: fn(uint, u8) -> bool);
pure fn each_char(&self, it: fn(char) -> bool);
pure fn each_chari(&self, it: fn(uint, char) -> bool);
pure fn each(&self, it: &fn(u8) -> bool);
pure fn eachi(&self, it: &fn(uint, u8) -> bool);
pure fn each_char(&self, it: &fn(char) -> bool);
pure fn each_chari(&self, it: &fn(uint, char) -> bool);
pure fn ends_with(&self, needle: &str) -> bool;
pure fn is_empty(&self) -> bool;
pure fn is_whitespace(&self) -> bool;
pure fn is_alphanumeric(&self) -> bool;
pure fn len(&self) -> uint;
pure fn slice(&self, begin: uint, end: uint) -> ~str;
pure fn split(&self, sepfn: fn(char) -> bool) -> ~[~str];
pure fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str];
pure fn split_char(&self, sep: char) -> ~[~str];
pure fn split_str(&self, sep: &a/str) -> ~[~str];
pure fn starts_with(&self, needle: &a/str) -> bool;
@ -2276,13 +2282,13 @@ impl StrSlice for &self/str {
* contains no characters
*/
#[inline]
pure fn all(&self, it: fn(char) -> bool) -> bool { all(*self, it) }
pure fn all(&self, it: &fn(char) -> bool) -> bool { all(*self, it) }
/**
* Return true if a predicate matches any character (and false if it
* matches none or there are no characters)
*/
#[inline]
pure fn any(&self, it: fn(char) -> bool) -> bool { any(*self, it) }
pure fn any(&self, it: &fn(char) -> bool) -> bool { any(*self, it) }
/// Returns true if one string contains another
#[inline]
pure fn contains(&self, needle: &a/str) -> bool {
@ -2295,16 +2301,16 @@ impl StrSlice for &self/str {
}
/// Iterate over the bytes in a string
#[inline]
pure fn each(&self, it: fn(u8) -> bool) { each(*self, it) }
pure fn each(&self, it: &fn(u8) -> bool) { each(*self, it) }
/// Iterate over the bytes in a string, with indices
#[inline]
pure fn eachi(&self, it: fn(uint, u8) -> bool) { eachi(*self, it) }
pure fn eachi(&self, it: &fn(uint, u8) -> bool) { eachi(*self, it) }
/// Iterate over the chars in a string
#[inline]
pure fn each_char(&self, it: fn(char) -> bool) { each_char(*self, it) }
pure fn each_char(&self, it: &fn(char) -> bool) { each_char(*self, it) }
/// Iterate over the chars in a string, with indices
#[inline]
pure fn each_chari(&self, it: fn(uint, char) -> bool) {
pure fn each_chari(&self, it: &fn(uint, char) -> bool) {
each_chari(*self, it)
}
/// Returns true if one string ends with another
@ -2345,7 +2351,7 @@ impl StrSlice for &self/str {
}
/// Splits a string into substrings using a character function
#[inline]
pure fn split(&self, sepfn: fn(char) -> bool) -> ~[~str] {
pure fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str] {
split(*self, sepfn)
}
/**

View File

@ -227,7 +227,7 @@ pub mod tests {
pub fn synthesize_closure() {
unsafe {
let x = 10;
let f: fn(int) -> int = |y| x + y;
let f: &fn(int) -> int = |y| x + y;
fail_unless!(f(20) == 30);
@ -241,7 +241,7 @@ pub mod tests {
env: environment
};
let new_f: fn(int) -> int = cast::transmute(new_closure);
let new_f: &fn(int) -> int = cast::transmute(new_closure);
fail_unless!(new_f(20) == 30);
}
}

View File

@ -79,7 +79,7 @@ pub unsafe fn local_data_set<T:Durable>(
*/
pub unsafe fn local_data_modify<T:Durable>(
key: LocalDataKey<T>,
modify_fn: fn(Option<@T>) -> Option<@T>) {
modify_fn: &fn(Option<@T>) -> Option<@T>) {
local_modify(rt::rust_get_task(), key, modify_fn)
}

View File

@ -176,7 +176,7 @@ pub unsafe fn local_set<T:Durable>(
pub unsafe fn local_modify<T:Durable>(
task: *rust_task, key: LocalDataKey<T>,
modify_fn: fn(Option<@T>) -> Option<@T>) {
modify_fn: &fn(Option<@T>) -> Option<@T>) {
// Could be more efficient by doing the lookup work, but this is easy.
let newdata = modify_fn(local_pop(task, key));

View File

@ -295,7 +295,7 @@ pub impl TaskBuilder {
* # Failure
* Fails if a future_result was already set for this task.
*/
fn future_result(&self, blk: fn(v: Port<TaskResult>)) -> TaskBuilder {
fn future_result(&self, blk: &fn(v: Port<TaskResult>)) -> TaskBuilder {
// FIXME (#3725): Once linked failure and notification are
// handled in the library, I can imagine implementing this by just
// registering an arbitrary number of task::on_exit handlers and
@ -572,7 +572,7 @@ pub fn get_scheduler() -> Scheduler {
* }
* ~~~
*/
pub unsafe fn unkillable<U>(f: fn() -> U) -> U {
pub unsafe fn unkillable<U>(f: &fn() -> U) -> U {
struct AllowFailure {
t: *rust_task,
drop {
@ -597,7 +597,7 @@ pub unsafe fn unkillable<U>(f: fn() -> U) -> U {
}
/// The inverse of unkillable. Only ever to be used nested in unkillable().
pub unsafe fn rekillable<U>(f: fn() -> U) -> U {
pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
struct DisallowFailure {
t: *rust_task,
drop {
@ -625,7 +625,7 @@ pub unsafe fn rekillable<U>(f: fn() -> U) -> U {
* A stronger version of unkillable that also inhibits scheduling operations.
* For use with exclusive ARCs, which use pthread mutexes directly.
*/
pub unsafe fn atomically<U>(f: fn() -> U) -> U {
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
struct DeferInterrupts {
t: *rust_task,
drop {

View File

@ -108,7 +108,7 @@ fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
let was_present = tasks.remove(&task);
fail_unless!(was_present);
}
pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) {
pub fn taskset_each(tasks: &TaskSet, blk: &fn(v: *rust_task) -> bool) {
tasks.each(|k| blk(*k))
}
@ -151,17 +151,17 @@ struct AncestorNode {
mut ancestors: AncestorList,
}
enum AncestorList = Option<unstable::Exclusive<AncestorNode>>;
struct AncestorList(Option<unstable::Exclusive<AncestorNode>>);
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
#[inline(always)]
fn access_group<U>(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U {
fn access_group<U>(x: &TaskGroupArc, blk: &fn(TaskGroupInner) -> U) -> U {
unsafe { x.with(blk) }
}
#[inline(always)]
fn access_ancestors<U>(x: &unstable::Exclusive<AncestorNode>,
blk: fn(x: &mut AncestorNode) -> U) -> U {
blk: &fn(x: &mut AncestorNode) -> U) -> U {
unsafe { x.with(blk) }
}
@ -175,7 +175,7 @@ fn access_ancestors<U>(x: &unstable::Exclusive<AncestorNode>,
// allocations. Once that bug is fixed, changing the sigil should suffice.
fn each_ancestor(list: &mut AncestorList,
bail_opt: Option<@fn(TaskGroupInner)>,
forward_blk: fn(TaskGroupInner) -> bool)
forward_blk: &fn(TaskGroupInner) -> bool)
-> bool {
// "Kickoff" call - there was no last generation.
return !coalesce(list, bail_opt, forward_blk, uint::max_value);
@ -184,7 +184,7 @@ fn each_ancestor(list: &mut AncestorList,
// whether or not unwinding is needed (i.e., !successful iteration).
fn coalesce(list: &mut AncestorList,
bail_opt: Option<@fn(TaskGroupInner)>,
forward_blk: fn(TaskGroupInner) -> bool,
forward_blk: &fn(TaskGroupInner) -> bool,
last_generation: uint) -> bool {
// Need to swap the list out to use it, to appease borrowck.
let tmp_list = util::replace(&mut *list, AncestorList(None));
@ -288,7 +288,7 @@ fn each_ancestor(list: &mut AncestorList,
// Wrapper around exclusive::with that appeases borrowck.
fn with_parent_tg<U>(parent_group: &mut Option<TaskGroupArc>,
blk: fn(TaskGroupInner) -> U) -> U {
blk: &fn(TaskGroupInner) -> U) -> U {
// If this trips, more likely the problem is 'blk' failed inside.
let tmp_arc = option::swap_unwrap(&mut *parent_group);
let result = do access_group(&tmp_arc) |tg_opt| { blk(tg_opt) };

View File

@ -32,7 +32,7 @@ pub struct TrieMap<T> {
impl<T> BaseIter<(uint, &'self T)> for TrieMap<T> {
/// Visit all key-value pairs in order
#[inline(always)]
pure fn each(&self, f: fn(&(uint, &self/T)) -> bool) {
pure fn each(&self, f: &fn(&(uint, &self/T)) -> bool) {
self.root.each(f);
}
#[inline(always)]
@ -42,7 +42,7 @@ impl<T> BaseIter<(uint, &'self T)> for TrieMap<T> {
impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
/// Visit all key-value pairs in reverse order
#[inline(always)]
pure fn each_reverse(&self, f: fn(&(uint, &self/T)) -> bool) {
pure fn each_reverse(&self, f: &fn(&(uint, &self/T)) -> bool) {
self.root.each_reverse(f);
}
}
@ -75,13 +75,16 @@ impl<T> Map<uint, T> for TrieMap<T> {
/// Visit all keys in order
#[inline(always)]
pure fn each_key(&self, f: fn(&uint) -> bool) {
pure fn each_key(&self, f: &fn(&uint) -> bool) {
self.each(|&(k, _)| f(&k))
}
/// Visit all values in order
#[inline(always)]
pure fn each_value(&self, f: fn(&T) -> bool) { self.each(|&(_, v)| f(v)) }
pure fn each_value(&self,
f: &fn(&T) -> bool) {
self.each(|&(_, v)| f(v))
}
/// Return the value corresponding to the key in the map
#[inline(hint)]
@ -138,18 +141,18 @@ impl<T> TrieMap<T> {
impl<T> TrieMap<T> {
/// Visit all keys in reverse order
#[inline(always)]
pure fn each_key_reverse(&self, f: fn(&uint) -> bool) {
pure fn each_key_reverse(&self, f: &fn(&uint) -> bool) {
self.each_reverse(|&(k, _)| f(&k))
}
/// Visit all values in reverse order
#[inline(always)]
pure fn each_value_reverse(&self, f: fn(&T) -> bool) {
pure fn each_value_reverse(&self, f: &fn(&T) -> bool) {
self.each_reverse(|&(_, v)| f(v))
}
/// Iterate over the map and mutate the contained values
fn mutate_values(&mut self, f: fn(uint, &mut T) -> bool) {
fn mutate_values(&mut self, f: &fn(uint, &mut T) -> bool) {
self.root.mutate_values(f);
}
}
@ -160,13 +163,13 @@ pub struct TrieSet {
impl BaseIter<uint> for TrieSet {
/// Visit all values in order
pure fn each(&self, f: fn(&uint) -> bool) { self.map.each_key(f) }
pure fn each(&self, f: &fn(&uint) -> bool) { self.map.each_key(f) }
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl ReverseIter<uint> for TrieSet {
/// Visit all values in reverse order
pure fn each_reverse(&self, f: fn(&uint) -> bool) {
pure fn each_reverse(&self, f: &fn(&uint) -> bool) {
self.map.each_key_reverse(f)
}
}
@ -223,7 +226,7 @@ impl<T> TrieNode<T> {
}
impl<T> TrieNode<T> {
pure fn each(&self, f: fn(&(uint, &self/T)) -> bool) -> bool {
pure fn each(&self, f: &fn(&(uint, &self/T)) -> bool) -> bool {
for uint::range(0, self.children.len()) |idx| {
match self.children[idx] {
Internal(ref x) => if !x.each(f) { return false },
@ -234,7 +237,7 @@ impl<T> TrieNode<T> {
true
}
pure fn each_reverse(&self, f: fn(&(uint, &self/T)) -> bool) -> bool {
pure fn each_reverse(&self, f: &fn(&(uint, &self/T)) -> bool) -> bool {
for uint::range_rev(self.children.len(), 0) |idx| {
match self.children[idx - 1] {
Internal(ref x) => if !x.each_reverse(f) { return false },
@ -245,7 +248,7 @@ impl<T> TrieNode<T> {
true
}
fn mutate_values(&mut self, f: fn(uint, &mut T) -> bool) -> bool {
fn mutate_values(&mut self, f: &fn(uint, &mut T) -> bool) -> bool {
for vec::each_mut(self.children) |child| {
match *child {
Internal(ref mut x) => if !x.mutate_values(f) {

View File

@ -232,7 +232,7 @@ fn LittleLock() -> LittleLock {
pub impl LittleLock {
#[inline(always)]
unsafe fn lock<T>(&self, f: fn() -> T) -> T {
unsafe fn lock<T>(&self, f: &fn() -> T) -> T {
struct Unlock {
l: rust_little_lock,
drop {
@ -284,7 +284,7 @@ pub impl<T:Owned> Exclusive<T> {
// accessing the provided condition variable) are prohibited while inside
// the exclusive. Supporting that is a work in progress.
#[inline(always)]
unsafe fn with<U>(&self, f: fn(x: &mut T) -> U) -> U {
unsafe fn with<U>(&self, f: &fn(x: &mut T) -> U) -> U {
unsafe {
let rec = get_shared_mutable_state(&self.x);
do (*rec).lock.lock {
@ -301,7 +301,7 @@ pub impl<T:Owned> Exclusive<T> {
}
#[inline(always)]
unsafe fn with_imm<U>(&self, f: fn(x: &T) -> U) -> U {
unsafe fn with_imm<U>(&self, f: &fn(x: &T) -> U) -> U {
do self.with |x| {
f(cast::transmute_immut(x))
}

View File

@ -175,7 +175,7 @@ pub pure fn with_capacity<T>(capacity: uint) -> ~[T] {
*/
#[inline(always)]
pub pure fn build_sized<A>(size: uint,
builder: fn(push: pure fn(v: A))) -> ~[A] {
builder: &fn(push: &pure fn(v: A))) -> ~[A] {
let mut vec = with_capacity(size);
builder(|x| unsafe { vec.push(x) });
vec
@ -192,7 +192,7 @@ pub pure fn build_sized<A>(size: uint,
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build<A>(builder: fn(push: pure fn(v: A))) -> ~[A] {
pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> ~[A] {
build_sized(4, builder)
}
@ -210,7 +210,7 @@ pub pure fn build<A>(builder: fn(push: pure fn(v: A))) -> ~[A] {
*/
#[inline(always)]
pub pure fn build_sized_opt<A>(size: Option<uint>,
builder: fn(push: pure fn(v: A))) -> ~[A] {
builder: &fn(push: &pure fn(v: A))) -> ~[A] {
build_sized(size.get_or_default(4), builder)
}
@ -305,7 +305,7 @@ pub pure fn const_slice<T>(v: &r/[const T],
/// Copies
/// Split the vector `v` by applying each element against the predicate `f`.
pub fn split<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
pub fn split<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { return ~[] }
@ -328,7 +328,7 @@ pub fn split<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
* Split the vector `v` by applying each element against the predicate `f` up
* to `n` times.
*/
pub fn splitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
pub fn splitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { return ~[] }
@ -354,7 +354,7 @@ pub fn splitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
* Reverse split the vector `v` by applying each element against the predicate
* `f`.
*/
pub fn rsplit<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
pub fn rsplit<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0) { return ~[] }
@ -378,7 +378,7 @@ pub fn rsplit<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
* Reverse split the vector `v` by applying each element against the predicate
* `f` up to `n times.
*/
pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { return ~[] }
@ -405,7 +405,7 @@ pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
* Partitions a vector into two new vectors: those that satisfies the
* predicate, and those that do not.
*/
pub fn partition<T>(v: ~[T], f: fn(&T) -> bool) -> (~[T], ~[T]) {
pub fn partition<T>(v: ~[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) {
let mut lefts = ~[];
let mut rights = ~[];
@ -426,7 +426,7 @@ pub fn partition<T>(v: ~[T], f: fn(&T) -> bool) -> (~[T], ~[T]) {
* Partitions a vector into two new vectors: those that satisfies the
* predicate, and those that do not.
*/
pub pure fn partitioned<T:Copy>(v: &[T], f: fn(&T) -> bool) -> (~[T], ~[T]) {
pub pure fn partitioned<T:Copy>(v: &[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) {
let mut lefts = ~[];
let mut rights = ~[];
@ -535,7 +535,7 @@ pub fn remove<T>(v: &mut ~[T], i: uint) -> T {
v.pop()
}
pub fn consume<T>(mut v: ~[T], f: fn(uint, v: T)) {
pub fn consume<T>(mut v: ~[T], f: &fn(uint, v: T)) {
unsafe {
do as_mut_buf(v) |p, ln| {
for uint::range(0, ln) |i| {
@ -780,7 +780,7 @@ pub fn grow_set<T:Copy>(v: &mut ~[T], index: uint, initval: &T, val: T) {
// Functional utilities
/// Apply a function to each element of a vector and return the results
pub pure fn map<T, U>(v: &[T], f: fn(t: &T) -> U) -> ~[U] {
pub pure fn map<T, U>(v: &[T], f: &fn(t: &T) -> U) -> ~[U] {
let mut result = with_capacity(len(v));
for each(v) |elem| {
unsafe {
@ -790,7 +790,7 @@ pub pure fn map<T, U>(v: &[T], f: fn(t: &T) -> U) -> ~[U] {
result
}
pub fn map_consume<T, U>(v: ~[T], f: fn(v: T) -> U) -> ~[U] {
pub fn map_consume<T, U>(v: ~[T], f: &fn(v: T) -> U) -> ~[U] {
let mut result = ~[];
do consume(v) |_i, x| {
result.push(f(x));
@ -799,7 +799,7 @@ pub fn map_consume<T, U>(v: ~[T], f: fn(v: T) -> U) -> ~[U] {
}
/// Apply a function to each element of a vector and return the results
pub pure fn mapi<T, U>(v: &[T], f: fn(uint, t: &T) -> U) -> ~[U] {
pub pure fn mapi<T, U>(v: &[T], f: &fn(uint, t: &T) -> U) -> ~[U] {
let mut i = 0;
do map(v) |e| {
i += 1;
@ -811,7 +811,7 @@ pub pure fn mapi<T, U>(v: &[T], f: fn(uint, t: &T) -> U) -> ~[U] {
* Apply a function to each element of a vector and return a concatenation
* of each result vector
*/
pub pure fn flat_map<T, U>(v: &[T], f: fn(t: &T) -> ~[U]) -> ~[U] {
pub pure fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] {
let mut result = ~[];
for each(v) |elem| { unsafe{ result.push_all_move(f(elem)); } }
result
@ -819,7 +819,7 @@ pub pure fn flat_map<T, U>(v: &[T], f: fn(t: &T) -> ~[U]) -> ~[U] {
/// Apply a function to each pair of elements and return the results
pub pure fn map2<T:Copy,U:Copy,V>(v0: &[T], v1: &[U],
f: fn(t: &T, v: &U) -> V) -> ~[V] {
f: &fn(t: &T, v: &U) -> V) -> ~[V] {
let v0_len = len(v0);
if v0_len != len(v1) { fail!(); }
let mut u: ~[V] = ~[];
@ -833,7 +833,7 @@ pub pure fn map2<T:Copy,U:Copy,V>(v0: &[T], v1: &[U],
pub fn filter_map<T, U>(
v: ~[T],
f: fn(t: T) -> Option<U>) -> ~[U]
f: &fn(t: T) -> Option<U>) -> ~[U]
{
/*!
*
@ -854,7 +854,7 @@ pub fn filter_map<T, U>(
pub pure fn filter_mapped<T, U: Copy>(
v: &[T],
f: fn(t: &T) -> Option<U>) -> ~[U]
f: &fn(t: &T) -> Option<U>) -> ~[U]
{
/*!
*
@ -879,7 +879,7 @@ pub pure fn filter_mapped<T, U: Copy>(
* Apply function `f` to each element of `v` and return a vector containing
* only those elements for which `f` returned true.
*/
pub fn filter<T>(v: ~[T], f: fn(t: &T) -> bool) -> ~[T] {
pub fn filter<T>(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] {
let mut result = ~[];
// FIXME (#4355 maybe): using v.consume here crashes
// do v.consume |_, elem| {
@ -896,7 +896,7 @@ pub fn filter<T>(v: ~[T], f: fn(t: &T) -> bool) -> ~[T] {
* Apply function `f` to each element of `v` and return a vector containing
* only those elements for which `f` returned true.
*/
pub pure fn filtered<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[T] {
pub pure fn filtered<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[T] {
let mut result = ~[];
for each(v) |elem| {
if f(elem) { unsafe { result.push(*elem); } }
@ -907,7 +907,7 @@ pub pure fn filtered<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[T] {
/**
* Like `filter()`, but in place. Preserves order of `v`. Linear time.
*/
pub fn retain<T>(v: &mut ~[T], f: pure fn(t: &T) -> bool) {
pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
let len = v.len();
let mut deleted: uint = 0;
@ -963,7 +963,7 @@ pub pure fn connect<T:Copy>(v: &[~[T]], sep: &T) -> ~[T] {
* ~~~
*
*/
pub pure fn foldl<T, U>(z: T, v: &[U], p: fn(t: T, u: &U) -> T) -> T {
pub pure fn foldl<T, U>(z: T, v: &[U], p: &fn(t: T, u: &U) -> T) -> T {
let mut accum = z;
let mut i = 0;
let l = v.len();
@ -995,7 +995,7 @@ pub pure fn foldl<T, U>(z: T, v: &[U], p: fn(t: T, u: &U) -> T) -> T {
* ~~~
*
*/
pub pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(t: &T, u: U) -> U) -> U {
pub pure fn foldr<T, U: Copy>(v: &[T], z: U, p: &fn(t: &T, u: U) -> U) -> U {
let mut accum = z;
for rev_each(v) |elt| {
accum = p(elt, accum);
@ -1008,7 +1008,7 @@ pub pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(t: &T, u: U) -> U) -> U {
*
* If the vector contains no elements then false is returned.
*/
pub pure fn any<T>(v: &[T], f: fn(t: &T) -> bool) -> bool {
pub pure fn any<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool {
for each(v) |elem| { if f(elem) { return true; } }
false
}
@ -1019,7 +1019,7 @@ pub pure fn any<T>(v: &[T], f: fn(t: &T) -> bool) -> bool {
* If the vectors contains no elements then false is returned.
*/
pub pure fn any2<T, U>(v0: &[T], v1: &[U],
f: fn(a: &T, b: &U) -> bool) -> bool {
f: &fn(a: &T, b: &U) -> bool) -> bool {
let v0_len = len(v0);
let v1_len = len(v1);
let mut i = 0u;
@ -1035,7 +1035,7 @@ pub pure fn any2<T, U>(v0: &[T], v1: &[U],
*
* If the vector contains no elements then true is returned.
*/
pub pure fn all<T>(v: &[T], f: fn(t: &T) -> bool) -> bool {
pub pure fn all<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool {
for each(v) |elem| { if !f(elem) { return false; } }
true
}
@ -1045,7 +1045,7 @@ pub pure fn all<T>(v: &[T], f: fn(t: &T) -> bool) -> bool {
*
* If the vector contains no elements then true is returned.
*/
pub pure fn alli<T>(v: &[T], f: fn(uint, t: &T) -> bool) -> bool {
pub pure fn alli<T>(v: &[T], f: &fn(uint, t: &T) -> bool) -> bool {
for eachi(v) |i, elem| { if !f(i, elem) { return false; } }
true
}
@ -1056,7 +1056,7 @@ pub pure fn alli<T>(v: &[T], f: fn(uint, t: &T) -> bool) -> bool {
* If the vectors are not the same size then false is returned.
*/
pub pure fn all2<T, U>(v0: &[T], v1: &[U],
f: fn(t: &T, u: &U) -> bool) -> bool {
f: &fn(t: &T, u: &U) -> bool) -> bool {
let v0_len = len(v0);
if v0_len != len(v1) { return false; }
let mut i = 0u;
@ -1084,7 +1084,7 @@ pub pure fn count<T:Eq>(v: &[T], x: &T) -> uint {
* When function `f` returns true then an option containing the element
* is returned. If `f` matches no elements then none is returned.
*/
pub pure fn find<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
pub pure fn find<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
find_between(v, 0u, len(v), f)
}
@ -1096,7 +1096,7 @@ pub pure fn find<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
* the element is returned. If `f` matches no elements then none is returned.
*/
pub pure fn find_between<T:Copy>(v: &[T], start: uint, end: uint,
f: fn(t: &T) -> bool) -> Option<T> {
f: &fn(t: &T) -> bool) -> Option<T> {
position_between(v, start, end, f).map(|i| v[*i])
}
@ -1107,7 +1107,7 @@ pub pure fn find_between<T:Copy>(v: &[T], start: uint, end: uint,
* `f` returns true then an option containing the element is returned. If `f`
* matches no elements then none is returned.
*/
pub pure fn rfind<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
pub pure fn rfind<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
rfind_between(v, 0u, len(v), f)
}
@ -1119,7 +1119,7 @@ pub pure fn rfind<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> {
* the element is returned. If `f` matches no elements then none is return.
*/
pub pure fn rfind_between<T:Copy>(v: &[T], start: uint, end: uint,
f: fn(t: &T) -> bool) -> Option<T> {
f: &fn(t: &T) -> bool) -> Option<T> {
rposition_between(v, start, end, f).map(|i| v[*i])
}
@ -1135,7 +1135,7 @@ pub pure fn position_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
* then an option containing the index is returned. If `f` matches no elements
* then none is returned.
*/
pub pure fn position<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> {
pub pure fn position<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
position_between(v, 0u, len(v), f)
}
@ -1147,7 +1147,7 @@ pub pure fn position<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> {
* the index is returned. If `f` matches no elements then none is returned.
*/
pub pure fn position_between<T>(v: &[T], start: uint, end: uint,
f: fn(t: &T) -> bool) -> Option<uint> {
f: &fn(t: &T) -> bool) -> Option<uint> {
fail_unless!(start <= end);
fail_unless!(end <= len(v));
let mut i = start;
@ -1167,7 +1167,7 @@ pure fn rposition_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
* `f` returns true then an option containing the index is returned. If `f`
* matches no elements then none is returned.
*/
pub pure fn rposition<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> {
pub pure fn rposition<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
rposition_between(v, 0u, len(v), f)
}
@ -1180,7 +1180,7 @@ pub pure fn rposition<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> {
* returned.
*/
pub pure fn rposition_between<T>(v: &[T], start: uint, end: uint,
f: fn(t: &T) -> bool) -> Option<uint> {
f: &fn(t: &T) -> bool) -> Option<uint> {
fail_unless!(start <= end);
fail_unless!(end <= len(v));
let mut i = end;
@ -1334,7 +1334,7 @@ pub pure fn reversed<T:Copy>(v: &[const T]) -> ~[T] {
* ~~~
*/
#[inline(always)]
pub pure fn each<T>(v: &r/[T], f: fn(&r/T) -> bool) {
pub pure fn each<T>(v: &r/[T], f: &fn(&r/T) -> bool) {
// ^^^^
// NB---this CANNOT be &[const T]! The reason
// is that you are passing it to `f()` using
@ -1358,7 +1358,7 @@ pub pure fn each<T>(v: &r/[T], f: fn(&r/T) -> bool) {
/// a vector with mutable contents and you would like
/// to mutate the contents as you iterate.
#[inline(always)]
pub fn each_mut<T>(v: &mut [T], f: fn(elem: &mut T) -> bool) {
pub fn each_mut<T>(v: &mut [T], f: &fn(elem: &mut T) -> bool) {
let mut i = 0;
let n = v.len();
while i < n {
@ -1372,7 +1372,7 @@ pub fn each_mut<T>(v: &mut [T], f: fn(elem: &mut T) -> bool) {
/// Like `each()`, but for the case where you have a vector that *may or may
/// not* have mutable contents.
#[inline(always)]
pub pure fn each_const<T>(v: &[const T], f: fn(elem: &const T) -> bool) {
pub pure fn each_const<T>(v: &[const T], f: &fn(elem: &const T) -> bool) {
let mut i = 0;
let n = v.len();
while i < n {
@ -1389,7 +1389,7 @@ pub pure fn each_const<T>(v: &[const T], f: fn(elem: &const T) -> bool) {
* Return true to continue, false to break.
*/
#[inline(always)]
pub pure fn eachi<T>(v: &r/[T], f: fn(uint, v: &r/T) -> bool) {
pub pure fn eachi<T>(v: &r/[T], f: &fn(uint, v: &r/T) -> bool) {
let mut i = 0;
for each(v) |p| {
if !f(i, p) { return; }
@ -1403,7 +1403,7 @@ pub pure fn eachi<T>(v: &r/[T], f: fn(uint, v: &r/T) -> bool) {
* Return true to continue, false to break.
*/
#[inline(always)]
pub pure fn rev_each<T>(v: &r/[T], blk: fn(v: &r/T) -> bool) {
pub pure fn rev_each<T>(v: &r/[T], blk: &fn(v: &r/T) -> bool) {
rev_eachi(v, |_i, v| blk(v))
}
@ -1413,7 +1413,7 @@ pub pure fn rev_each<T>(v: &r/[T], blk: fn(v: &r/T) -> bool) {
* Return true to continue, false to break.
*/
#[inline(always)]
pub pure fn rev_eachi<T>(v: &r/[T], blk: fn(i: uint, v: &r/T) -> bool) {
pub pure fn rev_eachi<T>(v: &r/[T], blk: &fn(i: uint, v: &r/T) -> bool) {
let mut i = v.len();
while i > 0 {
i -= 1;
@ -1431,7 +1431,7 @@ pub pure fn rev_eachi<T>(v: &r/[T], blk: fn(i: uint, v: &r/T) -> bool) {
* Both vectors must have the same length
*/
#[inline]
pub pure fn each2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) {
pub pure fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) {
fail_unless!(len(v1) == len(v2));
for uint::range(0u, len(v1)) |i| {
if !f(&v1[i], &v2[i]) {
@ -1450,7 +1450,7 @@ pub pure fn each2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) {
* The total number of permutations produced is `len(v)!`. If `v` contains
* repeated elements, then some permutations are repeated.
*/
pub pure fn each_permutation<T:Copy>(v: &[T], put: fn(ts: &[T]) -> bool) {
pub pure fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) {
let ln = len(v);
if ln <= 1 {
put(v);
@ -1497,7 +1497,7 @@ pub pure fn windowed<TT:Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
#[inline(always)]
pub pure fn as_imm_buf<T,U>(s: &[T],
/* NB---this CANNOT be const, see below */
f: fn(*T, uint) -> U) -> U {
f: &fn(*T, uint) -> U) -> U {
// NB---Do not change the type of s to `&[const T]`. This is
// unsound. The reason is that we are going to create immutable pointers
@ -1516,7 +1516,7 @@ pub pure fn as_imm_buf<T,U>(s: &[T],
/// Similar to `as_imm_buf` but passing a `*const T`
#[inline(always)]
pub pure fn as_const_buf<T,U>(s: &[const T],
f: fn(*const T, uint) -> U) -> U {
f: &fn(*const T, uint) -> U) -> U {
unsafe {
let v : *(*const T,uint) =
@ -1529,7 +1529,7 @@ pub pure fn as_const_buf<T,U>(s: &[const T],
/// Similar to `as_imm_buf` but passing a `*mut T`
#[inline(always)]
pub pure fn as_mut_buf<T,U>(s: &mut [T],
f: fn(*mut T, uint) -> U) -> U {
f: &fn(*mut T, uint) -> U) -> U {
unsafe {
let v : *(*mut T,uint) =
@ -1721,13 +1721,13 @@ pub trait ImmutableVector<T> {
pure fn initn(&self, n: uint) -> &self/[T];
pure fn last(&self) -> &self/T;
pure fn last_opt(&self) -> Option<&self/T>;
pure fn foldr<U: Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U;
pure fn map<U>(&self, f: fn(t: &T) -> U) -> ~[U];
pure fn mapi<U>(&self, f: fn(uint, t: &T) -> U) -> ~[U];
fn map_r<U>(&self, f: fn(x: &T) -> U) -> ~[U];
pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool;
pure fn flat_map<U>(&self, f: fn(t: &T) -> ~[U]) -> ~[U];
pure fn filter_mapped<U:Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U];
pure fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U;
pure fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U];
pure fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U];
fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U];
pure fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool;
pure fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
pure fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U];
}
/// Extension methods for vectors
@ -1772,24 +1772,24 @@ impl<T> ImmutableVector<T> for &self/[T] {
/// Reduce a vector from right to left
#[inline]
pure fn foldr<U:Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U {
pure fn foldr<U:Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U {
foldr(*self, z, p)
}
/// Apply a function to each element of a vector and return the results
#[inline]
pure fn map<U>(&self, f: fn(t: &T) -> U) -> ~[U] { map(*self, f) }
pure fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] { map(*self, f) }
/**
* Apply a function to the index and value of each element in the vector
* and return the results
*/
pure fn mapi<U>(&self, f: fn(uint, t: &T) -> U) -> ~[U] {
pure fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U] {
mapi(*self, f)
}
#[inline]
fn map_r<U>(&self, f: fn(x: &T) -> U) -> ~[U] {
fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U] {
let mut r = ~[];
let mut i = 0;
while i < self.len() {
@ -1804,7 +1804,7 @@ impl<T> ImmutableVector<T> for &self/[T] {
*
* If the vector is empty, true is returned.
*/
pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool {
pure fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool {
alli(*self, f)
}
/**
@ -1812,7 +1812,7 @@ impl<T> ImmutableVector<T> for &self/[T] {
* of each result vector
*/
#[inline]
pure fn flat_map<U>(&self, f: fn(t: &T) -> ~[U]) -> ~[U] {
pure fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] {
flat_map(*self, f)
}
/**
@ -1822,15 +1822,15 @@ impl<T> ImmutableVector<T> for &self/[T] {
* the resulting vector.
*/
#[inline]
pure fn filter_mapped<U:Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U] {
pure fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U] {
filter_mapped(*self, f)
}
}
pub trait ImmutableEqVector<T:Eq> {
pure fn position(&self, f: fn(t: &T) -> bool) -> Option<uint>;
pure fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
pure fn position_elem(&self, t: &T) -> Option<uint>;
pure fn rposition(&self, f: fn(t: &T) -> bool) -> Option<uint>;
pure fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
pure fn rposition_elem(&self, t: &T) -> Option<uint>;
}
@ -1843,7 +1843,7 @@ impl<T:Eq> ImmutableEqVector<T> for &self/[T] {
* elements then none is returned.
*/
#[inline]
pure fn position(&self, f: fn(t: &T) -> bool) -> Option<uint> {
pure fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
position(*self, f)
}
@ -1861,7 +1861,7 @@ impl<T:Eq> ImmutableEqVector<T> for &self/[T] {
* returned. If `f` matches no elements then none is returned.
*/
#[inline]
pure fn rposition(&self, f: fn(t: &T) -> bool) -> Option<uint> {
pure fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
rposition(*self, f)
}
@ -1873,9 +1873,9 @@ impl<T:Eq> ImmutableEqVector<T> for &self/[T] {
}
pub trait ImmutableCopyableVector<T> {
pure fn filtered(&self, f: fn(&T) -> bool) -> ~[T];
pure fn rfind(&self, f: fn(t: &T) -> bool) -> Option<T>;
pure fn partitioned(&self, f: fn(&T) -> bool) -> (~[T], ~[T]);
pure fn filtered(&self, f: &fn(&T) -> bool) -> ~[T];
pure fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T>;
pure fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
}
/// Extension methods for vectors
@ -1888,7 +1888,7 @@ impl<T:Copy> ImmutableCopyableVector<T> for &self/[T] {
* containing only those elements for which `f` returned true.
*/
#[inline]
pure fn filtered(&self, f: fn(t: &T) -> bool) -> ~[T] {
pure fn filtered(&self, f: &fn(t: &T) -> bool) -> ~[T] {
filtered(*self, f)
}
@ -1900,7 +1900,7 @@ impl<T:Copy> ImmutableCopyableVector<T> for &self/[T] {
* returned. If `f` matches no elements then none is returned.
*/
#[inline]
pure fn rfind(&self, f: fn(t: &T) -> bool) -> Option<T> {
pure fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T> {
rfind(*self, f)
}
@ -1909,7 +1909,7 @@ impl<T:Copy> ImmutableCopyableVector<T> for &self/[T] {
* those that do not.
*/
#[inline]
pure fn partitioned(&self, f: fn(&T) -> bool) -> (~[T], ~[T]) {
pure fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]) {
partitioned(*self, f)
}
}
@ -1924,10 +1924,10 @@ pub trait OwnedVector<T> {
fn remove(&mut self, i: uint) -> T;
fn swap_remove(&mut self, index: uint) -> T;
fn truncate(&mut self, newlen: uint);
fn retain(&mut self, f: pure fn(t: &T) -> bool);
fn consume(self, f: fn(uint, v: T));
fn filter(self, f: fn(t: &T) -> bool) -> ~[T];
fn partition(self, f: pure fn(&T) -> bool) -> (~[T], ~[T]);
fn retain(&mut self, f: &pure fn(t: &T) -> bool);
fn consume(self, f: &fn(uint, v: T));
fn filter(self, f: &fn(t: &T) -> bool) -> ~[T];
fn partition(self, f: &pure fn(&T) -> bool) -> (~[T], ~[T]);
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>);
}
@ -1978,17 +1978,17 @@ impl<T> OwnedVector<T> for ~[T] {
}
#[inline]
fn retain(&mut self, f: pure fn(t: &T) -> bool) {
fn retain(&mut self, f: &pure fn(t: &T) -> bool) {
retain(self, f);
}
#[inline]
fn consume(self, f: fn(uint, v: T)) {
fn consume(self, f: &fn(uint, v: T)) {
consume(self, f)
}
#[inline]
fn filter(self, f: fn(&T) -> bool) -> ~[T] {
fn filter(self, f: &fn(&T) -> bool) -> ~[T] {
filter(self, f)
}
@ -1997,7 +1997,7 @@ impl<T> OwnedVector<T> for ~[T] {
* those that do not.
*/
#[inline]
fn partition(self, f: fn(&T) -> bool) -> (~[T], ~[T]) {
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]) {
partition(self, f)
}
@ -2138,7 +2138,7 @@ pub mod raw {
#[inline(always)]
pub unsafe fn buf_as_slice<T,U>(p: *T,
len: uint,
f: fn(v: &[T]) -> U) -> U {
f: &fn(v: &[T]) -> U) -> U {
let pair = (p, len * sys::nonzero_size_of::<T>());
let v : *(&blk/[T]) =
::cast::reinterpret_cast(&addr_of(&pair));
@ -2270,7 +2270,9 @@ pub mod bytes {
impl<A> iter::BaseIter<A> for &self/[A] {
#[inline(always)]
pure fn each(&self, blk: fn(v: &'self A) -> bool) { each(*self, blk) }
pub pure fn each(&self, blk: &fn(v: &'self A) -> bool) {
each(*self, blk)
}
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
@ -2278,7 +2280,7 @@ impl<A> iter::BaseIter<A> for &self/[A] {
// FIXME(#4148): This should be redundant
impl<A> iter::BaseIter<A> for ~[A] {
#[inline(always)]
pure fn each(&self, blk: fn(v: &'self A) -> bool) { each(*self, blk) }
pure fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
@ -2286,31 +2288,31 @@ impl<A> iter::BaseIter<A> for ~[A] {
// FIXME(#4148): This should be redundant
impl<A> iter::BaseIter<A> for @[A] {
#[inline(always)]
pure fn each(&self, blk: fn(v: &'self A) -> bool) { each(*self, blk) }
pure fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<A> iter::ExtendedIter<A> for &self/[A] {
pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) {
pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
iter::eachi(self, blk)
}
pub pure fn all(&self, blk: fn(&A) -> bool) -> bool {
pub pure fn all(&self, blk: &fn(&A) -> bool) -> bool {
iter::all(self, blk)
}
pub pure fn any(&self, blk: fn(&A) -> bool) -> bool {
pub pure fn any(&self, blk: &fn(&A) -> bool) -> bool {
iter::any(self, blk)
}
pub pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B {
pub pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
iter::foldl(self, b0, blk)
}
pub pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> {
pub pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
iter::position(self, f)
}
pure fn map_to_vec<B>(&self, op: fn(&A) -> B) -> ~[B] {
pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
iter::map_to_vec(self, op)
}
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: fn(&A) -> IB)
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B] {
iter::flat_map_to_vec(self, op)
}
@ -2318,25 +2320,25 @@ impl<A> iter::ExtendedIter<A> for &self/[A] {
// FIXME(#4148): This should be redundant
impl<A> iter::ExtendedIter<A> for ~[A] {
pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) {
pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
iter::eachi(self, blk)
}
pub pure fn all(&self, blk: fn(&A) -> bool) -> bool {
pub pure fn all(&self, blk: &fn(&A) -> bool) -> bool {
iter::all(self, blk)
}
pub pure fn any(&self, blk: fn(&A) -> bool) -> bool {
pub pure fn any(&self, blk: &fn(&A) -> bool) -> bool {
iter::any(self, blk)
}
pub pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B {
pub pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
iter::foldl(self, b0, blk)
}
pub pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> {
pub pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
iter::position(self, f)
}
pure fn map_to_vec<B>(&self, op: fn(&A) -> B) -> ~[B] {
pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
iter::map_to_vec(self, op)
}
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: fn(&A) -> IB)
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B] {
iter::flat_map_to_vec(self, op)
}
@ -2344,25 +2346,25 @@ impl<A> iter::ExtendedIter<A> for ~[A] {
// FIXME(#4148): This should be redundant
impl<A> iter::ExtendedIter<A> for @[A] {
pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) {
pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
iter::eachi(self, blk)
}
pub pure fn all(&self, blk: fn(&A) -> bool) -> bool {
pub pure fn all(&self, blk: &fn(&A) -> bool) -> bool {
iter::all(self, blk)
}
pub pure fn any(&self, blk: fn(&A) -> bool) -> bool {
pub pure fn any(&self, blk: &fn(&A) -> bool) -> bool {
iter::any(self, blk)
}
pub pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B {
pub pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
iter::foldl(self, b0, blk)
}
pub pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> {
pub pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
iter::position(self, f)
}
pure fn map_to_vec<B>(&self, op: fn(&A) -> B) -> ~[B] {
pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
iter::map_to_vec(self, op)
}
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: fn(&A) -> IB)
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B] {
iter::flat_map_to_vec(self, op)
}
@ -2386,33 +2388,33 @@ impl<A:Eq> iter::EqIter<A> for @[A] {
}
impl<A:Copy> iter::CopyableIter<A> for &self/[A] {
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
iter::filter_to_vec(self, pred)
}
pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
pub pure fn find(&self, f: fn(&A) -> bool) -> Option<A> {
pub pure fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
iter::find(self, f)
}
}
// FIXME(#4148): This should be redundant
impl<A:Copy> iter::CopyableIter<A> for ~[A] {
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
iter::filter_to_vec(self, pred)
}
pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
pub pure fn find(&self, f: fn(&A) -> bool) -> Option<A> {
pub pure fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
iter::find(self, f)
}
}
// FIXME(#4148): This should be redundant
impl<A:Copy> iter::CopyableIter<A> for @[A] {
pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] {
pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
iter::filter_to_vec(self, pred)
}
pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
pub pure fn find(&self, f: fn(&A) -> bool) -> Option<A> {
pub pure fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
iter::find(self, f)
}
}
@ -2435,7 +2437,7 @@ impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for @[A] {
}
impl<A:Copy> iter::CopyableNonstrictIter<A> for &self/[A] {
pure fn each_val(&const self, f: fn(A) -> bool) {
pure fn each_val(&const self, f: &fn(A) -> bool) {
let mut i = 0;
while i < self.len() {
if !f(copy self[i]) { break; }
@ -2446,7 +2448,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for &self/[A] {
// FIXME(#4148): This should be redundant
impl<A:Copy> iter::CopyableNonstrictIter<A> for ~[A] {
pure fn each_val(&const self, f: fn(A) -> bool) {
pure fn each_val(&const self, f: &fn(A) -> bool) {
let mut i = 0;
while i < self.len() {
if !f(copy self[i]) { break; }
@ -2457,7 +2459,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for ~[A] {
// FIXME(#4148): This should be redundant
impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
pure fn each_val(&const self, f: fn(A) -> bool) {
pure fn each_val(&const self, f: &fn(A) -> bool) {
let mut i = 0;
while i < self.len() {
if !f(copy self[i]) { break; }

View File

@ -247,7 +247,7 @@ pub fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::Ty,
*crate2
}
pub fn under(n: uint, it: fn(uint)) {
pub fn under(n: uint, it: &fn(uint)) {
let mut i: uint = 0u;
while i < n { it(i); i += 1u; }
}

View File

@ -153,7 +153,7 @@ pub mod jit {
code: entry,
env: ptr::null()
};
let func: fn(++argv: ~[~str]) = cast::transmute(closure);
let func: &fn(++argv: ~[~str]) = cast::transmute(closure);
func(~[/*bad*/copy sess.opts.binary]);
}

View File

@ -164,7 +164,7 @@ pub fn parse_input(sess: Session, +cfg: ast::crate_cfg, input: input)
}
}
pub fn time<T>(do_it: bool, what: ~str, thunk: fn() -> T) -> T {
pub fn time<T>(do_it: bool, what: ~str, thunk: &fn() -> T) -> T {
if !do_it { return thunk(); }
let start = std::time::precise_time_s();
let rv = thunk();

View File

@ -306,7 +306,7 @@ pub fn basic_options() -> @options {
// Seems out of place, but it uses session, so I'm putting it here
pub fn expect<T:Copy>(sess: Session,
opt: Option<T>,
msg: fn() -> ~str)
msg: &fn() -> ~str)
-> T {
diagnostic::expect(sess.diagnostic(), opt, msg)
}

View File

@ -155,7 +155,7 @@ pub fn get_static_methods_if_impl(cstore: @mut cstore::CStore,
pub fn get_item_attrs(cstore: @mut cstore::CStore,
def_id: ast::def_id,
f: fn(~[@ast::meta_item])) {
f: &fn(~[@ast::meta_item])) {
let cdata = cstore::get_crate_data(cstore, def_id.crate);
decoder::get_item_attrs(cdata, def_id.node, f)
}

View File

@ -88,7 +88,7 @@ pub fn have_crate_data(cstore: @mut CStore, cnum: ast::crate_num) -> bool {
}
pub fn iter_crate_data(cstore: @mut CStore,
i: fn(ast::crate_num, @crate_metadata)) {
i: &fn(ast::crate_num, @crate_metadata)) {
let metas = cstore.metas;
for metas.each |&k, &v| {
i(k, v);

View File

@ -48,7 +48,7 @@ type cmd = @crate_metadata;
// what crate that's in and give us a def_id that makes sense for the current
// build.
fn lookup_hash(d: ebml::Doc, eq_fn: fn(x:&[u8]) -> bool, hash: uint) ->
fn lookup_hash(d: ebml::Doc, eq_fn: &fn(x:&[u8]) -> bool, hash: uint) ->
Option<ebml::Doc> {
let index = reader::get_doc(d, tag_index);
let table = reader::get_doc(index, tag_index_table);
@ -193,7 +193,7 @@ fn item_def_id(d: ebml::Doc, cdata: cmd) -> ast::def_id {
|d| parse_def_id(d)));
}
fn each_reexport(d: ebml::Doc, f: fn(ebml::Doc) -> bool) {
fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) {
for reader::tagged_docs(d, tag_items_data_item_reexport) |reexport_doc| {
if !f(reexport_doc) {
return;
@ -451,7 +451,7 @@ pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) {
/// Iterates over all the paths in the given crate.
pub fn each_path(intr: @ident_interner, cdata: cmd,
get_crate_data: GetCrateDataCb,
f: fn(&str, def_like) -> bool) {
f: &fn(&str, def_like) -> bool) {
let root = reader::Doc(cdata.data);
let items = reader::get_doc(root, tag_items);
let items_data = reader::get_doc(items, tag_items_data);
@ -855,7 +855,7 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
pub fn get_item_attrs(cdata: cmd,
node_id: ast::node_id,
f: fn(~[@ast::meta_item])) {
f: &fn(~[@ast::meta_item])) {
let item = lookup_item(node_id, cdata.data);
for reader::tagged_docs(item, tag_attributes) |attributes| {
@ -1093,7 +1093,7 @@ pub fn get_crate_vers(data: @~[u8]) -> @~str {
fn iter_crate_items(intr: @ident_interner, cdata: cmd,
get_crate_data: GetCrateDataCb,
proc: fn(path: &str, ast::def_id)) {
proc: &fn(path: &str, ast::def_id)) {
for each_path(intr, cdata, get_crate_data) |path_string, def_like| {
match def_like {
dl_impl(*) | dl_field => {}

View File

@ -1054,7 +1054,7 @@ fn create_index<T:Copy + Hash + IterBytes>(index: ~[entry<T>]) ->
}
fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
write_fn: fn(io::Writer, T)) {
write_fn: &fn(io::Writer, T)) {
let writer = ebml_w.writer;
ebml_w.start_tag(tag_index);
let mut bucket_locs: ~[uint] = ~[];

View File

@ -217,7 +217,7 @@ fn parse_region(st: @mut PState) -> ty::Region {
}
}
fn parse_opt<T>(st: @mut PState, f: fn() -> T) -> Option<T> {
fn parse_opt<T>(st: @mut PState, f: &fn() -> T) -> Option<T> {
match next(st) {
'n' => None,
's' => Some(f()),

View File

@ -122,7 +122,7 @@ fn enc_mt(w: io::Writer, cx: @ctxt, mt: ty::mt) {
enc_ty(w, cx, mt.ty);
}
fn enc_opt<T>(w: io::Writer, t: Option<T>, enc_f: fn(T)) {
fn enc_opt<T>(w: io::Writer, t: Option<T>, enc_f: &fn(T)) {
match &t {
&None => w.write_char('n'),
&Some(ref v) => {

View File

@ -795,12 +795,12 @@ impl ebml_writer_helpers for writer::Encoder {
}
trait write_tag_and_id {
fn tag(&self, tag_id: c::astencode_tag, f: fn());
fn tag(&self, tag_id: c::astencode_tag, f: &fn());
fn id(&self, id: ast::node_id);
}
impl write_tag_and_id for writer::Encoder {
fn tag(&self, tag_id: c::astencode_tag, f: fn()) {
fn tag(&self, tag_id: c::astencode_tag, f: &fn()) {
do self.wr_tag(tag_id as uint) { f() }
}

View File

@ -510,7 +510,7 @@ pub impl BorrowckCtxt {
method_map: self.method_map}
}
fn cat_pattern(&self, cmt: cmt, pat: @ast::pat, op: fn(cmt, @ast::pat)) {
fn cat_pattern(&self, cmt: cmt, pat: @ast::pat, op: &fn(cmt, @ast::pat)) {
let mc = self.mc_ctxt();
mc.cat_pattern(cmt, pat, op);
}

View File

@ -95,7 +95,7 @@ type check_fn = @fn(Context, @freevar_entry);
// Yields the appropriate function to check the kind of closed over
// variables. `id` is the node_id for some expression that creates the
// closure.
fn with_appropriate_checker(cx: Context, id: node_id, b: fn(check_fn)) {
fn with_appropriate_checker(cx: Context, id: node_id, b: &fn(check_fn)) {
fn check_for_uniq(cx: Context, fv: @freevar_entry) {
// all captured data must be owned, regardless of whether it is
// moved in or copied in.

View File

@ -77,6 +77,7 @@ pub enum lint {
default_methods,
deprecated_self,
deprecated_mutable_fields,
deprecated_drop,
managed_heap_memory,
owned_heap_memory,
@ -251,6 +252,13 @@ pub fn get_lint_dict() -> LintDict {
default: deny
}),
(@~"deprecated_drop",
@LintSpec {
lint: deprecated_drop,
desc: "deprecated \"drop\" notation for the destructor",
default: deny
}),
/* FIXME(#3266)--make liveness warnings lintable
(@~"unused_variable",
@LintSpec {
@ -342,7 +350,7 @@ pub impl Context {
* current lint context, call the provided function, then reset the
* lints in effect to their previous state.
*/
fn with_lint_attrs(&self, attrs: ~[ast::attribute], f: fn(Context)) {
fn with_lint_attrs(&self, attrs: ~[ast::attribute], f: &fn(Context)) {
let mut new_ctxt = *self;
let mut triples = ~[];
@ -483,6 +491,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
check_item_default_methods(cx, i);
check_item_deprecated_self(cx, i);
check_item_deprecated_mutable_fields(cx, i);
check_item_deprecated_drop(cx, i);
}
// Take a visitor, and modify it so that it will not proceed past subitems.
@ -720,6 +729,26 @@ fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
}
}
fn check_item_deprecated_drop(cx: ty::ctxt, item: @ast::item) {
match item.node {
ast::item_struct(struct_def, _) => {
match struct_def.dtor {
None => {}
Some(ref dtor) => {
cx.sess.span_lint(deprecated_drop,
item.id,
item.id,
dtor.span,
~"`drop` notation for destructors is \
deprecated; implement the `Drop` \
trait instead");
}
}
}
_ => {}
}
}
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,

View File

@ -137,8 +137,8 @@ use syntax::{visit, ast_util};
// if it detects an outstanding loan (that is, the addr is taken).
pub type last_use_map = HashMap<node_id, @mut ~[node_id]>;
enum Variable = uint;
enum LiveNode = uint;
struct Variable(uint);
struct LiveNode(uint);
impl cmp::Eq for Variable {
pure fn eq(&self, other: &Variable) -> bool { *(*self) == *(*other) }
@ -735,7 +735,7 @@ pub impl Liveness {
}
}
fn pat_bindings(&self, pat: @pat, f: fn(LiveNode, Variable, span)) {
fn pat_bindings(&self, pat: @pat, f: &fn(LiveNode, Variable, span)) {
let def_map = self.tcx.def_map;
do pat_util::pat_bindings(def_map, pat) |_bm, p_id, sp, _n| {
let ln = self.live_node(p_id, sp);
@ -745,7 +745,7 @@ pub impl Liveness {
}
fn arm_pats_bindings(&self,
pats: &[@pat], f: fn(LiveNode, Variable, span)) {
pats: &[@pat], f: &fn(LiveNode, Variable, span)) {
// only consider the first pattern; any later patterns must have
// the same bindings, and we also consider the first pattern to be
// the "authoratative" set of ids
@ -809,15 +809,14 @@ pub impl Liveness {
self.assigned_on_entry(copy self.successors[*ln], var)
}
fn indices(&self, ln: LiveNode, op: fn(uint)) {
fn indices(&self, ln: LiveNode, op: &fn(uint)) {
let node_base_idx = self.idx(ln, Variable(0));
for uint::range(0, self.ir.num_vars) |var_idx| {
op(node_base_idx + var_idx)
}
}
fn indices2(&self, ln: LiveNode, succ_ln: LiveNode,
op: fn(uint, uint)) {
fn indices2(&self, ln: LiveNode, succ_ln: LiveNode, op: &fn(uint, uint)) {
let node_base_idx = self.idx(ln, Variable(0u));
let succ_base_idx = self.idx(succ_ln, Variable(0u));
for uint::range(0u, self.ir.num_vars) |var_idx| {
@ -827,7 +826,7 @@ pub impl Liveness {
fn write_vars(&self, wr: io::Writer,
ln: LiveNode,
test: fn(uint) -> LiveNode) {
test: &fn(uint) -> LiveNode) {
let node_base_idx = self.idx(ln, Variable(0));
for uint::range(0, self.ir.num_vars) |var_idx| {
let idx = node_base_idx + var_idx;
@ -1510,7 +1509,7 @@ pub impl Liveness {
fn with_loop_nodes<R>(&self, loop_node_id: node_id,
break_ln: LiveNode,
cont_ln: LiveNode,
f: fn() -> R) -> R {
f: &fn() -> R) -> R {
debug!("with_loop_nodes: %d %u", loop_node_id, *break_ln);
self.loop_scope.push(loop_node_id);
self.break_ln.insert(loop_node_id, break_ln);

View File

@ -856,7 +856,7 @@ pub impl mem_categorization_ctxt {
fn cat_pattern(&self,
cmt: cmt,
pat: @ast::pat,
op: fn(cmt, @ast::pat))
op: &fn(cmt, @ast::pat))
{
// Here, `cmt` is the categorization for the value being
// matched and pat is the pattern it is being matched against.

View File

@ -72,7 +72,7 @@ pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @pat) -> bool {
}
pub fn pat_bindings(dm: resolve::DefMap, pat: @pat,
it: fn(binding_mode, node_id, span, @path)) {
it: &fn(binding_mode, node_id, span, @path)) {
do walk_pat(pat) |p| {
match p.node {
pat_ident(binding_mode, pth, _) if pat_is_binding(dm, p) => {

View File

@ -3241,7 +3241,7 @@ pub impl Resolver {
// generate a fake "implementation scope" containing all the
// implementations thus found, for compatibility with old resolve pass.
fn with_scope(@mut self, name: Option<ident>, f: fn()) {
fn with_scope(@mut self, name: Option<ident>, f: &fn()) {
let orig_module = self.current_module;
// Move down in the graph.
@ -3661,7 +3661,7 @@ pub impl Resolver {
fn with_type_parameter_rib(@mut self,
type_parameters: TypeParameters,
f: fn()) {
f: &fn()) {
match type_parameters {
HasTypeParameters(generics, node_id, initial_index,
rib_kind) => {
@ -3702,13 +3702,13 @@ pub impl Resolver {
}
}
fn with_label_rib(@mut self, f: fn()) {
fn with_label_rib(@mut self, f: &fn()) {
self.label_ribs.push(@Rib(NormalRibKind));
f();
self.label_ribs.pop();
}
fn with_constant_rib(@mut self, f: fn()) {
fn with_constant_rib(@mut self, f: &fn()) {
self.value_ribs.push(@Rib(ConstantItemRibKind));
f();
self.value_ribs.pop();

View File

@ -728,8 +728,8 @@ pub fn cast_shift_const_rhs(op: ast::binop,
pub fn cast_shift_rhs(op: ast::binop,
lhs: ValueRef, rhs: ValueRef,
trunc: fn(ValueRef, TypeRef) -> ValueRef,
zext: fn(ValueRef, TypeRef) -> ValueRef)
trunc: &fn(ValueRef, TypeRef) -> ValueRef,
zext: &fn(ValueRef, TypeRef) -> ValueRef)
-> ValueRef {
// Shifts may have any size int on the rhs
unsafe {
@ -863,7 +863,7 @@ pub fn have_cached_lpad(bcx: block) -> bool {
return res;
}
pub fn in_lpad_scope_cx(bcx: block, f: fn(+si: &mut scope_info)) {
pub fn in_lpad_scope_cx(bcx: block, f: &fn(+si: &mut scope_info)) {
let mut bcx = bcx;
loop {
{
@ -1326,7 +1326,7 @@ pub fn leave_block(bcx: block, out_of: block) -> block {
pub fn with_scope(bcx: block,
opt_node_info: Option<NodeInfo>,
+name: ~str,
f: fn(block) -> block) -> block {
f: &fn(block) -> block) -> block {
let _icx = bcx.insn_ctxt("with_scope");
debug!("with_scope(bcx=%s, opt_node_info=%?, name=%s)",
@ -1341,7 +1341,7 @@ pub fn with_scope(bcx: block,
pub fn with_scope_result(bcx: block,
opt_node_info: Option<NodeInfo>,
+name: ~str,
f: fn(block) -> Result) -> Result {
f: &fn(block) -> Result) -> Result {
let _icx = bcx.insn_ctxt("with_scope_result");
let scope_cx = scope_block(bcx, opt_node_info, name);
Br(bcx, scope_cx.llbb);
@ -1350,7 +1350,7 @@ pub fn with_scope_result(bcx: block,
}
pub fn with_scope_datumblock(bcx: block, opt_node_info: Option<NodeInfo>,
+name: ~str, f: fn(block) -> datum::DatumBlock)
+name: ~str, f: &fn(block) -> datum::DatumBlock)
-> datum::DatumBlock {
use middle::trans::datum::DatumBlock;
@ -1361,7 +1361,7 @@ pub fn with_scope_datumblock(bcx: block, opt_node_info: Option<NodeInfo>,
DatumBlock {bcx: leave_block(bcx, scope_cx), datum: datum}
}
pub fn block_locals(b: &ast::blk, it: fn(@ast::local)) {
pub fn block_locals(b: &ast::blk, it: &fn(@ast::local)) {
for vec::each(b.node.stmts) |s| {
match s.node {
ast::stmt_decl(d, _) => {
@ -1401,7 +1401,7 @@ pub fn alloc_local(cx: block, local: @ast::local) -> block {
}
pub fn with_cond(bcx: block, val: ValueRef, f: fn(block) -> block) -> block {
pub fn with_cond(bcx: block, val: ValueRef, f: &fn(block) -> block) -> block {
let _icx = bcx.insn_ctxt("with_cond");
let next_cx = base::sub_block(bcx, ~"next");
let cond_cx = base::sub_block(bcx, ~"cond");
@ -1742,8 +1742,8 @@ pub fn trans_closure(ccx: @CrateContext,
param_substs: Option<@param_substs>,
id: ast::node_id,
impl_id: Option<ast::def_id>,
maybe_load_env: fn(fn_ctxt),
finish: fn(block)) {
maybe_load_env: &fn(fn_ctxt),
finish: &fn(block)) {
ccx.stats.n_closures += 1;
let _icx = ccx.insn_ctxt("trans_closure");
set_uwtable(llfndecl);

View File

@ -37,7 +37,7 @@ pub struct FnType {
}
pub impl FnType {
fn decl_fn(&self, decl: fn(fnty: TypeRef) -> ValueRef) -> ValueRef {
fn decl_fn(&self, decl: &fn(fnty: TypeRef) -> ValueRef) -> ValueRef {
let atys = vec::map(self.arg_tys, |t| t.ty);
let rty = self.ret_ty.ty;
let fnty = T_fn(atys, rty);

View File

@ -346,7 +346,7 @@ fn x86_64_tys(atys: &[TypeRef],
}
fn x86_64_ty(ty: TypeRef,
is_mem_cls: fn(cls: &[x86_64_reg_class]) -> bool,
is_mem_cls: &fn(cls: &[x86_64_reg_class]) -> bool,
attr: Attribute) -> (LLVMType, Option<Attribute>) {
let mut cast = false;
let mut ty_attr = option::None;

View File

@ -438,7 +438,7 @@ pub fn trans_call_inner(
call_info: Option<NodeInfo>,
fn_expr_ty: ty::t,
ret_ty: ty::t,
get_callee: fn(block) -> Callee,
get_callee: &fn(block) -> Callee,
args: CallArgs,
dest: expr::Dest,
autoref_arg: AutorefArg) -> block {

View File

@ -515,7 +515,7 @@ pub impl Datum {
fn get_element(&self, bcx: block,
ty: ty::t,
source: DatumCleanup,
gep: fn(ValueRef) -> ValueRef) -> Datum {
gep: &fn(ValueRef) -> ValueRef) -> Datum {
let base_val = self.to_ref_llval(bcx);
Datum {
val: gep(base_val),

View File

@ -190,7 +190,7 @@ fn md_from_metadata<T>(val: debug_metadata) -> T {
fn cached_metadata<T:Copy>(cache: metadata_cache,
mdtag: int,
eq_fn: fn(md: T) -> bool)
eq_fn: &fn(md: T) -> bool)
-> Option<T> {
unsafe {
if cache.contains_key(&mdtag) {

View File

@ -1135,7 +1135,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
pub fn with_field_tys<R>(tcx: ty::ctxt,
ty: ty::t,
node_id_opt: Option<ast::node_id>,
op: fn(int, (&[ty::field])) -> R) -> R {
op: &fn(int, (&[ty::field])) -> R) -> R {
match ty::get(ty).sty {
ty::ty_struct(did, ref substs) => {
op(0, struct_mutable_fields(tcx, did, substs))

View File

@ -582,18 +582,20 @@ pub enum param_bound {
}
#[deriving_eq]
pub enum TyVid = uint;
pub struct TyVid(uint);
#[deriving_eq]
pub enum IntVid = uint;
pub struct IntVid(uint);
#[deriving_eq]
pub enum FloatVid = uint;
pub struct FloatVid(uint);
#[deriving_eq]
#[auto_encode]
#[auto_decode]
pub enum RegionVid = uint;
pub struct RegionVid {
id: uint
}
#[deriving_eq]
pub enum InferTy {
@ -687,11 +689,11 @@ impl ToStr for FloatVid {
}
impl Vid for RegionVid {
pure fn to_uint(&self) -> uint { **self }
pure fn to_uint(&self) -> uint { self.id }
}
impl ToStr for RegionVid {
pure fn to_str(&self) -> ~str { fmt!("%?", self) }
pure fn to_str(&self) -> ~str { fmt!("%?", self.id) }
}
impl ToStr for FnSig {
@ -1138,11 +1140,11 @@ pub fn encl_region(cx: ctxt, id: ast::node_id) -> ty::Region {
}
}
pub fn walk_ty(ty: t, f: fn(t)) {
pub fn walk_ty(ty: t, f: &fn(t)) {
maybe_walk_ty(ty, |t| { f(t); true });
}
pub fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
pub fn maybe_walk_ty(ty: t, f: &fn(t) -> bool) {
if !f(ty) { return; }
match /*bad*/copy get(ty).sty {
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
@ -1170,11 +1172,11 @@ pub fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
}
}
pub fn fold_sty_to_ty(tcx: ty::ctxt, sty: &sty, foldop: fn(t) -> t) -> t {
pub fn fold_sty_to_ty(tcx: ty::ctxt, sty: &sty, foldop: &fn(t) -> t) -> t {
mk_t(tcx, fold_sty(sty, foldop))
}
pub fn fold_sig(sig: &FnSig, fldop: fn(t) -> t) -> FnSig {
pub fn fold_sig(sig: &FnSig, fldop: &fn(t) -> t) -> FnSig {
let args = do sig.inputs.map |arg| {
arg { mode: arg.mode, ty: fldop(arg.ty) }
};
@ -1185,8 +1187,8 @@ pub fn fold_sig(sig: &FnSig, fldop: fn(t) -> t) -> FnSig {
}
}
fn fold_sty(sty: &sty, fldop: fn(t) -> t) -> sty {
fn fold_substs(substs: &substs, fldop: fn(t) -> t) -> substs {
fn fold_sty(sty: &sty, fldop: &fn(t) -> t) -> sty {
fn fold_substs(substs: &substs, fldop: &fn(t) -> t) -> substs {
substs {self_r: substs.self_r,
self_ty: substs.self_ty.map(|t| fldop(*t)),
tps: substs.tps.map(|t| fldop(*t))}
@ -1241,7 +1243,7 @@ fn fold_sty(sty: &sty, fldop: fn(t) -> t) -> sty {
}
// Folds types from the bottom up.
pub fn fold_ty(cx: ctxt, t0: t, fldop: fn(t) -> t) -> t {
pub fn fold_ty(cx: ctxt, t0: t, fldop: &fn(t) -> t) -> t {
let sty = fold_sty(&get(t0).sty, |t| fold_ty(cx, fldop(t), fldop));
fldop(mk_t(cx, sty))
}
@ -1249,8 +1251,8 @@ pub fn fold_ty(cx: ctxt, t0: t, fldop: fn(t) -> t) -> t {
pub fn walk_regions_and_ty(
cx: ctxt,
ty: t,
walkr: fn(r: Region),
walkt: fn(t: t) -> bool) {
walkr: &fn(r: Region),
walkt: &fn(t: t) -> bool) {
if (walkt(ty)) {
fold_regions_and_ty(
@ -1264,14 +1266,14 @@ pub fn walk_regions_and_ty(
pub fn fold_regions_and_ty(
cx: ctxt,
ty: t,
fldr: fn(r: Region) -> Region,
fldfnt: fn(t: t) -> t,
fldt: fn(t: t) -> t) -> t {
fldr: &fn(r: Region) -> Region,
fldfnt: &fn(t: t) -> t,
fldt: &fn(t: t) -> t) -> t {
fn fold_substs(
substs: &substs,
fldr: fn(r: Region) -> Region,
fldt: fn(t: t) -> t)
fldr: &fn(r: Region) -> Region,
fldt: &fn(t: t) -> t)
-> substs {
substs {
self_r: substs.self_r.map(|r| fldr(*r)),
@ -1325,9 +1327,9 @@ pub fn fold_regions_and_ty(
pub fn fold_regions(
cx: ctxt,
ty: t,
fldr: fn(r: Region, in_fn: bool) -> Region) -> t {
fldr: &fn(r: Region, in_fn: bool) -> Region) -> t {
fn do_fold(cx: ctxt, ty: t, in_fn: bool,
fldr: fn(Region, bool) -> Region) -> t {
fldr: &fn(Region, bool) -> Region) -> t {
debug!("do_fold(ty=%s, in_fn=%b)", ty_to_str(cx, ty), in_fn);
if !type_has_regions(ty) { return ty; }
fold_regions_and_ty(
@ -2274,7 +2276,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
pub fn type_structurally_contains(cx: ctxt,
ty: t,
test: fn(x: &sty) -> bool)
test: &fn(x: &sty) -> bool)
-> bool {
let sty = &get(ty).sty;
debug!("type_structurally_contains: %s",
@ -4008,7 +4010,7 @@ pub fn struct_fields(cx: ctxt,
fn struct_item_fields(cx:ctxt,
did: ast::def_id,
substs: &substs,
frob_mutability: fn(struct_mutability) -> mutability)
frob_mutability: &fn(struct_mutability) -> mutability)
-> ~[field] {
do lookup_struct_fields(cx, did).map |f| {
// consider all instance vars mut, because the

View File

@ -36,7 +36,7 @@
* scopes and (b) the default region may change. To understand case (a),
* consider something like:
*
* type foo = { x: &a.int, y: fn(&a.int) }
* type foo = { x: &a.int, y: &fn(&a.int) }
*
* The type of `x` is an error because there is no region `a` in scope.
* In the type of `y`, however, region `a` is considered a bound region
@ -224,7 +224,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>(
rscope: &RS,
a_seq_ty: ast::mt,
vst: ty::vstore,
constr: fn(ty::mt) -> ty::t) -> ty::t
constr: &fn(ty::mt) -> ty::t) -> ty::t
{
let tcx = self.tcx();

View File

@ -33,7 +33,7 @@ pub fn subtype(fcx: @mut FnCtxt, sp: span, expected: ty::t, actual: ty::t) {
pub fn suptype_with_fn(fcx: @mut FnCtxt,
sp: span, b_is_expected: bool,
ty_a: ty::t, ty_b: ty::t,
handle_err: fn(span, ty::t, ty::t, &ty::type_err)) {
handle_err: &fn(span, ty::t, ty::t, &ty::type_err)) {
// n.b.: order of actual, expected is reversed
match infer::mk_subty(fcx.infcx(), b_is_expected, sp,
ty_b, ty_a) {

View File

@ -105,6 +105,12 @@ use syntax::ast::{m_const, m_mutbl, m_imm};
use syntax::ast;
use syntax::ast_map;
#[deriving_eq]
pub enum CheckTraitsFlag {
CheckTraitsOnly,
CheckTraitsAndInherentMethods,
}
pub fn lookup(
fcx: @mut FnCtxt,
@ -115,7 +121,8 @@ pub fn lookup(
m_name: ast::ident, // The ident `b`.
self_ty: ty::t, // The type of `a`.
supplied_tps: &[ty::t], // The list of types X, Y, ... .
deref_args: check::DerefArgs) // Whether we autopointer first.
deref_args: check::DerefArgs, // Whether we autopointer first.
check_traits: CheckTraitsFlag) // Whether we check traits only.
-> Option<method_map_entry>
{
let lcx = LookupContext {
@ -129,6 +136,7 @@ pub fn lookup(
inherent_candidates: @mut ~[],
extension_candidates: @mut ~[],
deref_args: deref_args,
check_traits: check_traits,
};
let mme = lcx.do_lookup(self_ty);
debug!("method lookup for %s yielded %?",
@ -147,6 +155,7 @@ pub struct LookupContext {
inherent_candidates: @mut ~[Candidate],
extension_candidates: @mut ~[Candidate],
deref_args: check::DerefArgs,
check_traits: CheckTraitsFlag,
}
/**
@ -299,8 +308,10 @@ pub impl LookupContext/&self {
self_ty, self_did, &substs);
}
ty_enum(did, _) | ty_struct(did, _) => {
if self.check_traits == CheckTraitsAndInherentMethods {
self.push_inherent_impl_candidates_for_type(did);
}
}
_ => { /* No inherent methods in these types */ }
}

View File

@ -89,7 +89,8 @@ use middle::typeck::astconv::{AstConv, ast_path_to_ty};
use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty};
use middle::typeck::astconv;
use middle::typeck::check::_match::pat_ctxt;
use middle::typeck::check::method::TransformTypeNormally;
use middle::typeck::check::method::{CheckTraitsAndInherentMethods};
use middle::typeck::check::method::{CheckTraitsOnly, TransformTypeNormally};
use middle::typeck::check::regionmanip::replace_bound_regions_in_fn_sig;
use middle::typeck::check::vtable::{LocationInfo, VtableContext};
use middle::typeck::CrateCtxt;
@ -1142,7 +1143,7 @@ pub fn break_here() {
pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
expr: @ast::expr,
expected: Option<ty::t>,
unifier: fn()) -> bool {
unifier: &fn()) -> bool {
debug!(">> typechecking %s", fcx.expr_to_str(expr));
// A generic function to factor out common logic from call and
@ -1371,7 +1372,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
method_name,
expr_t,
tps,
DontDerefArgs) {
DontDerefArgs,
CheckTraitsAndInherentMethods) {
Some(ref entry) => {
let method_map = fcx.ccx.method_map;
method_map.insert(expr.id, (*entry));
@ -1453,9 +1455,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
+args: ~[@ast::expr],
+deref_args: DerefArgs)
-> Option<(ty::t, bool)> {
match method::lookup(fcx, op_ex, self_ex,
op_ex.callee_id, opname, self_t, ~[],
deref_args) {
match method::lookup(fcx,
op_ex,
self_ex,
op_ex.callee_id,
opname,
self_t,
~[],
deref_args,
CheckTraitsOnly) {
Some(ref origin) => {
let method_ty = fcx.node_ty(op_ex.callee_id);
let method_map = fcx.ccx.method_map;
@ -1602,7 +1610,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
// returns `none`.
fn unpack_expected<O:Copy>(fcx: @mut FnCtxt,
expected: Option<ty::t>,
unpack: fn(&ty::sty) -> Option<O>)
unpack: &fn(&ty::sty) -> Option<O>)
-> Option<O> {
match expected {
Some(t) => {
@ -1732,7 +1740,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
field,
expr_t,
tps,
DontDerefArgs) {
DontDerefArgs,
CheckTraitsAndInherentMethods) {
Some(ref entry) => {
let method_map = fcx.ccx.method_map;
method_map.insert(expr.id, (*entry));

View File

@ -30,7 +30,7 @@ pub fn replace_bound_regions_in_fn_sig(
isr: isr_alist,
self_info: Option<SelfInfo>,
fn_sig: &ty::FnSig,
mapf: fn(ty::bound_region) -> ty::Region) ->
mapf: &fn(ty::bound_region) -> ty::Region) ->
(isr_alist, Option<SelfInfo>, ty::FnSig) {
// Take self_info apart; the self_ty part is the only one we want
// to update here.
@ -96,7 +96,7 @@ pub fn replace_bound_regions_in_fn_sig(
tcx: ty::ctxt,
isr: isr_alist,
tys: ~[ty::t],
to_r: fn(ty::bound_region) -> ty::Region) -> isr_alist {
to_r: &fn(ty::bound_region) -> ty::Region) -> isr_alist {
// Takes `isr` (described above), `to_r` (described above),
// and `r`, a region. If `r` is anything other than a bound
@ -106,7 +106,7 @@ pub fn replace_bound_regions_in_fn_sig(
// updated isr_alist that now contains a mapping from `r` to
// the result of calling `to_r` on it.
fn append_isr(isr: isr_alist,
to_r: fn(ty::bound_region) -> ty::Region,
to_r: &fn(ty::bound_region) -> ty::Region,
r: ty::Region) -> isr_alist {
match r {
ty::re_free(_, _) | ty::re_static | ty::re_scope(_) |

View File

@ -84,7 +84,7 @@ use syntax::ast;
// Note: Coerce is not actually a combiner, in that it does not
// conform to the same interface, though it performs a similar
// function.
pub enum Coerce = CombineFields;
pub struct Coerce(CombineFields);
pub impl Coerce {
fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult {

View File

@ -29,7 +29,7 @@ use util::ppaux::mt_to_str;
use std::list;
pub enum Glb = CombineFields; // "greatest lower bound" (common subtype)
pub struct Glb(CombineFields); // "greatest lower bound" (common subtype)
impl Combine for Glb {
fn infcx(&self) -> @mut InferCtxt { self.infcx }
@ -228,7 +228,7 @@ impl Combine for Glb {
// NB---I do not believe this algorithm computes
// (necessarily) the GLB. As written it can
// spuriously fail. In particular, if there is a case
// like: fn(fn(&a)) and fn(fn(&b)), where a and b are
// like: &fn(fn(&a)) and fn(fn(&b)), where a and b are
// free, it will return fn(&c) where c = GLB(a,b). If
// however this GLB is not defined, then the result is
// an error, even though something like

View File

@ -29,7 +29,7 @@ use syntax::ast::{pure_fn, ret_style, return_val, unsafe_fn};
use syntax::ast::{Onceness, purity};
use syntax::codemap::span;
pub enum Lub = CombineFields; // least-upper-bound: common supertype
pub struct Lub(CombineFields); // least-upper-bound: common supertype
pub impl Lub {
fn bot_ty(&self, b: ty::t) -> cres<ty::t> { Ok(b) }

View File

@ -481,12 +481,12 @@ fn resolve_borrowings(cx: @mut InferCtxt) {
*/
trait then {
fn then<T:Copy>(&self, f: fn() -> Result<T,ty::type_err>)
fn then<T:Copy>(&self, f: &fn() -> Result<T,ty::type_err>)
-> Result<T,ty::type_err>;
}
impl then for ures {
fn then<T:Copy>(&self, f: fn() -> Result<T,ty::type_err>)
fn then<T:Copy>(&self, f: &fn() -> Result<T,ty::type_err>)
-> Result<T,ty::type_err> {
self.chain(|_i| f())
}
@ -506,11 +506,11 @@ impl<T> ToUres for cres<T> {
}
trait CresCompare<T> {
fn compare(&self, t: T, f: fn() -> ty::type_err) -> cres<T>;
fn compare(&self, t: T, f: &fn() -> ty::type_err) -> cres<T>;
}
impl<T:Copy + Eq> CresCompare<T> for cres<T> {
fn compare(&self, t: T, f: fn() -> ty::type_err) -> cres<T> {
fn compare(&self, t: T, f: &fn() -> ty::type_err) -> cres<T> {
do self.chain |s| {
if s == t {
*self
@ -584,7 +584,7 @@ pub impl @mut InferCtxt {
}
/// Execute `f` and commit the bindings if successful
fn commit<T,E>(&self, f: fn() -> Result<T,E>) -> Result<T,E> {
fn commit<T,E>(&self, f: &fn() -> Result<T,E>) -> Result<T,E> {
fail_unless!(!self.in_snapshot());
debug!("commit()");
@ -599,7 +599,7 @@ pub impl @mut InferCtxt {
}
/// Execute `f`, unroll bindings on failure
fn try<T,E>(&self, f: fn() -> Result<T,E>) -> Result<T,E> {
fn try<T,E>(&self, f: &fn() -> Result<T,E>) -> Result<T,E> {
debug!("try()");
do indent {
let snapshot = self.start_snapshot();
@ -613,7 +613,7 @@ pub impl @mut InferCtxt {
}
/// Execute `f` then unroll any bindings it creates
fn probe<T,E>(&self, f: fn() -> Result<T,E>) -> Result<T,E> {
fn probe<T,E>(&self, f: &fn() -> Result<T,E>) -> Result<T,E> {
debug!("probe()");
do indent {
let snapshot = self.start_snapshot();
@ -706,7 +706,7 @@ pub impl @mut InferCtxt {
}
}
fn type_error_message(&self, sp: span, mk_msg: fn(~str) -> ~str,
fn type_error_message(&self, sp: span, mk_msg: &fn(~str) -> ~str,
actual_ty: ty::t, err: Option<&ty::type_err>) {
let actual_ty = self.resolve_type_vars_if_possible(actual_ty);

View File

@ -153,7 +153,7 @@ The problem we are addressing is that there is a kind of subtyping
between functions with bound region parameters. Consider, for
example, whether the following relation holds:
fn(&a/int) <: fn(&b/int)? (Yes, a => b)
fn(&a/int) <: &fn(&b/int)? (Yes, a => b)
The answer is that of course it does. These two types are basically
the same, except that in one we used the name `a` and one we used
@ -170,7 +170,7 @@ Now let's consider two more function types. Here, we assume that the
`self` lifetime is defined somewhere outside and hence is not a
lifetime parameter bound by the function type (it "appears free"):
fn<a>(&a/int) <: fn(&self/int)? (Yes, a => self)
fn<a>(&a/int) <: &fn(&self/int)? (Yes, a => self)
This subtyping relation does in fact hold. To see why, you have to
consider what subtyping means. One way to look at `T1 <: T2` is to
@ -187,7 +187,7 @@ to the same thing: a function that accepts pointers with any lifetime
So, what if we reverse the order of the two function types, like this:
fn(&self/int) <: fn<a>(&a/int)? (No)
fn(&self/int) <: &fn<a>(&a/int)? (No)
Does the subtyping relationship still hold? The answer of course is
no. In this case, the function accepts *only the lifetime `&self`*,
@ -196,8 +196,8 @@ accepted any lifetime.
What about these two examples:
fn<a,b>(&a/int, &b/int) <: fn<a>(&a/int, &a/int)? (Yes)
fn<a>(&a/int, &a/int) <: fn<a,b>(&a/int, &b/int)? (No)
fn<a,b>(&a/int, &b/int) <: &fn<a>(&a/int, &a/int)? (Yes)
fn<a>(&a/int, &a/int) <: &fn<a,b>(&a/int, &b/int)? (No)
Here, it is true that functions which take two pointers with any two
lifetimes can be treated as if they only accepted two pointers with
@ -221,12 +221,12 @@ Let's walk through some examples and see how this algorithm plays out.
We'll start with the first example, which was:
1. fn<a>(&a/T) <: fn<b>(&b/T)? Yes: a -> b
1. fn<a>(&a/T) <: &fn<b>(&b/T)? Yes: a -> b
After steps 1 and 2 of the algorithm we will have replaced the types
like so:
1. fn(&A/T) <: fn(&x/T)?
1. fn(&A/T) <: &fn(&x/T)?
Here the upper case `&A` indicates a *region variable*, that is, a
region whose value is being inferred by the system. I also replaced
@ -255,12 +255,12 @@ So far we have encountered no error, so the subtype check succeeds.
Now let's look first at the third example, which was:
3. fn(&self/T) <: fn<b>(&b/T)? No!
3. fn(&self/T) <: &fn<b>(&b/T)? No!
After steps 1 and 2 of the algorithm we will have replaced the types
like so:
3. fn(&self/T) <: fn(&x/T)?
3. fn(&self/T) <: &fn(&x/T)?
This looks pretty much the same as before, except that on the LHS
`&self` was not bound, and hence was left as-is and not replaced with
@ -275,7 +275,7 @@ You may be wondering about that mysterious last step in the algorithm.
So far it has not been relevant. The purpose of that last step is to
catch something like *this*:
fn<a>() -> fn(&a/T) <: fn() -> fn<b>(&b/T)? No.
fn<a>() -> fn(&a/T) <: &fn() -> fn<b>(&b/T)? No.
Here the function types are the same but for where the binding occurs.
The subtype returns a function that expects a value in precisely one
@ -289,15 +289,15 @@ So let's step through what happens when we perform this subtype check.
We first replace the bound regions in the subtype (the supertype has
no bound regions). This gives us:
fn() -> fn(&A/T) <: fn() -> fn<b>(&b/T)?
fn() -> fn(&A/T) <: &fn() -> fn<b>(&b/T)?
Now we compare the return types, which are covariant, and hence we have:
fn(&A/T) <: fn<b>(&b/T)?
fn(&A/T) <: &fn<b>(&b/T)?
Here we skolemize the bound region in the supertype to yield:
fn(&A/T) <: fn(&x/T)?
fn(&A/T) <: &fn(&x/T)?
And then proceed to compare the argument types:
@ -314,7 +314,7 @@ The difference between this example and the first one is that the variable
`A` already existed at the point where the skolemization occurred. In
the first example, you had two functions:
fn<a>(&a/T) <: fn<b>(&b/T)
fn<a>(&a/T) <: &fn<b>(&b/T)
and hence `&A` and `&x` were created "together". In general, the
intention of the skolemized names is that they are supposed to be
@ -700,7 +700,7 @@ pub impl RegionVarBindings {
match undo_item {
Snapshot => {}
AddVar(vid) => {
fail_unless!(self.var_spans.len() == *vid + 1);
fail_unless!(self.var_spans.len() == vid.to_uint() + 1);
self.var_spans.pop();
}
AddConstraint(ref constraint) => {
@ -720,7 +720,7 @@ pub impl RegionVarBindings {
fn new_region_var(&mut self, span: span) -> RegionVid {
let id = self.num_vars();
self.var_spans.push(span);
let vid = RegionVid(id);
let vid = RegionVid { id: id };
if self.in_snapshot() {
self.undo_log.push(AddVar(vid));
}
@ -863,15 +863,15 @@ pub impl RegionVarBindings {
}
fn resolve_var(&mut self, rid: RegionVid) -> ty::Region {
debug!("RegionVarBindings: resolve_var(%?=%u)", rid, *rid);
debug!("RegionVarBindings: resolve_var(%?=%u)", rid, rid.to_uint());
if self.values.is_empty() {
self.tcx.sess.span_bug(
self.var_spans[*rid],
self.var_spans[rid.to_uint()],
fmt!("Attempt to resolve region variable before values have \
been computed!"));
}
let v = self.values.with_ref(|values| values[*rid]);
let v = self.values.with_ref(|values| values[rid.to_uint()]);
match v {
Value(r) => r,
@ -886,13 +886,13 @@ pub impl RegionVarBindings {
// should ultimately have some bounds.
self.tcx.sess.span_err(
self.var_spans[*rid],
fmt!("Unconstrained region variable #%u", *rid));
self.var_spans[rid.to_uint()],
fmt!("Unconstrained region variable #%u", rid.to_uint()));
// Touch of a hack: to suppress duplicate messages,
// replace the NoValue entry with ErrorValue.
let mut values = self.values.take();
values[*rid] = ErrorValue;
values[rid.to_uint()] = ErrorValue;
self.values.put_back(values);
re_static
}
@ -1049,7 +1049,7 @@ priv impl RegionVarBindings {
(re_infer(ReVar(v_id)), _) | (_, re_infer(ReVar(v_id))) => {
self.tcx.sess.span_bug(
self.var_spans[*v_id],
self.var_spans[v_id.to_uint()],
fmt!("lub_concrete_regions invoked with \
non-concrete regions: %?, %?", a, b));
}
@ -1111,7 +1111,7 @@ priv impl RegionVarBindings {
(re_infer(ReVar(v_id)), _) |
(_, re_infer(ReVar(v_id))) => {
self.tcx.sess.span_bug(
self.var_spans[*v_id],
self.var_spans[v_id.to_uint()],
fmt!("glb_concrete_regions invoked with \
non-concrete regions: %?, %?", a, b));
}
@ -1275,8 +1275,8 @@ pub impl RegionVarBindings {
edge_idx: uint) {
let edge_dir = edge_dir as uint;
graph.edges[edge_idx].next_edge[edge_dir] =
graph.nodes[*node_id].head_edge[edge_dir];
graph.nodes[*node_id].head_edge[edge_dir] =
graph.nodes[node_id.to_uint()].head_edge[edge_dir];
graph.nodes[node_id.to_uint()].head_edge[edge_dir] =
edge_idx;
}
}
@ -1285,14 +1285,14 @@ pub impl RegionVarBindings {
do iterate_until_fixed_point(~"Expansion", graph) |nodes, edge| {
match edge.constraint {
ConstrainRegSubVar(a_region, b_vid) => {
let b_node = &mut nodes[*b_vid];
let b_node = &mut nodes[b_vid.to_uint()];
self.expand_node(a_region, b_vid, b_node)
}
ConstrainVarSubVar(a_vid, b_vid) => {
match nodes[*a_vid].value {
match nodes[a_vid.to_uint()].value {
NoValue | ErrorValue => false,
Value(a_region) => {
let b_node = &mut nodes[*b_vid];
let b_node = &mut nodes[b_vid.to_uint()];
self.expand_node(a_region, b_vid, b_node)
}
}
@ -1349,16 +1349,16 @@ pub impl RegionVarBindings {
false
}
ConstrainVarSubVar(a_vid, b_vid) => {
match nodes[*b_vid].value {
match nodes[b_vid.to_uint()].value {
NoValue | ErrorValue => false,
Value(b_region) => {
let a_node = &mut nodes[*a_vid];
let a_node = &mut nodes[a_vid.to_uint()];
self.contract_node(a_vid, a_node, b_region)
}
}
}
ConstrainVarSubReg(a_vid, b_region) => {
let a_node = &mut nodes[*a_vid];
let a_node = &mut nodes[a_vid.to_uint()];
self.contract_node(a_vid, a_node, b_region)
}
}
@ -1474,7 +1474,7 @@ pub impl RegionVarBindings {
that is not used is not a problem, so if this rule
starts to create problems we'll have to revisit
this portion of the code and think hard about it. =) */
let node_vid = RegionVid(idx);
let node_vid = RegionVid { id: idx };
match node.classification {
Expanding => {
self.report_error_for_expanding_node(
@ -1525,7 +1525,7 @@ pub impl RegionVarBindings {
}
self.tcx.sess.span_err(
self.var_spans[*node_idx],
self.var_spans[node_idx.to_uint()],
fmt!("cannot infer an appropriate lifetime \
due to conflicting requirements"));
@ -1578,7 +1578,7 @@ pub impl RegionVarBindings {
}
self.tcx.sess.span_err(
self.var_spans[*node_idx],
self.var_spans[node_idx.to_uint()],
fmt!("cannot infer an appropriate lifetime \
due to conflicting requirements"));
@ -1616,7 +1616,7 @@ pub impl RegionVarBindings {
-> ~[SpannedRegion] {
let set = HashMap();
let mut stack = ~[orig_node_idx];
set.insert(*orig_node_idx, ());
set.insert(orig_node_idx.to_uint(), ());
let mut result = ~[];
while !vec::is_empty(stack) {
let node_idx = stack.pop();
@ -1627,7 +1627,7 @@ pub impl RegionVarBindings {
Incoming => from_vid,
Outgoing => to_vid
};
if set.insert(*vid, ()) {
if set.insert(vid.to_uint(), ()) {
stack.push(vid);
}
}
@ -1657,8 +1657,9 @@ pub impl RegionVarBindings {
graph: &Graph,
node_idx: RegionVid,
dir: Direction,
op: fn(edge: &GraphEdge) -> bool) {
let mut edge_idx = graph.nodes[*node_idx].head_edge[dir as uint];
op: &fn(edge: &GraphEdge) -> bool) {
let mut edge_idx =
graph.nodes[node_idx.to_uint()].head_edge[dir as uint];
while edge_idx != uint::max_value {
let edge_ptr = &graph.edges[edge_idx];
if !op(edge_ptr) {

View File

@ -29,7 +29,7 @@ use syntax::ast::{Onceness, m_const, purity, ret_style};
use syntax::codemap::span;
pub enum Sub = CombineFields; // "subtype", "subregion" etc
pub struct Sub(CombineFields); // "subtype", "subregion" etc
impl Combine for Sub {
fn infcx(&self) -> @mut InferCtxt { self.infcx }

View File

@ -225,7 +225,7 @@ pub fn require_same_types(
span: span,
t1: ty::t,
t2: ty::t,
msg: fn() -> ~str) -> bool {
msg: &fn() -> ~str) -> bool {
let l_tcx, l_infcx;
match maybe_infcx {

View File

@ -74,7 +74,8 @@ impl region_scope for MethodRscope {
}
}
pub enum type_rscope = Option<ty::region_variance>;
pub struct type_rscope(Option<ty::region_variance>);
impl type_rscope {
priv fn replacement(&self) -> ty::Region {
if self.is_some() {

View File

@ -17,7 +17,7 @@ use syntax::visit;
use core::str;
use std::oldmap::HashMap;
pub fn indent<R>(op: fn() -> R) -> R {
pub fn indent<R>(op: &fn() -> R) -> R {
// Use in conjunction with the log post-processor like `src/etc/indenter`
// to make debug output more readable.
debug!(">>");

View File

@ -322,8 +322,7 @@ fn structdoc_from_struct(
fields: do struct_def.fields.map |field| {
match field.node.kind {
ast::named_field(ident, _, _) => to_str(ident),
ast::unnamed_field => fail!(
~"what is an unnamed struct field?")
ast::unnamed_field => ~"(unnamed)",
}
},
sig: None

View File

@ -143,7 +143,7 @@ fn run(config: Config) {
}
}
pub fn time<T>(what: ~str, f: fn() -> T) -> T {
pub fn time<T>(what: ~str, f: &fn() -> T) -> T {
let start = std::time::precise_time_s();
let rv = f();
let end = std::time::precise_time_s();

View File

@ -59,7 +59,7 @@ enum CmdAction {
/// A utility function that hands off a pretty printer to a callback.
fn with_pp(intr: @token::ident_interner,
cb: fn(@pprust::ps, io::Writer)) -> ~str {
cb: &fn(@pprust::ps, io::Writer)) -> ~str {
do io::with_str_writer |writer| {
let pp = pprust::rust_printer(writer, intr);

View File

@ -260,7 +260,7 @@ pub fn hash(data: ~str) -> ~str {
hasher.result_str()
}
pub fn temp_change_dir<T>(dir: &Path, cb: fn() -> T) {
pub fn temp_change_dir<T>(dir: &Path, cb: &fn() -> T) {
let cwd = os::getcwd();
os::change_dir(dir);

View File

@ -176,7 +176,7 @@ pub impl<T:Owned> MutexARC<T> {
* blocked on the mutex) will also fail immediately.
*/
#[inline(always)]
unsafe fn access<U>(&self, blk: fn(x: &mut T) -> U) -> U {
unsafe fn access<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
unsafe {
let state = get_shared_mutable_state(&self.x);
// Borrowck would complain about this if the function were
@ -301,7 +301,7 @@ pub impl<T:Const + Owned> RWARC<T> {
* poison the ARC, so subsequent readers and writers will both also fail.
*/
#[inline(always)]
fn write<U>(&self, blk: fn(x: &mut T) -> U) -> U {
fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
unsafe {
let state = get_shared_mutable_state(&self.x);
do (*borrow_rwlock(state)).write {
@ -313,7 +313,7 @@ pub impl<T:Const + Owned> RWARC<T> {
}
/// As write(), but with a condvar, as sync::rwlock.write_cond().
#[inline(always)]
fn write_cond<U>(&self, blk: fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
fn write_cond<U>(&self, blk: &fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
unsafe {
let state = get_shared_mutable_state(&self.x);
do (*borrow_rwlock(state)).write_cond |cond| {
@ -335,7 +335,7 @@ pub impl<T:Const + Owned> RWARC<T> {
* Failing will unlock the ARC while unwinding. However, unlike all other
* access modes, this will not poison the ARC.
*/
fn read<U>(&self, blk: fn(x: &T) -> U) -> U {
fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
let state = unsafe { get_shared_immutable_state(&self.x) };
do (&state.lock).read {
check_poison(false, state.failed);
@ -360,14 +360,16 @@ pub impl<T:Const + Owned> RWARC<T> {
* }
* ~~~
*/
fn write_downgrade<U>(&self, blk: fn(v: RWWriteMode<T>) -> U) -> U {
fn write_downgrade<U>(&self, blk: &fn(v: RWWriteMode<T>) -> U) -> U {
unsafe {
let state = get_shared_mutable_state(&self.x);
do (*borrow_rwlock(state)).write_downgrade |write_mode| {
check_poison(false, (*state).failed);
blk(RWWriteMode((&mut (*state).data,
write_mode,
PoisonOnFail(&mut (*state).failed))))
blk(RWWriteMode {
data: &mut (*state).data,
token: write_mode,
poison: PoisonOnFail(&mut (*state).failed)
})
}
}
}
@ -376,7 +378,11 @@ pub impl<T:Const + Owned> RWARC<T> {
fn downgrade(&self, token: RWWriteMode/&a<T>) -> RWReadMode/&a<T> {
// The rwlock should assert that the token belongs to us for us.
let state = unsafe { get_shared_immutable_state(&self.x) };
let RWWriteMode((data, t, _poison)) = token;
let RWWriteMode {
data: data,
token: t,
poison: _poison
} = token;
// Let readers in
let new_token = (&state.lock).downgrade(t);
// Whatever region the input reference had, it will be safe to use
@ -386,7 +392,10 @@ pub impl<T:Const + Owned> RWARC<T> {
// Downgrade ensured the token belonged to us. Just a sanity check.
fail_unless!(ptr::ref_eq(&state.data, new_data));
// Produce new token
RWReadMode((new_data, new_token))
RWReadMode {
data: new_data,
token: new_token,
}
}
}
@ -398,19 +407,28 @@ fn borrow_rwlock<T:Const + Owned>(state: *const RWARCInner<T>) -> *RWlock {
unsafe { cast::transmute(&const (*state).lock) }
}
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
/// The "write permission" token used for RWARC.write_downgrade().
pub enum RWWriteMode<T> =
(&self/mut T, sync::RWlockWriteMode/&self, PoisonOnFail);
pub struct RWWriteMode<'self, T> {
data: &'self mut T,
token: sync::RWlockWriteMode<'self>,
poison: PoisonOnFail,
}
/// The "read permission" token used for RWARC.write_downgrade().
pub enum RWReadMode<T> = (&self/T, sync::RWlockReadMode/&self);
pub struct RWReadMode<'self, T> {
data: &'self T,
token: sync::RWlockReadMode<'self>,
}
pub impl<T:Const + Owned> RWWriteMode/&self<T> {
/// Access the pre-downgrade RWARC in write mode.
fn write<U>(&self, blk: fn(x: &mut T) -> U) -> U {
fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
match *self {
RWWriteMode((ref data, ref token, _)) => {
RWWriteMode {
data: ref data,
token: ref token,
poison: _
} => {
do token.write {
blk(&mut **data)
}
@ -418,9 +436,13 @@ pub impl<T:Const + Owned> RWWriteMode/&self<T> {
}
}
/// Access the pre-downgrade RWARC in write mode with a condvar.
fn write_cond<U>(&self, blk: fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
fn write_cond<U>(&self, blk: &fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
match *self {
RWWriteMode((ref data, ref token, ref poison)) => {
RWWriteMode {
data: ref data,
token: ref token,
poison: ref poison
} => {
do token.write_cond |cond| {
unsafe {
let cvar = Condvar {
@ -438,9 +460,12 @@ pub impl<T:Const + Owned> RWWriteMode/&self<T> {
pub impl<T:Const + Owned> RWReadMode/&self<T> {
/// Access the post-downgrade rwlock in read mode.
fn read<U>(&self, blk: fn(x: &T) -> U) -> U {
fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
match *self {
RWReadMode((data, ref token)) => {
RWReadMode {
data: data,
token: ref token
} => {
do token.read { blk(data) }
}
}

View File

@ -201,7 +201,7 @@ pub impl Arena {
}
#[inline(always)]
fn alloc_pod<T>(&self, op: fn() -> T) -> &self/T {
fn alloc_pod<T>(&self, op: &fn() -> T) -> &self/T {
unsafe {
let tydesc = sys::get_type_desc::<T>();
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
@ -246,7 +246,7 @@ pub impl Arena {
}
#[inline(always)]
fn alloc_nonpod<T>(&self, op: fn() -> T) -> &self/T {
fn alloc_nonpod<T>(&self, op: &fn() -> T) -> &self/T {
unsafe {
let tydesc = sys::get_type_desc::<T>();
let (ty_ptr, ptr) =
@ -268,7 +268,7 @@ pub impl Arena {
// The external interface
#[inline(always)]
fn alloc<T>(&self, op: fn() -> T) -> &self/T {
fn alloc<T>(&self, op: &fn() -> T) -> &self/T {
unsafe {
if !rusti::needs_drop::<T>() {
self.alloc_pod(op)

View File

@ -33,7 +33,7 @@ pub impl SmallBitv {
#[inline(always)]
fn bits_op(&mut self, right_bits: uint, nbits: uint,
f: fn(uint, uint) -> uint) -> bool {
f: &fn(uint, uint) -> uint) -> bool {
let mask = small_mask(nbits);
let old_b: uint = self.bits;
let new_b = f(old_b, right_bits);
@ -130,7 +130,7 @@ pub impl BigBitv {
#[inline(always)]
fn process(&mut self, b: &BigBitv, nbits: uint,
op: fn(uint, uint) -> uint) -> bool {
op: &fn(uint, uint) -> uint) -> bool {
let len = b.storage.len();
fail_unless!((self.storage.len() == len));
let mut changed = false;
@ -148,7 +148,7 @@ pub impl BigBitv {
}
#[inline(always)]
fn each_storage(&mut self, op: fn(v: &mut uint) -> bool) {
fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) {
for uint::range(0, self.storage.len()) |i| {
let mut w = self.storage[i];
let b = op(&mut w);
@ -392,7 +392,7 @@ pub impl Bitv {
}
#[inline(always)]
fn each(&self, f: fn(bool) -> bool) {
fn each(&self, f: &fn(bool) -> bool) {
let mut i = 0;
while i < self.nbits {
if !f(self.get(i)) { break; }
@ -493,7 +493,7 @@ pub impl Bitv {
true
}
fn ones(&self, f: fn(uint) -> bool) {
fn ones(&self, f: &fn(uint) -> bool) {
for uint::range(0, self.nbits) |i| {
if self.get(i) {
if !f(i) { break }
@ -546,7 +546,7 @@ pub fn from_bools(bools: &[bool]) -> Bitv {
* Create a bitv of the specified length where the value at each
* index is f(index).
*/
pub fn from_fn(len: uint, f: fn(index: uint) -> bool) -> Bitv {
pub fn from_fn(len: uint, f: &fn(index: uint) -> bool) -> Bitv {
let mut bitv = Bitv::new(len, false);
for uint::range(0, len) |i| {
bitv.set(i, f(i));
@ -561,7 +561,7 @@ impl ops::Index<uint,bool> for Bitv {
}
#[inline(always)]
pure fn iterate_bits(base: uint, bits: uint, f: fn(uint) -> bool) -> bool {
pure fn iterate_bits(base: uint, bits: uint, f: &fn(uint) -> bool) -> bool {
if bits == 0 {
return true;
}
@ -622,7 +622,7 @@ pub impl BitvSet {
}
#[inline(always)]
priv fn other_op(&mut self, other: &BitvSet, f: fn(uint, uint) -> uint) {
priv fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) {
fn nbits(mut w: uint) -> uint {
let mut bits = 0;
for uint::bits.times {
@ -669,7 +669,7 @@ pub impl BitvSet {
impl BaseIter<uint> for BitvSet {
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
pure fn each(&self, blk: fn(v: &uint) -> bool) {
pure fn each(&self, blk: &fn(v: &uint) -> bool) {
for self.bitv.storage.eachi |i, &w| {
if !iterate_bits(i * uint::bits, w, |b| blk(&b)) {
return;
@ -778,7 +778,7 @@ impl Set<uint> for BitvSet {
other.is_subset(self)
}
pure fn difference(&self, other: &BitvSet, f: fn(&uint) -> bool) {
pure fn difference(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
for self.each_common(other) |i, w1, w2| {
if !iterate_bits(i, w1 & !w2, |b| f(&b)) {
return;
@ -791,7 +791,7 @@ impl Set<uint> for BitvSet {
}
pure fn symmetric_difference(&self, other: &BitvSet,
f: fn(&uint) -> bool) {
f: &fn(&uint) -> bool) {
for self.each_common(other) |i, w1, w2| {
if !iterate_bits(i, w1 ^ w2, |b| f(&b)) {
return;
@ -802,7 +802,7 @@ impl Set<uint> for BitvSet {
);
}
pure fn intersection(&self, other: &BitvSet, f: fn(&uint) -> bool) {
pure fn intersection(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
for self.each_common(other) |i, w1, w2| {
if !iterate_bits(i, w1 & w2, |b| f(&b)) {
return;
@ -810,7 +810,7 @@ impl Set<uint> for BitvSet {
}
}
pure fn union(&self, other: &BitvSet, f: fn(&uint) -> bool) {
pure fn union(&self, other: &BitvSet, f: &fn(&uint) -> bool) {
for self.each_common(other) |i, w1, w2| {
if !iterate_bits(i, w1 | w2, |b| f(&b)) {
return;
@ -828,7 +828,7 @@ priv impl BitvSet {
/// w1, w2) where the bit location is the number of bits offset so far,
/// and w1/w2 are the words coming from the two vectors self, other.
pure fn each_common(&self, other: &BitvSet,
f: fn(uint, uint, uint) -> bool) {
f: &fn(uint, uint, uint) -> bool) {
let min = uint::min(self.bitv.storage.len(),
other.bitv.storage.len());
for self.bitv.storage.view(0, min).eachi |i, &w| {
@ -846,7 +846,7 @@ priv impl BitvSet {
/// is true if the word comes from 'self', and false if it comes from
/// 'other'.
pure fn each_outlier(&self, other: &BitvSet,
f: fn(bool, uint, uint) -> bool) {
f: &fn(bool, uint, uint) -> bool) {
let len1 = self.bitv.storage.len();
let len2 = other.bitv.storage.len();
let min = uint::min(len1, len2);

View File

@ -142,7 +142,7 @@ pub mod reader {
}
}
pub fn docs(d: Doc, it: fn(uint, Doc) -> bool) {
pub fn docs(d: Doc, it: &fn(uint, Doc) -> bool) {
let mut pos = d.start;
while pos < d.end {
let elt_tag = vuint_at(*d.data, pos);
@ -155,7 +155,7 @@ pub mod reader {
}
}
pub fn tagged_docs(d: Doc, tg: uint, it: fn(Doc) -> bool) {
pub fn tagged_docs(d: Doc, tg: uint, it: &fn(Doc) -> bool) {
let mut pos = d.start;
while pos < d.end {
let elt_tag = vuint_at(*d.data, pos);
@ -175,7 +175,7 @@ pub mod reader {
vec::slice::<u8>(*d.data, d.start, d.end).to_vec()
}
pub fn with_doc_data<T>(d: Doc, f: fn(x: &[u8]) -> T) -> T {
pub fn with_doc_data<T>(d: Doc, f: &fn(x: &[u8]) -> T) -> T {
f(vec::slice(*d.data, d.start, d.end))
}
@ -255,7 +255,7 @@ pub mod reader {
r_doc
}
fn push_doc<T>(&self, d: Doc, f: fn() -> T) -> T {
fn push_doc<T>(&self, d: Doc, f: &fn() -> T) -> T {
let old_parent = self.parent;
let old_pos = self.pos;
self.parent = d;
@ -274,7 +274,7 @@ pub mod reader {
}
pub impl Decoder {
fn read_opaque<R>(&self, op: fn(Doc) -> R) -> R {
fn read_opaque<R>(&self, op: &fn(Doc) -> R) -> R {
do self.push_doc(self.next_doc(EsOpaque)) {
op(copy self.parent)
}
@ -321,23 +321,23 @@ pub mod reader {
fn read_managed_str(&self) -> @str { fail!(~"read_managed_str()"); }
// Compound types:
fn read_owned<T>(&self, f: fn() -> T) -> T {
fn read_owned<T>(&self, f: &fn() -> T) -> T {
debug!("read_owned()");
f()
}
fn read_managed<T>(&self, f: fn() -> T) -> T {
fn read_managed<T>(&self, f: &fn() -> T) -> T {
debug!("read_managed()");
f()
}
fn read_enum<T>(&self, name: &str, f: fn() -> T) -> T {
fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T {
debug!("read_enum(%s)", name);
self._check_label(name);
self.push_doc(self.next_doc(EsEnum), f)
}
fn read_enum_variant<T>(&self, f: fn(uint) -> T) -> T {
fn read_enum_variant<T>(&self, f: &fn(uint) -> T) -> T {
debug!("read_enum_variant()");
let idx = self._next_uint(EsEnumVid);
debug!(" idx=%u", idx);
@ -346,12 +346,12 @@ pub mod reader {
}
}
fn read_enum_variant_arg<T>(&self, idx: uint, f: fn() -> T) -> T {
fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
debug!("read_enum_variant_arg(idx=%u)", idx);
f()
}
fn read_owned_vec<T>(&self, f: fn(uint) -> T) -> T {
fn read_owned_vec<T>(&self, f: &fn(uint) -> T) -> T {
debug!("read_owned_vec()");
do self.push_doc(self.next_doc(EsVec)) {
let len = self._next_uint(EsVecLen);
@ -360,7 +360,7 @@ pub mod reader {
}
}
fn read_managed_vec<T>(&self, f: fn(uint) -> T) -> T {
fn read_managed_vec<T>(&self, f: &fn(uint) -> T) -> T {
debug!("read_managed_vec()");
do self.push_doc(self.next_doc(EsVec)) {
let len = self._next_uint(EsVecLen);
@ -369,33 +369,33 @@ pub mod reader {
}
}
fn read_vec_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
fn read_vec_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
debug!("read_vec_elt(idx=%u)", idx);
self.push_doc(self.next_doc(EsVecElt), f)
}
fn read_rec<T>(&self, f: fn() -> T) -> T {
fn read_rec<T>(&self, f: &fn() -> T) -> T {
debug!("read_rec()");
f()
}
fn read_struct<T>(&self, name: &str, _len: uint, f: fn() -> T) -> T {
fn read_struct<T>(&self, name: &str, _len: uint, f: &fn() -> T) -> T {
debug!("read_struct(name=%s)", name);
f()
}
fn read_field<T>(&self, name: &str, idx: uint, f: fn() -> T) -> T {
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
debug!("read_field(name=%s, idx=%u)", name, idx);
self._check_label(name);
f()
}
fn read_tup<T>(&self, len: uint, f: fn() -> T) -> T {
fn read_tup<T>(&self, len: uint, f: &fn() -> T) -> T {
debug!("read_tup(len=%u)", len);
f()
}
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
fn read_tup_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
debug!("read_tup_elt(idx=%u)", idx);
f()
}
@ -469,7 +469,7 @@ pub mod writer {
debug!("End tag (size = %u)", size);
}
fn wr_tag(&self, tag_id: uint, blk: fn()) {
fn wr_tag(&self, tag_id: uint, blk: &fn()) {
self.start_tag(tag_id);
blk();
self.end_tag();
@ -566,7 +566,7 @@ pub mod writer {
}
pub impl Encoder {
fn emit_opaque(&self, f: fn()) {
fn emit_opaque(&self, f: &fn()) {
do self.wr_tag(EsOpaque as uint) {
f()
}
@ -623,49 +623,49 @@ pub mod writer {
self.emit_borrowed_str(v)
}
fn emit_borrowed(&self, f: fn()) { f() }
fn emit_owned(&self, f: fn()) { f() }
fn emit_managed(&self, f: fn()) { f() }
fn emit_borrowed(&self, f: &fn()) { f() }
fn emit_owned(&self, f: &fn()) { f() }
fn emit_managed(&self, f: &fn()) { f() }
fn emit_enum(&self, name: &str, f: fn()) {
fn emit_enum(&self, name: &str, f: &fn()) {
self._emit_label(name);
self.wr_tag(EsEnum as uint, f)
}
fn emit_enum_variant(&self, _v_name: &str, v_id: uint, _cnt: uint,
f: fn()) {
f: &fn()) {
self._emit_tagged_uint(EsEnumVid, v_id);
self.wr_tag(EsEnumBody as uint, f)
}
fn emit_enum_variant_arg(&self, _idx: uint, f: fn()) { f() }
fn emit_enum_variant_arg(&self, _idx: uint, f: &fn()) { f() }
fn emit_borrowed_vec(&self, len: uint, f: fn()) {
fn emit_borrowed_vec(&self, len: uint, f: &fn()) {
do self.wr_tag(EsVec as uint) {
self._emit_tagged_uint(EsVecLen, len);
f()
}
}
fn emit_owned_vec(&self, len: uint, f: fn()) {
fn emit_owned_vec(&self, len: uint, f: &fn()) {
self.emit_borrowed_vec(len, f)
}
fn emit_managed_vec(&self, len: uint, f: fn()) {
fn emit_managed_vec(&self, len: uint, f: &fn()) {
self.emit_borrowed_vec(len, f)
}
fn emit_vec_elt(&self, _idx: uint, f: fn()) {
fn emit_vec_elt(&self, _idx: uint, f: &fn()) {
self.wr_tag(EsVecElt as uint, f)
}
fn emit_rec(&self, f: fn()) { f() }
fn emit_struct(&self, _name: &str, _len: uint, f: fn()) { f() }
fn emit_field(&self, name: &str, _idx: uint, f: fn()) {
fn emit_rec(&self, f: &fn()) { f() }
fn emit_struct(&self, _name: &str, _len: uint, f: &fn()) { f() }
fn emit_field(&self, name: &str, _idx: uint, f: &fn()) {
self._emit_label(name);
f()
}
fn emit_tup(&self, _len: uint, f: fn()) { f() }
fn emit_tup_elt(&self, _idx: uint, f: fn()) { f() }
fn emit_tup(&self, _len: uint, f: &fn()) { f() }
fn emit_tup_elt(&self, _idx: uint, f: &fn()) { f() }
}
}

View File

@ -61,7 +61,7 @@ pub fn find<K:Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K) -> Option<V> {
}
/// Visit all pairs in the map in order.
pub fn traverse<K, V: Copy>(m: Treemap<K, V>, f: fn(&K, &V)) {
pub fn traverse<K, V: Copy>(m: Treemap<K, V>, f: &fn(&K, &V)) {
match *m {
Empty => (),
/*

View File

@ -116,15 +116,15 @@ impl serialize::Encoder for Encoder {
fn emit_owned_str(&self, v: &str) { self.emit_borrowed_str(v) }
fn emit_managed_str(&self, v: &str) { self.emit_borrowed_str(v) }
fn emit_borrowed(&self, f: fn()) { f() }
fn emit_owned(&self, f: fn()) { f() }
fn emit_managed(&self, f: fn()) { f() }
fn emit_borrowed(&self, f: &fn()) { f() }
fn emit_owned(&self, f: &fn()) { f() }
fn emit_managed(&self, f: &fn()) { f() }
fn emit_enum(&self, _name: &str, f: fn()) {
fn emit_enum(&self, _name: &str, f: &fn()) {
f()
}
fn emit_enum_variant(&self, name: &str, _id: uint, _cnt: uint, f: fn()) {
fn emit_enum_variant(&self, name: &str, _id: uint, _cnt: uint, f: &fn()) {
// encoding of enums is special-cased for Option. Specifically:
// Some(34) => 34
// None => null
@ -160,49 +160,49 @@ impl serialize::Encoder for Encoder {
}
}
fn emit_enum_variant_arg(&self, idx: uint, f: fn()) {
fn emit_enum_variant_arg(&self, idx: uint, f: &fn()) {
if (idx != 0) {self.wr.write_char(',');}
f();
}
fn emit_borrowed_vec(&self, _len: uint, f: fn()) {
fn emit_borrowed_vec(&self, _len: uint, f: &fn()) {
self.wr.write_char('[');
f();
self.wr.write_char(']');
}
fn emit_owned_vec(&self, len: uint, f: fn()) {
fn emit_owned_vec(&self, len: uint, f: &fn()) {
self.emit_borrowed_vec(len, f)
}
fn emit_managed_vec(&self, len: uint, f: fn()) {
fn emit_managed_vec(&self, len: uint, f: &fn()) {
self.emit_borrowed_vec(len, f)
}
fn emit_vec_elt(&self, idx: uint, f: fn()) {
fn emit_vec_elt(&self, idx: uint, f: &fn()) {
if idx != 0 { self.wr.write_char(','); }
f()
}
fn emit_rec(&self, f: fn()) {
fn emit_rec(&self, f: &fn()) {
self.wr.write_char('{');
f();
self.wr.write_char('}');
}
fn emit_struct(&self, _name: &str, _len: uint, f: fn()) {
fn emit_struct(&self, _name: &str, _len: uint, f: &fn()) {
self.wr.write_char('{');
f();
self.wr.write_char('}');
}
fn emit_field(&self, name: &str, idx: uint, f: fn()) {
fn emit_field(&self, name: &str, idx: uint, f: &fn()) {
if idx != 0 { self.wr.write_char(','); }
self.wr.write_str(escape_str(name));
self.wr.write_char(':');
f();
}
fn emit_tup(&self, len: uint, f: fn()) {
fn emit_tup(&self, len: uint, f: &fn()) {
self.emit_borrowed_vec(len, f);
}
fn emit_tup_elt(&self, idx: uint, f: fn()) {
fn emit_tup_elt(&self, idx: uint, f: &fn()) {
self.emit_vec_elt(idx, f)
}
}
@ -251,39 +251,39 @@ impl serialize::Encoder for PrettyEncoder {
fn emit_owned_str(&self, v: &str) { self.emit_borrowed_str(v) }
fn emit_managed_str(&self, v: &str) { self.emit_borrowed_str(v) }
fn emit_borrowed(&self, f: fn()) { f() }
fn emit_owned(&self, f: fn()) { f() }
fn emit_managed(&self, f: fn()) { f() }
fn emit_borrowed(&self, f: &fn()) { f() }
fn emit_owned(&self, f: &fn()) { f() }
fn emit_managed(&self, f: &fn()) { f() }
fn emit_enum(&self, name: &str, f: fn()) {
fn emit_enum(&self, name: &str, f: &fn()) {
if name != "option" { fail!(~"only supports option enum") }
f()
}
fn emit_enum_variant(&self, _name: &str, id: uint, _cnt: uint, f: fn()) {
fn emit_enum_variant(&self, _name: &str, id: uint, _cnt: uint, f: &fn()) {
if id == 0 {
self.emit_nil();
} else {
f()
}
}
fn emit_enum_variant_arg(&self, _idx: uint, f: fn()) {
fn emit_enum_variant_arg(&self, _idx: uint, f: &fn()) {
f()
}
fn emit_borrowed_vec(&self, _len: uint, f: fn()) {
fn emit_borrowed_vec(&self, _len: uint, f: &fn()) {
self.wr.write_char('[');
self.indent += 2;
f();
self.indent -= 2;
self.wr.write_char(']');
}
fn emit_owned_vec(&self, len: uint, f: fn()) {
fn emit_owned_vec(&self, len: uint, f: &fn()) {
self.emit_borrowed_vec(len, f)
}
fn emit_managed_vec(&self, len: uint, f: fn()) {
fn emit_managed_vec(&self, len: uint, f: &fn()) {
self.emit_borrowed_vec(len, f)
}
fn emit_vec_elt(&self, idx: uint, f: fn()) {
fn emit_vec_elt(&self, idx: uint, f: &fn()) {
if idx == 0 {
self.wr.write_char('\n');
} else {
@ -293,17 +293,17 @@ impl serialize::Encoder for PrettyEncoder {
f()
}
fn emit_rec(&self, f: fn()) {
fn emit_rec(&self, f: &fn()) {
self.wr.write_char('{');
self.indent += 2;
f();
self.indent -= 2;
self.wr.write_char('}');
}
fn emit_struct(&self, _name: &str, _len: uint, f: fn()) {
fn emit_struct(&self, _name: &str, _len: uint, f: &fn()) {
self.emit_rec(f)
}
fn emit_field(&self, name: &str, idx: uint, f: fn()) {
fn emit_field(&self, name: &str, idx: uint, f: &fn()) {
if idx == 0 {
self.wr.write_char('\n');
} else {
@ -314,10 +314,10 @@ impl serialize::Encoder for PrettyEncoder {
self.wr.write_str(": ");
f();
}
fn emit_tup(&self, sz: uint, f: fn()) {
fn emit_tup(&self, sz: uint, f: &fn()) {
self.emit_borrowed_vec(sz, f);
}
fn emit_tup_elt(&self, idx: uint, f: fn()) {
fn emit_tup_elt(&self, idx: uint, f: &fn()) {
self.emit_vec_elt(idx, f)
}
}
@ -828,23 +828,23 @@ impl serialize::Decoder for Decoder/&self {
}
}
fn read_owned<T>(&self, f: fn() -> T) -> T {
fn read_owned<T>(&self, f: &fn() -> T) -> T {
debug!("read_owned()");
f()
}
fn read_managed<T>(&self, f: fn() -> T) -> T {
fn read_managed<T>(&self, f: &fn() -> T) -> T {
debug!("read_managed()");
f()
}
fn read_enum<T>(&self, name: &str, f: fn() -> T) -> T {
fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T {
debug!("read_enum(%s)", name);
if name != ~"option" { fail!(~"only supports the option enum") }
f()
}
fn read_enum_variant<T>(&self, f: fn(uint) -> T) -> T {
fn read_enum_variant<T>(&self, f: &fn(uint) -> T) -> T {
debug!("read_enum_variant()");
let idx = match *self.peek() {
Null => 0,
@ -853,13 +853,13 @@ impl serialize::Decoder for Decoder/&self {
f(idx)
}
fn read_enum_variant_arg<T>(&self, idx: uint, f: fn() -> T) -> T {
fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
debug!("read_enum_variant_arg(idx=%u)", idx);
if idx != 0 { fail!(~"unknown index") }
f()
}
fn read_owned_vec<T>(&self, f: fn(uint) -> T) -> T {
fn read_owned_vec<T>(&self, f: &fn(uint) -> T) -> T {
debug!("read_owned_vec()");
let len = match *self.peek() {
List(ref list) => list.len(),
@ -870,7 +870,7 @@ impl serialize::Decoder for Decoder/&self {
res
}
fn read_managed_vec<T>(&self, f: fn(uint) -> T) -> T {
fn read_managed_vec<T>(&self, f: &fn(uint) -> T) -> T {
debug!("read_owned_vec()");
let len = match *self.peek() {
List(ref list) => list.len(),
@ -881,7 +881,7 @@ impl serialize::Decoder for Decoder/&self {
res
}
fn read_vec_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
fn read_vec_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
debug!("read_vec_elt(idx=%u)", idx);
match *self.peek() {
List(ref list) => {
@ -892,21 +892,21 @@ impl serialize::Decoder for Decoder/&self {
}
}
fn read_rec<T>(&self, f: fn() -> T) -> T {
fn read_rec<T>(&self, f: &fn() -> T) -> T {
debug!("read_rec()");
let value = f();
self.pop();
value
}
fn read_struct<T>(&self, _name: &str, _len: uint, f: fn() -> T) -> T {
fn read_struct<T>(&self, _name: &str, _len: uint, f: &fn() -> T) -> T {
debug!("read_struct()");
let value = f();
self.pop();
value
}
fn read_field<T>(&self, name: &str, idx: uint, f: fn() -> T) -> T {
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
debug!("read_rec_field(%s, idx=%u)", name, idx);
let top = self.peek();
match *top {
@ -929,14 +929,14 @@ impl serialize::Decoder for Decoder/&self {
}
}
fn read_tup<T>(&self, len: uint, f: fn() -> T) -> T {
fn read_tup<T>(&self, len: uint, f: &fn() -> T) -> T {
debug!("read_tup(len=%u)", len);
let value = f();
self.pop();
value
}
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
fn read_tup_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
debug!("read_tup_elt(idx=%u)", idx);
match *self.peek() {
List(ref list) => {

View File

@ -39,7 +39,7 @@ pub pure fn from_vec<T:Copy>(v: &[T]) -> @List<T> {
* * z - The initial value
* * f - The function to apply
*/
pub fn foldl<T:Copy,U>(z: T, ls: @List<U>, f: fn(&T, &U) -> T) -> T {
pub fn foldl<T:Copy,U>(z: T, ls: @List<U>, f: &fn(&T, &U) -> T) -> T {
let mut accum: T = z;
do iter(ls) |elt| { accum = f(&accum, elt);}
accum
@ -52,7 +52,7 @@ pub fn foldl<T:Copy,U>(z: T, ls: @List<U>, f: fn(&T, &U) -> T) -> T {
* When function `f` returns true then an option containing the element
* is returned. If `f` matches no elements then none is returned.
*/
pub pure fn find<T:Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
pub pure fn find<T:Copy>(ls: @List<T>, f: &fn(&T) -> bool) -> Option<T> {
let mut ls = ls;
loop {
ls = match *ls {
@ -125,7 +125,7 @@ pure fn push<T:Copy>(ll: &mut @list<T>, vv: T) {
*/
/// Iterate over a list
pub pure fn iter<T>(l: @List<T>, f: fn(&T)) {
pub pure fn iter<T>(l: @List<T>, f: &fn(&T)) {
let mut cur = l;
loop {
cur = match *cur {
@ -139,7 +139,7 @@ pub pure fn iter<T>(l: @List<T>, f: fn(&T)) {
}
/// Iterate over a list
pub pure fn each<T>(l: @List<T>, f: fn(&T) -> bool) {
pub pure fn each<T>(l: @List<T>, f: &fn(&T) -> bool) {
let mut cur = l;
loop {
cur = match *cur {

View File

@ -105,7 +105,7 @@ pub pure fn md4(msg: &[u8]) -> Quad {
pub pure fn md4_str(msg: &[u8]) -> ~str {
let Quad {a, b, c, d} = md4(msg);
pure fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
pure fn app(a: u32, b: u32, c: u32, d: u32, f: &fn(u32)) {
f(a); f(b); f(c); f(d);
}
let mut result = ~"";

View File

@ -134,7 +134,7 @@ pub mod chained {
}
pub impl<K:Eq + IterBytes + Hash,V> T<K, V> {
pure fn each_entry(&self, blk: fn(@Entry<K,V>) -> bool) {
pure fn each_entry(&self, blk: &fn(@Entry<K,V>) -> bool) {
// n.b. we can't use vec::iter() here because self.chains
// is stored in a mutable location.
let mut i = 0u, n = self.chains.len();
@ -236,17 +236,17 @@ pub mod chained {
}
}
pure fn each(&self, blk: fn(key: &K, value: &V) -> bool) {
pure fn each(&self, blk: &fn(key: &K, value: &V) -> bool) {
for self.each_entry |entry| {
if !blk(&entry.key, &entry.value) { break; }
}
}
pure fn each_key(&self, blk: fn(key: &K) -> bool) {
pure fn each_key(&self, blk: &fn(key: &K) -> bool) {
self.each(|k, _v| blk(k))
}
pure fn each_value(&self, blk: fn(value: &V) -> bool) {
pure fn each_value(&self, blk: &fn(value: &V) -> bool) {
self.each(|_k, v| blk(v))
}
}
@ -260,7 +260,7 @@ pub mod chained {
}
}
fn update_with_key(&self, key: K, newval: V, ff: fn(K, V, V) -> V)
fn update_with_key(&self, key: K, newval: V, ff: &fn(K, V, V) -> V)
-> bool {
/*
match self.find(key) {
@ -312,7 +312,7 @@ pub mod chained {
}
}
fn update(&self, key: K, newval: V, ff: fn(V, V) -> V) -> bool {
fn update(&self, key: K, newval: V, ff: &fn(V, V) -> V) -> bool {
return self.update_with_key(key, newval, |_k, v, v1| ff(v,v1));
}

View File

@ -98,87 +98,87 @@ impl serialize::Encoder for Serializer {
self.wr.write_str(fmt!("@%?", v));
}
fn emit_borrowed(&self, f: fn()) {
fn emit_borrowed(&self, f: &fn()) {
self.wr.write_str(~"&");
f();
}
fn emit_owned(&self, f: fn()) {
fn emit_owned(&self, f: &fn()) {
self.wr.write_str(~"~");
f();
}
fn emit_managed(&self, f: fn()) {
fn emit_managed(&self, f: &fn()) {
self.wr.write_str(~"@");
f();
}
fn emit_enum(&self, _name: &str, f: fn()) {
fn emit_enum(&self, _name: &str, f: &fn()) {
f();
}
fn emit_enum_variant(&self, v_name: &str, _v_id: uint, sz: uint,
f: fn()) {
f: &fn()) {
self.wr.write_str(v_name);
if sz > 0u { self.wr.write_str(~"("); }
f();
if sz > 0u { self.wr.write_str(~")"); }
}
fn emit_enum_variant_arg(&self, idx: uint, f: fn()) {
fn emit_enum_variant_arg(&self, idx: uint, f: &fn()) {
if idx > 0u { self.wr.write_str(~", "); }
f();
}
fn emit_borrowed_vec(&self, _len: uint, f: fn()) {
fn emit_borrowed_vec(&self, _len: uint, f: &fn()) {
self.wr.write_str(~"&[");
f();
self.wr.write_str(~"]");
}
fn emit_owned_vec(&self, _len: uint, f: fn()) {
fn emit_owned_vec(&self, _len: uint, f: &fn()) {
self.wr.write_str(~"~[");
f();
self.wr.write_str(~"]");
}
fn emit_managed_vec(&self, _len: uint, f: fn()) {
fn emit_managed_vec(&self, _len: uint, f: &fn()) {
self.wr.write_str(~"@[");
f();
self.wr.write_str(~"]");
}
fn emit_vec_elt(&self, idx: uint, f: fn()) {
fn emit_vec_elt(&self, idx: uint, f: &fn()) {
if idx > 0u { self.wr.write_str(~", "); }
f();
}
fn emit_rec(&self, f: fn()) {
fn emit_rec(&self, f: &fn()) {
self.wr.write_str(~"{");
f();
self.wr.write_str(~"}");
}
fn emit_struct(&self, name: &str, _len: uint, f: fn()) {
fn emit_struct(&self, name: &str, _len: uint, f: &fn()) {
self.wr.write_str(fmt!("%s {", name));
f();
self.wr.write_str(~"}");
}
fn emit_field(&self, name: &str, idx: uint, f: fn()) {
fn emit_field(&self, name: &str, idx: uint, f: &fn()) {
if idx > 0u { self.wr.write_str(~", "); }
self.wr.write_str(name);
self.wr.write_str(~": ");
f();
}
fn emit_tup(&self, _len: uint, f: fn()) {
fn emit_tup(&self, _len: uint, f: &fn()) {
self.wr.write_str(~"(");
f();
self.wr.write_str(~")");
}
fn emit_tup_elt(&self, idx: uint, f: fn()) {
fn emit_tup_elt(&self, idx: uint, f: &fn()) {
if idx > 0u { self.wr.write_str(~", "); }
f();
}

View File

@ -31,7 +31,7 @@ impl<T:Ord> BaseIter<T> for PriorityQueue<T> {
/// Visit all values in the underlying vector.
///
/// The values are **not** visited in order.
pure fn each(&self, f: fn(&T) -> bool) { self.data.each(f) }
pure fn each(&self, f: &fn(&T) -> bool) { self.data.each(f) }
pure fn size_hint(&self) -> Option<uint> { self.data.size_hint() }
}

View File

@ -68,7 +68,7 @@ pub unsafe fn read(prompt: ~str) -> Option<~str> {
}
}
pub type CompletionCb = @fn(~str, fn(~str));
pub type CompletionCb<'self> = @fn(~str, &'self fn(~str));
fn complete_key(_v: @CompletionCb) {}

View File

@ -393,7 +393,7 @@ Section: Iterating
* `true` If execution proceeded correctly, `false` if it was interrupted,
* that is if `it` returned `false` at any point.
*/
pub fn loop_chars(rope: Rope, it: fn(c: char) -> bool) -> bool {
pub fn loop_chars(rope: Rope, it: &fn(c: char) -> bool) -> bool {
match (rope) {
node::Empty => return true,
node::Content(x) => return node::loop_chars(x, it)
@ -407,7 +407,7 @@ pub fn loop_chars(rope: Rope, it: fn(c: char) -> bool) -> bool {
* * rope - A rope to traverse. It may be empty
* * it - A block to execute with each consecutive character of the rope.
*/
pub fn iter_chars(rope: Rope, it: fn(char)) {
pub fn iter_chars(rope: Rope, it: &fn(char)) {
do loop_chars(rope) |x| {
it(x);
true
@ -436,7 +436,7 @@ pub fn iter_chars(rope: Rope, it: fn(char)) {
* `true` If execution proceeded correctly, `false` if it was interrupted,
* that is if `it` returned `false` at any point.
*/
pub fn loop_leaves(rope: Rope, it: fn(node::Leaf) -> bool) -> bool{
pub fn loop_leaves(rope: Rope, it: &fn(node::Leaf) -> bool) -> bool{
match (rope) {
node::Empty => return true,
node::Content(x) => return node::loop_leaves(x, it)
@ -1078,7 +1078,7 @@ pub mod node {
return result;
}
pub fn loop_chars(node: @Node, it: fn(c: char) -> bool) -> bool {
pub fn loop_chars(node: @Node, it: &fn(c: char) -> bool) -> bool {
return loop_leaves(node,|leaf| {
str::all_between(*leaf.content,
leaf.byte_offset,
@ -1100,7 +1100,7 @@ pub mod node {
* `true` If execution proceeded correctly, `false` if it was interrupted,
* that is if `it` returned `false` at any point.
*/
pub fn loop_leaves(node: @Node, it: fn(Leaf) -> bool) -> bool{
pub fn loop_leaves(node: @Node, it: &fn(Leaf) -> bool) -> bool{
let mut current = node;
loop {
match (*current) {

View File

@ -140,7 +140,7 @@ condition! {
fn take_nonempty_prefix(rdr: io::Reader,
ch: char,
pred: fn(char) -> bool) -> (~str, char) {
pred: &fn(char) -> bool) -> (~str, char) {
let mut buf = ~"";
let mut ch = ch;
while pred(ch) {

View File

@ -43,25 +43,25 @@ pub trait Encoder {
fn emit_managed_str(&self, v: &str);
// Compound types:
fn emit_borrowed(&self, f: fn());
fn emit_owned(&self, f: fn());
fn emit_managed(&self, f: fn());
fn emit_borrowed(&self, f: &fn());
fn emit_owned(&self, f: &fn());
fn emit_managed(&self, f: &fn());
fn emit_enum(&self, name: &str, f: fn());
fn emit_enum_variant(&self, v_name: &str, v_id: uint, sz: uint, f: fn());
fn emit_enum_variant_arg(&self, idx: uint, f: fn());
fn emit_enum(&self, name: &str, f: &fn());
fn emit_enum_variant(&self, v_name: &str, v_id: uint, sz: uint, f: &fn());
fn emit_enum_variant_arg(&self, idx: uint, f: &fn());
fn emit_borrowed_vec(&self, len: uint, f: fn());
fn emit_owned_vec(&self, len: uint, f: fn());
fn emit_managed_vec(&self, len: uint, f: fn());
fn emit_vec_elt(&self, idx: uint, f: fn());
fn emit_borrowed_vec(&self, len: uint, f: &fn());
fn emit_owned_vec(&self, len: uint, f: &fn());
fn emit_managed_vec(&self, len: uint, f: &fn());
fn emit_vec_elt(&self, idx: uint, f: &fn());
fn emit_rec(&self, f: fn());
fn emit_struct(&self, name: &str, _len: uint, f: fn());
fn emit_field(&self, f_name: &str, f_idx: uint, f: fn());
fn emit_rec(&self, f: &fn());
fn emit_struct(&self, name: &str, _len: uint, f: &fn());
fn emit_field(&self, f_name: &str, f_idx: uint, f: &fn());
fn emit_tup(&self, len: uint, f: fn());
fn emit_tup_elt(&self, idx: uint, f: fn());
fn emit_tup(&self, len: uint, f: &fn());
fn emit_tup_elt(&self, idx: uint, f: &fn());
}
pub trait Decoder {
@ -86,23 +86,23 @@ pub trait Decoder {
fn read_managed_str(&self) -> @str;
// Compound types:
fn read_enum<T>(&self, name: &str, f: fn() -> T) -> T;
fn read_enum_variant<T>(&self, f: fn(uint) -> T) -> T;
fn read_enum_variant_arg<T>(&self, idx: uint, f: fn() -> T) -> T;
fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T;
fn read_enum_variant<T>(&self, f: &fn(uint) -> T) -> T;
fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T;
fn read_owned<T>(&self, f: fn() -> T) -> T;
fn read_managed<T>(&self, f: fn() -> T) -> T;
fn read_owned<T>(&self, f: &fn() -> T) -> T;
fn read_managed<T>(&self, f: &fn() -> T) -> T;
fn read_owned_vec<T>(&self, f: fn(uint) -> T) -> T;
fn read_managed_vec<T>(&self, f: fn(uint) -> T) -> T;
fn read_vec_elt<T>(&self, idx: uint, f: fn() -> T) -> T;
fn read_owned_vec<T>(&self, f: &fn(uint) -> T) -> T;
fn read_managed_vec<T>(&self, f: &fn(uint) -> T) -> T;
fn read_vec_elt<T>(&self, idx: uint, f: &fn() -> T) -> T;
fn read_rec<T>(&self, f: fn() -> T) -> T;
fn read_struct<T>(&self, name: &str, _len: uint, f: fn() -> T) -> T;
fn read_field<T>(&self, name: &str, idx: uint, f: fn() -> T) -> T;
fn read_rec<T>(&self, f: &fn() -> T) -> T;
fn read_struct<T>(&self, name: &str, _len: uint, f: &fn() -> T) -> T;
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T;
fn read_tup<T>(&self, sz: uint, f: fn() -> T) -> T;
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T;
fn read_tup<T>(&self, sz: uint, f: &fn() -> T) -> T;
fn read_tup_elt<T>(&self, idx: uint, f: &fn() -> T) -> T;
}
pub trait Encodable<S:Encoder> {
@ -547,11 +547,11 @@ impl<
// In some cases, these should eventually be coded as traits.
pub trait EncoderHelpers {
fn emit_from_vec<T>(&self, v: &[T], f: fn(v: &T));
fn emit_from_vec<T>(&self, v: &[T], f: &fn(v: &T));
}
impl<S:Encoder> EncoderHelpers for S {
fn emit_from_vec<T>(&self, v: &[T], f: fn(v: &T)) {
fn emit_from_vec<T>(&self, v: &[T], f: &fn(v: &T)) {
do self.emit_owned_vec(v.len()) {
for v.eachi |i, e| {
do self.emit_vec_elt(i) {
@ -563,11 +563,11 @@ impl<S:Encoder> EncoderHelpers for S {
}
pub trait DecoderHelpers {
fn read_to_vec<T>(&self, f: fn() -> T) -> ~[T];
fn read_to_vec<T>(&self, f: &fn() -> T) -> ~[T];
}
impl<D:Decoder> DecoderHelpers for D {
fn read_to_vec<T>(&self, f: fn() -> T) -> ~[T] {
fn read_to_vec<T>(&self, f: &fn() -> T) -> ~[T] {
do self.read_owned_vec |len| {
do vec::from_fn(len) |i| {
self.read_vec_elt(i, || f())

View File

@ -24,7 +24,7 @@ pub struct SmallIntMap<T> {
impl<V> BaseIter<(uint, &self/V)> for SmallIntMap<V> {
/// Visit all key-value pairs in order
pure fn each(&self, it: fn(&(uint, &self/V)) -> bool) {
pure fn each(&self, it: &fn(&(uint, &self/V)) -> bool) {
for uint::range(0, self.v.len()) |i| {
match self.v[i] {
Some(ref elt) => if !it(&(i, elt)) { break },
@ -38,7 +38,7 @@ impl<V> BaseIter<(uint, &self/V)> for SmallIntMap<V> {
impl<V> ReverseIter<(uint, &self/V)> for SmallIntMap<V> {
/// Visit all key-value pairs in reverse order
pure fn each_reverse(&self, it: fn(&(uint, &self/V)) -> bool) {
pure fn each_reverse(&self, it: &fn(&(uint, &self/V)) -> bool) {
for uint::range_rev(self.v.len(), 0) |i| {
match self.v[i - 1] {
Some(ref elt) => if !it(&(i - 1, elt)) { break },
@ -76,12 +76,12 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
}
/// Visit all keys in order
pure fn each_key(&self, blk: fn(key: &uint) -> bool) {
pure fn each_key(&self, blk: &fn(key: &uint) -> bool) {
self.each(|&(k, _)| blk(&k))
}
/// Visit all values in order
pure fn each_value(&self, blk: fn(value: &V) -> bool) {
pure fn each_value(&self, blk: &fn(value: &V) -> bool) {
self.each(|&(_, v)| blk(v))
}
@ -133,7 +133,7 @@ pub impl<V> SmallIntMap<V> {
pub impl<V:Copy> SmallIntMap<V> {
fn update_with_key(&mut self, key: uint, val: V,
ff: fn(uint, V, V) -> V) -> bool {
ff: &fn(uint, V, V) -> V) -> bool {
let new_val = match self.find(&key) {
None => val,
Some(orig) => ff(key, *orig, val)
@ -141,7 +141,7 @@ pub impl<V:Copy> SmallIntMap<V> {
self.insert(key, new_val)
}
fn update(&mut self, key: uint, newval: V, ff: fn(V, V) -> V) -> bool {
fn update(&mut self, key: uint, newval: V, ff: &fn(V, V) -> V) -> bool {
self.update_with_key(key, newval, |_k, v, v1| ff(v,v1))
}
}

View File

@ -79,8 +79,9 @@ struct SemInner<Q> {
// a condition variable attached, others should.
blocked: Q
}
#[doc(hidden)]
enum Sem<Q> = Exclusive<SemInner<Q>>;
struct Sem<Q>(Exclusive<SemInner<Q>>);
#[doc(hidden)]
fn new_sem<Q:Owned>(count: int, q: Q) -> Sem<Q> {
@ -135,7 +136,7 @@ pub impl<Q:Owned> &self/Sem<Q> {
// FIXME(#3154) move both copies of this into Sem<Q>, and unify the 2 structs
#[doc(hidden)]
pub impl &self/Sem<()> {
fn access<U>(&self, blk: fn() -> U) -> U {
fn access<U>(&self, blk: &fn() -> U) -> U {
let mut release = None;
unsafe {
do task::unkillable {
@ -148,7 +149,7 @@ pub impl &self/Sem<()> {
}
#[doc(hidden)]
pub impl &self/Sem<~[Waitqueue]> {
fn access<U>(&self, blk: fn() -> U) -> U {
fn access<U>(&self, blk: &fn() -> U) -> U {
let mut release = None;
unsafe {
do task::unkillable {
@ -332,7 +333,7 @@ pub impl Condvar/&self {
#[inline(always)]
#[doc(hidden)]
fn check_cvar_bounds<U>(out_of_bounds: Option<uint>, id: uint, act: &str,
blk: fn() -> U) -> U {
blk: &fn() -> U) -> U {
match out_of_bounds {
Some(0) =>
fail!(fmt!("%s with illegal ID %u - this lock has no condvars!",
@ -347,7 +348,7 @@ fn check_cvar_bounds<U>(out_of_bounds: Option<uint>, id: uint, act: &str,
#[doc(hidden)]
pub impl Sem<~[Waitqueue]> {
// The only other place that condvars get built is rwlock_write_mode.
fn access_cond<U>(&self, blk: fn(c: &Condvar) -> U) -> U {
fn access_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
do self.access { blk(&Condvar { sem: self }) }
}
}
@ -385,7 +386,7 @@ pub impl Semaphore {
fn release(&self) { (&self.sem).release() }
/// Run a function with ownership of one of the semaphore's resources.
fn access<U>(&self, blk: fn() -> U) -> U { (&self.sem).access(blk) }
fn access<U>(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) }
}
/****************************************************************************
@ -421,10 +422,10 @@ impl Clone for Mutex {
pub impl Mutex {
/// Run a function with ownership of the mutex.
fn lock<U>(&self, blk: fn() -> U) -> U { (&self.sem).access(blk) }
fn lock<U>(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) }
/// Run a function with ownership of the mutex and a handle to a condvar.
fn lock_cond<U>(&self, blk: fn(c: &Condvar) -> U) -> U {
fn lock_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
(&self.sem).access_cond(blk)
}
}
@ -480,7 +481,7 @@ pub impl RWlock {
* Run a function with the rwlock in read mode. Calls to 'read' from other
* tasks may run concurrently with this one.
*/
fn read<U>(&self, blk: fn() -> U) -> U {
fn read<U>(&self, blk: &fn() -> U) -> U {
let mut release = None;
unsafe {
do task::unkillable {
@ -511,7 +512,7 @@ pub impl RWlock {
* Run a function with the rwlock in write mode. No calls to 'read' or
* 'write' from other tasks will run concurrently with this one.
*/
fn write<U>(&self, blk: fn() -> U) -> U {
fn write<U>(&self, blk: &fn() -> U) -> U {
unsafe {
do task::unkillable {
(&self.order_lock).acquire();
@ -529,7 +530,7 @@ pub impl RWlock {
* the waiting task is signalled. (Note: a writer that waited and then
* was signalled might reacquire the lock before other waiting writers.)
*/
fn write_cond<U>(&self, blk: fn(c: &Condvar) -> U) -> U {
fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
// NB: You might think I should thread the order_lock into the cond
// wait call, so that it gets waited on before access_lock gets
// reacquired upon being woken up. However, (a) this would be not
@ -564,7 +565,7 @@ pub impl RWlock {
* }
* ~~~
*/
fn write_downgrade<U>(&self, blk: fn(v: RWlockWriteMode) -> U) -> U {
fn write_downgrade<U>(&self, blk: &fn(v: RWlockWriteMode) -> U) -> U {
// Implementation slightly different from the slicker 'write's above.
// The exit path is conditional on whether the caller downgrades.
let mut _release = None;
@ -692,16 +693,16 @@ impl Drop for RWlockReadMode/&self { fn finalize(&self) {} }
pub impl RWlockWriteMode/&self {
/// Access the pre-downgrade rwlock in write mode.
fn write<U>(&self, blk: fn() -> U) -> U { blk() }
fn write<U>(&self, blk: &fn() -> U) -> U { blk() }
/// Access the pre-downgrade rwlock in write mode with a condvar.
fn write_cond<U>(&self, blk: fn(c: &Condvar) -> U) -> U {
fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
blk(&Condvar { sem: &self.lock.access_lock })
}
}
pub impl RWlockReadMode/&self {
/// Access the post-downgrade rwlock in read mode.
fn read<U>(&self, blk: fn() -> U) -> U { blk() }
fn read<U>(&self, blk: &fn() -> U) -> U { blk() }
}
/****************************************************************************
@ -1082,7 +1083,7 @@ mod tests {
#[cfg(test)]
pub enum RWlockMode { Read, Write, Downgrade, DowngradeRead }
#[cfg(test)]
pub fn lock_rwlock_in_mode(x: &RWlock, mode: RWlockMode, blk: fn()) {
pub fn lock_rwlock_in_mode(x: &RWlock, mode: RWlockMode, blk: &fn()) {
match mode {
Read => x.read(blk),
Write => x.write(blk),
@ -1239,7 +1240,7 @@ mod tests {
dg1: bool,
dg2: bool) {
// Much like the mutex broadcast test. Downgrade-enabled.
fn lock_cond(x: &RWlock, downgrade: bool, blk: fn(c: &Condvar)) {
fn lock_cond(x: &RWlock, downgrade: bool, blk: &fn(c: &Condvar)) {
if downgrade {
do x.write_downgrade |mode| {
(&mode).write_cond(blk)

View File

@ -96,7 +96,7 @@ impl<K: Ord + TotalOrd, V> Ord for TreeMap<K, V> {
impl<'self, K: TotalOrd, V> BaseIter<(&'self K, &'self V)> for TreeMap<K, V> {
/// Visit all key-value pairs in order
pure fn each(&self, f: fn(&(&self/K, &self/V)) -> bool) {
pure fn each(&self, f: &fn(&(&self/K, &self/V)) -> bool) {
each(&self.root, f)
}
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
@ -107,7 +107,7 @@ impl<'self, K: TotalOrd, V>
for TreeMap<K, V>
{
/// Visit all key-value pairs in reverse order
pure fn each_reverse(&self, f: fn(&(&self/K, &self/V)) -> bool) {
pure fn each_reverse(&self, f: &fn(&(&self/K, &self/V)) -> bool) {
each_reverse(&self.root, f);
}
}
@ -135,10 +135,12 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
}
/// Visit all keys in order
pure fn each_key(&self, f: fn(&K) -> bool) { self.each(|&(k, _)| f(k)) }
pure fn each_key(&self, f: &fn(&K) -> bool) { self.each(|&(k, _)| f(k)) }
/// Visit all values in order
pure fn each_value(&self, f: fn(&V) -> bool) { self.each(|&(_, v)| f(v)) }
pure fn each_value(&self, f: &fn(&V) -> bool) {
self.each(|&(_, v)| f(v))
}
/// Return the value corresponding to the key in the map
pure fn find(&self, key: &K) -> Option<&self/V> {
@ -180,12 +182,12 @@ pub impl<K: TotalOrd, V> TreeMap<K, V> {
static pure fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
/// Visit all keys in reverse order
pure fn each_key_reverse(&self, f: fn(&K) -> bool) {
pure fn each_key_reverse(&self, f: &fn(&K) -> bool) {
self.each_reverse(|&(k, _)| f(k))
}
/// Visit all values in reverse order
pure fn each_value_reverse(&self, f: fn(&V) -> bool) {
pure fn each_value_reverse(&self, f: &fn(&V) -> bool) {
self.each_reverse(|&(_, v)| f(v))
}
@ -225,7 +227,7 @@ pub fn map_next<K, V>(iter: &mut TreeMapIterator/&r<K, V>)
/// Advance the iterator through the map
pub fn map_advance<K, V>(iter: &mut TreeMapIterator/&r<K, V>,
f: fn((&r/K, &r/V)) -> bool) {
f: &fn((&r/K, &r/V)) -> bool) {
loop {
match map_next(iter) {
Some(x) => {
@ -242,13 +244,13 @@ pub struct TreeSet<T> {
impl<T: TotalOrd> BaseIter<T> for TreeSet<T> {
/// Visit all values in order
pure fn each(&self, f: fn(&T) -> bool) { self.map.each_key(f) }
pure fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<T: TotalOrd> ReverseIter<T> for TreeSet<T> {
/// Visit all values in reverse order
pure fn each_reverse(&self, f: fn(&T) -> bool) {
pure fn each_reverse(&self, f: &fn(&T) -> bool) {
self.map.each_key_reverse(f)
}
}
@ -350,7 +352,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
}
/// Visit the values (in-order) representing the difference
pure fn difference(&self, other: &TreeSet<T>, f: fn(&T) -> bool) {
pure fn difference(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
let mut x = self.iter();
let mut y = other.iter();
@ -383,7 +385,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
/// Visit the values (in-order) representing the symmetric difference
pure fn symmetric_difference(&self, other: &TreeSet<T>,
f: fn(&T) -> bool) {
f: &fn(&T) -> bool) {
let mut x = self.iter();
let mut y = other.iter();
@ -422,7 +424,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
}
/// Visit the values (in-order) representing the intersection
pure fn intersection(&self, other: &TreeSet<T>, f: fn(&T) -> bool) {
pure fn intersection(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
let mut x = self.iter();
let mut y = other.iter();
@ -449,7 +451,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
}
/// Visit the values (in-order) representing the union
pure fn union(&self, other: &TreeSet<T>, f: fn(&T) -> bool) {
pure fn union(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
let mut x = self.iter();
let mut y = other.iter();
@ -508,7 +510,7 @@ pub fn set_next<T>(iter: &mut TreeSetIterator/&r<T>) -> Option<&r/T> {
/// Advance the iterator through the set
fn set_advance<T>(iter: &mut TreeSetIterator/&r<T>,
f: fn(&r/T) -> bool) {
f: &fn(&r/T) -> bool) {
do map_advance(&mut iter.iter) |(k, _)| { f(k) }
}
@ -530,7 +532,7 @@ pub impl<K: TotalOrd, V> TreeNode<K, V> {
}
pure fn each<K: TotalOrd, V>(node: &r/Option<~TreeNode<K, V>>,
f: fn(&(&r/K, &r/V)) -> bool) {
f: &fn(&(&r/K, &r/V)) -> bool) {
for node.each |x| {
each(&x.left, f);
if f(&(&x.key, &x.value)) { each(&x.right, f) }
@ -538,7 +540,7 @@ pure fn each<K: TotalOrd, V>(node: &r/Option<~TreeNode<K, V>>,
}
pure fn each_reverse<K: TotalOrd, V>(node: &r/Option<~TreeNode<K, V>>,
f: fn(&(&r/K, &r/V)) -> bool) {
f: &fn(&(&r/K, &r/V)) -> bool) {
for node.each |x| {
each_reverse(&x.right, f);
if f(&(&x.key, &x.value)) { each_reverse(&x.left, f) }

View File

@ -269,7 +269,7 @@ pub impl Context {
Decodable<json::Decoder/&static>>( // FIXME(#5121)
@self,
fn_name:&str,
blk: fn(@Mut<Prep>)->Work<T>) -> Work<T> {
blk: &fn(@Mut<Prep>)->Work<T>) -> Work<T> {
let p = @Mut(Prep {ctxt: self,
fn_name: fn_name.to_owned(),
declared_inputs: LinearMap::new()});

View File

@ -1086,16 +1086,11 @@ pub enum variant_kind {
#[auto_encode]
#[auto_decode]
#[deriving_eq]
pub struct enum_def_ {
pub struct enum_def {
variants: ~[variant],
common: Option<@struct_def>,
}
#[auto_encode]
#[auto_decode]
#[deriving_eq]
pub enum enum_def = enum_def_;
#[auto_encode]
#[auto_decode]
#[deriving_eq]

Some files were not shown because too many files have changed in this diff Show More