diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-12-15 15:41:30 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-12-22 12:27:07 -0500 |
| commit | 8fe9e4dff6d9d0fdd940835ae377edcb3754f8c1 (patch) | |
| tree | f6a8b3551df4061a76323418007569709e34dcdf /src/libstd/path | |
| parent | 7f6177e64627110e5b9776bd5304d65806081390 (diff) | |
Insert coercions to fn pointer types required for the new types
post-unboxed-closure-conversion. This requires a fair amount of annoying coercions because all the `map` etc types are defined generically over the `F`, so the automatic coercions don't propagate; this is compounded by the need to use `let` and not `as` due to stage0. That said, this pattern is to a large extent temporary and unusual.
Diffstat (limited to 'src/libstd/path')
| -rw-r--r-- | src/libstd/path/posix.rs | 4 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 4 |
2 files changed, 6 insertions, 2 deletions
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) } |
