diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 01096c1fd4e..778314f352c 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -1230,6 +1230,7 @@ impl BTreeMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn keys<'a>(&'a self) -> Keys<'a, K, V> { fn first((a, _): (A, B)) -> A { a } + let first: fn((&'a K, &'a V)) -> &'a K = first; // coerce to fn pointer Keys { inner: self.iter().map(first) } } @@ -1251,6 +1252,7 @@ impl BTreeMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn values<'a>(&'a self) -> Values<'a, K, V> { fn second((_, b): (A, B)) -> B { b } + let second: fn((&'a K, &'a V)) -> &'a V = second; // coerce to fn pointer Values { inner: self.iter().map(second) } } diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index e4328a3cb20..4ab9c7a4fcd 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -126,6 +126,7 @@ impl BTreeSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn into_iter(self) -> MoveItems { fn first((a, _): (A, B)) -> A { a } + let first: fn((T, ())) -> T = first; // coerce to fn pointer MoveItems { iter: self.map.into_iter().map(first) } } diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 1babde6066d..553eae4d896 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -144,6 +144,7 @@ impl VecMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn keys<'r>(&'r self) -> Keys<'r, V> { fn first((a, _): (A, B)) -> A { a } + let first: fn((uint, &'r V)) -> uint = first; // coerce to fn pointer Keys { iter: self.iter().map(first) } } @@ -153,6 +154,7 @@ impl VecMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn values<'r>(&'r self) -> Values<'r, V> { fn second((_, b): (A, B)) -> B { b } + let second: fn((uint, &'r V)) -> &'r V = second; // coerce to fn pointer Values { iter: self.iter().map(second) } } @@ -239,6 +241,7 @@ impl VecMap { fn filter((i, v): (uint, Option)) -> Option<(uint, A)> { v.map(|v| (i, v)) } + let filter: fn((uint, Option)) -> Option<(uint, V)> = filter; // coerce to fn ptr let values = replace(&mut self.v, vec!()); MoveItems { iter: values.into_iter().enumerate().filter_map(filter) } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index b592d1db274..1cd4d7b89d6 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2612,6 +2612,9 @@ pub fn iterate(seed: T, f: F) -> Iterate where val.clone() } + // coerce to a fn pointer + let next: fn(&mut IterateState) -> Option = next; + Unfold::new((f, Some(seed), true), next) } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 1cd58aee061..1207c78fa37 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -2101,6 +2101,7 @@ impl StrPrelude for str { else { line } } + let f: fn(&str) -> &str = f; // coerce to fn pointer self.lines().map(f) } diff --git a/src/librustc_trans/trans/basic_block.rs b/src/librustc_trans/trans/basic_block.rs index 476f5e2d618..ab25343ff5f 100644 --- a/src/librustc_trans/trans/basic_block.rs +++ b/src/librustc_trans/trans/basic_block.rs @@ -37,7 +37,10 @@ impl BasicBlock { pub fn pred_iter(self) -> Preds { fn is_a_terminator_inst(user: &Value) -> bool { user.is_a_terminator_inst() } + let is_a_terminator_inst: fn(&Value) -> bool = is_a_terminator_inst; + fn get_parent(user: Value) -> BasicBlock { user.get_parent().unwrap() } + let get_parent: fn(Value) -> BasicBlock = get_parent; self.as_value().user_iter() .filter(is_a_terminator_inst) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 8149864afd4..dc9fd289344 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -838,8 +838,9 @@ impl, V, S, H: Hasher> HashMap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn keys(&self) -> Keys { + pub fn keys<'a>(&'a self) -> Keys<'a, K, V> { fn first((a, _): (A, B)) -> A { a } + let first: fn((&'a K,&'a V)) -> &'a K = first; // coerce to fn ptr Keys { inner: self.iter().map(first) } } @@ -862,8 +863,9 @@ impl, V, S, H: Hasher> HashMap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn values(&self) -> Values { + pub fn values<'a>(&'a self) -> Values<'a, K, V> { fn second((_, b): (A, B)) -> B { b } + let second: fn((&'a K,&'a V)) -> &'a V = second; // coerce to fn ptr Values { inner: self.iter().map(second) } } @@ -938,6 +940,7 @@ impl, V, S, H: Hasher> HashMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn into_iter(self) -> MoveEntries { fn last_two((_, b, c): (A, B, C)) -> (B, C) { (b, c) } + let last_two: fn((SafeHash, K, V)) -> (K, V) = last_two; MoveEntries { inner: self.table.into_iter().map(last_two) @@ -1007,6 +1010,7 @@ impl, V, S, H: Hasher> HashMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn drain(&mut self) -> Drain { fn last_two((_, b, c): (A, B, C)) -> (B, C) { (b, c) } + let last_two: fn((SafeHash, K, V)) -> (K, V) = last_two; // coerce to fn pointer Drain { inner: self.table.drain().map(last_two), diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index f587669d3da..15ac3394d41 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -277,6 +277,7 @@ impl, S, H: Hasher> HashSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn into_iter(self) -> IntoIter { fn first((a, _): (A, B)) -> A { a } + let first: fn((T, ())) -> T = first; IntoIter { iter: self.map.into_iter().map(first) } } @@ -419,6 +420,8 @@ impl, S, H: Hasher> HashSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn drain(&mut self) -> Drain { fn first((a, _): (A, B)) -> A { a } + let first: fn((T, ())) -> T = first; // coerce to fn pointer + Drain { iter: self.map.drain().map(first) } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 88907951673..0808b2a4f42 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -390,6 +390,7 @@ impl Path { let v = if self.repr[0] == SEP_BYTE { self.repr[1..] } else { self.repr.as_slice() }; + let is_sep_byte: fn(&u8) -> bool = is_sep_byte; // coerce to fn ptr let mut ret = v.split(is_sep_byte); if v.is_empty() { // consume the empty "" component @@ -401,7 +402,8 @@ impl Path { /// Returns an iterator that yields each component of the path as Option<&str>. /// See components() for details. pub fn str_components<'a>(&'a self) -> StrComponents<'a> { - self.components().map(str::from_utf8) + let from_utf8: fn(&[u8]) -> Option<&str> = str::from_utf8; // coerce to fn ptr + self.components().map(from_utf8) } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 9e4a66e0e5e..4b8fb7fad6a 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -655,7 +655,8 @@ impl Path { None if repr.as_bytes()[0] == SEP_BYTE => repr.slice_from(1), None => repr }; - let ret = s.split_terminator(SEP).map(Some); + let some: fn(&'a str) -> Option<&'a str> = Some; // coerce to fn ptr + let ret = s.split_terminator(SEP).map(some); ret } @@ -666,6 +667,7 @@ impl Path { #![inline] x.unwrap().as_bytes() } + let convert: for<'b> fn(Option<&'b str>) -> &'b [u8] = convert; // coerce to fn ptr self.str_components().map(convert) } diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 5e98109c432..88d87717ff3 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -143,7 +143,10 @@ impl UnicodeStrPrelude for str { #[inline] fn words(&self) -> Words { fn is_not_empty(s: &&str) -> bool { !s.is_empty() } + let is_not_empty: fn(&&str) -> bool = is_not_empty; // coerce to fn pointer + fn is_whitespace(c: char) -> bool { c.is_whitespace() } + let is_whitespace: fn(char) -> bool = is_whitespace; // coerce to fn pointer self.split(is_whitespace).filter(is_not_empty) }