diff --git a/doc/tutorial.md b/doc/tutorial.md
index 79553d5aa6ed0..23ab1ce4400c2 100644
--- a/doc/tutorial.md
+++ b/doc/tutorial.md
@@ -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`.
-
-
-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 {
}
~~~~
+
+
+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
@@ -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 {
diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs
index daa3036687c44..7d0a4d7dcc805 100644
--- a/src/compiletest/header.rs
+++ b/src/compiletest/header.rs
@@ -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();
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index e0db543250d66..f95a530831b93 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -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(),
diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs
index 7a2a15a5421dc..fa19e24aa0830 100644
--- a/src/libcore/at_vec.rs
+++ b/src/libcore/at_vec.rs
@@ -61,7 +61,7 @@ pub pure fn capacity(v: @[const T]) -> uint {
*/
#[inline(always)]
pub pure fn build_sized(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(size: uint,
* onto the vector being constructed.
*/
#[inline(always)]
-pub pure fn build(builder: &fn(push: pure fn(v: A))) -> @[A] {
+pub pure fn build(builder: &fn(push: &pure fn(v: A))) -> @[A] {
build_sized(4, builder)
}
@@ -97,7 +97,7 @@ pub pure fn build(builder: &fn(push: pure fn(v: A))) -> @[A] {
*/
#[inline(always)]
pub pure fn build_sized_opt(size: Option,
- builder: &fn(push: pure fn(v: A))) -> @[A] {
+ builder: &fn(push: &pure fn(v: A))) -> @[A] {
build_sized(size.get_or_default(4), builder)
}
diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs
index 13b8d0fc907fd..512855d8f86c0 100644
--- a/src/libcore/bool.rs
+++ b/src/libcore/bool.rs
@@ -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);
}
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index 8df0037b2afe3..91a4ded60efd6 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -54,7 +54,7 @@ pub impl Cell {
}
// Calls a closure with a reference to the value.
- fn with_ref(&self, op: fn(v: &T) -> R) -> R {
+ fn with_ref(&self, op: &fn(v: &T) -> R) -> R {
let v = self.take();
let r = op(&v);
self.put_back(v);
diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs
index bf1ea5f1150a7..faa6db45df2f6 100644
--- a/src/libcore/cleanup.rs
+++ b/src/libcore/cleanup.rs
@@ -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());
diff --git a/src/libcore/container.rs b/src/libcore/container.rs
index 36424d1bfaaa3..4f1f6004aad77 100644
--- a/src/libcore/container.rs
+++ b/src/libcore/container.rs
@@ -30,10 +30,10 @@ pub trait Map: 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: 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);
}
diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs
index 9cb872a0542a1..1b5d03d9eb8cd 100644
--- a/src/libcore/dlist.rs
+++ b/src/libcore/dlist.rs
@@ -399,7 +399,7 @@ pub impl DList {
}
/// Iterate over nodes.
- pure fn each_node(@mut self, f: fn(@mut DListNode) -> bool) {
+ pure fn each_node(@mut self, f: &fn(@mut DListNode) -> bool) {
let mut link = self.peek_n();
while link.is_some() {
let nobe = link.get();
@@ -507,7 +507,7 @@ impl BaseIter for @mut DList {
* 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);
diff --git a/src/libcore/either.rs b/src/libcore/either.rs
index e26f94261f9f9..e4b7bbbd99e87 100644
--- a/src/libcore/either.rs
+++ b/src/libcore/either.rs
@@ -24,8 +24,8 @@ pub enum Either {
}
#[inline(always)]
-pub fn either(f_left: fn(&T) -> V,
- f_right: fn(&U) -> V, value: &Either) -> V {
+pub fn either(f_left: &fn(&T) -> V,
+ f_right: &fn(&U) -> V, value: &Either) -> V {
/*!
* Applies a function based on the given either value
*
@@ -148,7 +148,7 @@ pub pure fn unwrap_right(eith: Either) -> U {
pub impl Either {
#[inline(always)]
- fn either(&self, f_left: fn(&T) -> V, f_right: fn(&U) -> V) -> V {
+ fn either(&self, f_left: &fn(&T) -> V, f_right: &fn(&U) -> V) -> V {
either(f_left, f_right, self)
}
diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs
index 783f96d9b9e81..2adcee495a738 100644
--- a/src/libcore/hashmap.rs
+++ b/src/libcore/hashmap.rs
@@ -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>) -> bool) {
+ op: &fn(x: &Option>) -> 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
{
/// 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 BaseIter for LinearSet {
/// 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 { Some(self.len()) }
}
@@ -583,7 +583,7 @@ pub mod linear {
}
/// Visit the values representing the difference
- pure fn difference(&self, other: &LinearSet, f: fn(&T) -> bool) {
+ pure fn difference(&self, other: &LinearSet, 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,
- 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, f: fn(&T) -> bool) {
+ pure fn intersection(&self,
+ other: &LinearSet,
+ 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, f: fn(&T) -> bool) {
+ pure fn union(&self, other: &LinearSet, f: &fn(&T) -> bool) {
for self.each |v| {
if !f(v) { return }
}
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index 4634eb8793d95..b04bb15f5e30b 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -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 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(bytes: &[u8], f: fn(@Reader) -> t) -> t {
+pub pure fn with_bytes_reader(bytes: &[u8], f: &fn(@Reader) -> t) -> t {
f(@BytesReader { bytes: bytes, pos: 0u } as @Reader)
}
-pub pure fn with_str_reader(s: &str, f: fn(@Reader) -> T) -> T {
+pub pure fn with_str_reader(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(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(n: u64, size: uint,
}
pub fn u64_to_be_bytes(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,
- 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,
- blk: fn(v: Res)) {
+ blk: &fn(v: Res)) {
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,
- blk: fn(v: Res)) {
+ blk: &fn(v: Res)) {
blk(Res(Arg {
val: o, opt_level: opt_level,
fsync_fn: |o, l| o.fsync(l)
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index c92f747fc9872..8931b4088263e 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -23,22 +23,22 @@ use vec;
pub type InitOp = &self/fn(uint) -> T;
pub trait BaseIter {
- pure fn each(&self, blk: fn(v: &A) -> bool);
+ pure fn each(&self, blk: &fn(v: &A) -> bool);
pure fn size_hint(&self) -> Option;
}
pub trait ReverseIter: BaseIter {
- pure fn each_reverse(&self, blk: fn(&A) -> bool);
+ pure fn each_reverse(&self, blk: &fn(&A) -> bool);
}
pub trait ExtendedIter {
- 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(&self, b0: B, blk: fn(&B, &A) -> B) -> B;
- pure fn position(&self, f: fn(&A) -> bool) -> Option;
- pure fn map_to_vec(&self, op: fn(&A) -> B) -> ~[B];
- pure fn flat_map_to_vec>(&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(&self, b0: B, blk: &fn(&B, &A) -> B) -> B;
+ pure fn position(&self, f: &fn(&A) -> bool) -> Option;
+ pure fn map_to_vec(&self, op: &fn(&A) -> B) -> ~[B];
+ pure fn flat_map_to_vec>(&self, op: &fn(&A) -> IB)
-> ~[B];
}
@@ -48,13 +48,13 @@ pub trait EqIter {
}
pub trait Times {
- pure fn times(&self, it: fn() -> bool);
+ pure fn times(&self, it: &fn() -> bool);
}
pub trait CopyableIter {
- 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;
+ pure fn find(&self, p: &fn(&A) -> bool) -> Option;
}
pub trait CopyableOrderedIter {
@@ -86,12 +86,12 @@ pub trait Buildable {
* 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>(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>(self: &IA,
#[inline(always)]
pub pure fn all>(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>(self: &IA,
#[inline(always)]
pub pure fn any>(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>(self: &IA,
#[inline(always)]
pub pure fn filter_to_vec>(
- 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>(
#[inline(always)]
pub pure fn map_to_vec>(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>(self: &IA,
#[inline(always)]
pub pure fn flat_map_to_vec,IB:BaseIter>(
- 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,IB:BaseIter>(
#[inline(always)]
pub pure fn foldl>(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>(self: &IA, x: &A) -> uint {
}
#[inline(always)]
-pub pure fn position>(self: &IA, f: fn(&A) -> bool)
+pub pure fn position>(self: &IA, f: &fn(&A) -> bool)
-> Option
{
let mut i = 0;
@@ -202,7 +202,7 @@ pub pure fn position>(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>(self: &IA) -> A {
#[inline(always)]
pub pure fn find>(self: &IA,
- f: fn(&A) -> bool) -> Option {
+ f: &fn(&A) -> bool) -> Option {
for self.each |i| {
if f(i) { return Some(*i) }
}
@@ -262,7 +262,7 @@ pub pure fn find>(self: &IA,
* onto the sequence being constructed.
*/
#[inline(always)]
-pub pure fn build>(builder: fn(push: pure fn(A)))
+pub pure fn build>(builder: &fn(push: &pure fn(A)))
-> B {
Buildable::build_sized(4, builder)
}
@@ -283,7 +283,7 @@ pub pure fn build>(builder: fn(push: pure fn(A)))
#[inline(always)]
pub pure fn build_sized_opt>(
size: Option,
- 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>(
/// Applies a function to each element of an iterable and returns the results.
#[inline(always)]
-pub fn map,U,BU: Buildable>(v: &IT, f: fn(&T) -> U)
+pub fn map,U,BU: Buildable>(v: &IT, f: &fn(&T) -> U)
-> BU {
do build_sized_opt(v.size_hint()) |push| {
for v.each() |elem| {
diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs
index 2f59b4c50de04..cef8542823a67 100644
--- a/src/libcore/num/int-template.rs
+++ b/src/libcore/num/int-template.rs
@@ -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(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
+pub pure fn to_str_bytes(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)
diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs
index 11bd7dbfd3ad9..9abbfb03d7a56 100644
--- a/src/libcore/num/uint-template.rs
+++ b/src/libcore/num/uint-template.rs
@@ -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(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
+pub pure fn to_str_bytes(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)
diff --git a/src/libcore/num/uint-template/uint.rs b/src/libcore/num/uint-template/uint.rs
index 6814b0e754199..f73ff4442ceee 100644
--- a/src/libcore/num/uint-template/uint.rs
+++ b/src/libcore/num/uint-template/uint.rs
@@ -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 }
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index 7b0e4d07b53b8..e0393fdf5e35a 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -131,7 +131,7 @@ pub pure fn get_ref(opt: &r/Option) -> &r/T {
}
#[inline(always)]
-pub pure fn map(opt: &r/Option, f: fn(x: &r/T) -> U) -> Option {
+pub pure fn map(opt: &r/Option, f: &fn(x: &r/T) -> U) -> Option {
//! 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(opt: &r/Option, f: fn(x: &r/T) -> U) -> Option {
#[inline(always)]
pub pure fn map_consume(opt: Option,
- f: fn(v: T) -> U) -> Option {
+ f: &fn(v: T) -> U) -> Option {
/*!
* As `map`, but consumes the option and gives `f` ownership to avoid
* copying.
@@ -149,7 +149,7 @@ pub pure fn map_consume(opt: Option,
#[inline(always)]
pub pure fn chain(opt: Option,
- f: fn(t: T) -> Option) -> Option {
+ f: &fn(t: T) -> Option) -> Option {
/*!
* Update an optional value by optionally running its content through a
* function that returns an option.
@@ -163,7 +163,7 @@ pub pure fn chain(opt: Option,
#[inline(always)]
pub pure fn chain_ref(opt: &Option,
- f: fn(x: &T) -> Option) -> Option {
+ f: &fn(x: &T) -> Option) -> Option {
/*!
* 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(opta: Option, optb: Option) -> Option {
}
#[inline(always)]
-pub pure fn while_some(x: Option, blk: fn(v: T) -> Option) {
+pub pure fn while_some(x: Option, blk: &fn(v: T) -> Option) {
//! 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(opt: Option, def: T) -> T {
#[inline(always)]
pub pure fn map_default(opt: &r/Option, 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(opt: Option, reason: &str) -> T {
impl BaseIter for Option {
/// 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 Option {
* through a function that returns an option.
*/
#[inline(always)]
- pure fn chain_ref(&self, f: fn(x: &T) -> Option) -> Option {
+ pure fn chain_ref(&self, f: &fn(x: &T) -> Option) -> Option {
chain_ref(self, f)
}
/// Maps a `some` value from one type to another by reference
#[inline(always)]
- pure fn map(&self, f: fn(&self/T) -> U) -> Option { map(self, f) }
+ pure fn map(&self, f: &fn(&self/T) -> U) -> Option { map(self, f) }
/// As `map`, but consumes the option and gives `f` ownership to avoid
/// copying.
#[inline(always)]
- pure fn map_consume(self, f: fn(v: T) -> U) -> Option {
+ pure fn map_consume(self, f: &fn(v: T) -> U) -> Option {
map_consume(self, f)
}
/// Applies a function to the contained value or returns a default
#[inline(always)]
- pure fn map_default(&self, def: U, f: fn(&self/T) -> U) -> U {
+ pure fn map_default(&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(self, def: U, f: fn(v: T) -> U) -> U {
+ pure fn map_consume_default(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 Option {
/// Applies a function zero or more times until the result is none.
#[inline(always)]
- pure fn while_some(self, blk: fn(v: T) -> Option) {
+ pure fn while_some(self, blk: &fn(v: T) -> Option) {
while_some(self, blk)
}
}
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index 5c73e45364be7..ba16c14a85add 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -75,11 +75,11 @@ pub fn getcwd() -> Path {
}
}
-pub fn as_c_charp(s: &str, f: fn(*c_char) -> T) -> T {
+pub fn as_c_charp(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(s: &str, f: fn(*u16) -> T) -> T {
+ pub fn as_utf16_p(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);
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs
index afb7aef25a3a0..fd823e9dda0d7 100644
--- a/src/libcore/pipes.rs
+++ b/src/libcore/pipes.rs
@@ -246,7 +246,7 @@ pub fn packet() -> *Packet {
#[doc(hidden)]
pub fn entangle_buffer(
buffer: ~Buffer,
- init: fn(*libc::c_void, x: &T) -> *Packet)
+ init: &fn(*libc::c_void, x: &T) -> *Packet)
-> (SendPacketBuffered, RecvPacketBuffered)
{
let p = init(unsafe { reinterpret_cast(&buffer) }, &buffer.data);
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index ebf41dc48f405..b66c1c4696fcf 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -82,7 +82,7 @@ pub unsafe fn buf_len(buf: **T) -> uint {
/// Return the first offset `i` such that `f(buf[i]) == true`.
#[inline(always)]
-pub unsafe fn position(buf: *T, f: fn(&T) -> bool) -> uint {
+pub unsafe fn position(buf: *T, f: &fn(&T) -> bool) -> uint {
let mut i = 0;
loop {
if f(&(*offset(buf, i))) { return i; }
diff --git a/src/libcore/reflect.rs b/src/libcore/reflect.rs
index f29447ef53e33..30c46cd3e35d1 100644
--- a/src/libcore/reflect.rs
+++ b/src/libcore/reflect.rs
@@ -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);
}
diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs
index e9122754eb42a..ad85c5e5ceff4 100644
--- a/src/libcore/repr.rs
+++ b/src/libcore/repr.rs
@@ -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(&self, f: fn(&T)) -> bool {
+ fn get(&self, f: &fn(&T)) -> bool {
unsafe {
f(transmute::<*c_void,&T>(copy self.ptr));
}
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index dd9b55e672580..e3fd279a99609 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -122,7 +122,7 @@ pub pure fn to_either(res: &Result)
* }
*/
#[inline(always)]
-pub pure fn chain(res: Result, op: fn(T)
+pub pure fn chain(res: Result, op: &fn(T)
-> Result) -> Result {
match res {
Ok(t) => op(t),
@@ -141,7 +141,7 @@ pub pure fn chain(res: Result, op: fn(T)
#[inline(always)]
pub pure fn chain_err(
res: Result,
- op: fn(t: V) -> Result)
+ op: &fn(t: V) -> Result)
-> Result {
match res {
Ok(t) => Ok(t),
@@ -164,7 +164,7 @@ pub pure fn chain_err(
* }
*/
#[inline(always)]
-pub pure fn iter(res: &Result, f: fn(&T)) {
+pub pure fn iter(res: &Result, f: &fn(&T)) {
match *res {
Ok(ref t) => f(t),
Err(_) => ()
@@ -180,7 +180,7 @@ pub pure fn iter(res: &Result, f: fn(&T)) {
* handling an error.
*/
#[inline(always)]
-pub pure fn iter_err(res: &Result, f: fn(&E)) {
+pub pure fn iter_err(res: &Result, f: &fn(&E)) {
match *res {
Ok(_) => (),
Err(ref e) => f(e)
@@ -202,7 +202,7 @@ pub pure fn iter_err(res: &Result, f: fn(&E)) {
* }
*/
#[inline(always)]
-pub pure fn map(res: &Result, op: fn(&T) -> U)
+pub pure fn map(res: &Result, op: &fn(&T) -> U)
-> Result {
match *res {
Ok(ref t) => Ok(op(t)),
@@ -219,7 +219,7 @@ pub pure fn map(res: &Result, op: fn(&T) -> U)
* successful result while handling an error.
*/
#[inline(always)]
-pub pure fn map_err(res: &Result, op: fn(&E) -> F)
+pub pure fn map_err(res: &Result, op: &fn(&E) -> F)
-> Result {
match *res {
Ok(copy t) => Ok(t),
@@ -238,10 +238,10 @@ pub impl Result {
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 Result {
pure fn unwrap_err(self) -> E { unwrap_err(self) }
#[inline(always)]
- pure fn chain(self, op: fn(T) -> Result) -> Result {
+ pure fn chain(self, op: &fn(T) -> Result) -> Result {
chain(self, op)
}
#[inline(always)]
- pure fn chain_err(self, op: fn(E) -> Result) -> Result {
+ pure fn chain_err(self, op: &fn(E) -> Result) -> Result {
chain_err(self, op)
}
}
@@ -265,7 +265,7 @@ pub impl Result {
pure fn get(&self) -> T { get(self) }
#[inline(always)]
- pure fn map_err(&self, op: fn(&E) -> F) -> Result {
+ pure fn map_err(&self, op: &fn(&E) -> F) -> Result {
map_err(self, op)
}
}
@@ -275,7 +275,7 @@ pub impl Result {
pure fn get_err(&self) -> E { get_err(self) }
#[inline(always)]
- pure fn map