diff options
| author | bors <bors@rust-lang.org> | 2014-12-19 13:22:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-12-19 13:22:10 +0000 |
| commit | bd90b936d73c0ea2c261cd8e7b9c43764cb2da05 (patch) | |
| tree | 1e06eeba880be012ebfa11ab64911625c17c972e /src/libcore | |
| parent | 0efafac398ff7f28c5f0fe756c15b9008b3e0534 (diff) | |
| parent | ebf1e4f23adba8fc2a4441b8c2a7473c3a7c9d65 (diff) | |
| download | rust-bd90b936d73c0ea2c261cd8e7b9c43764cb2da05.tar.gz rust-bd90b936d73c0ea2c261cd8e7b9c43764cb2da05.zip | |
auto merge of #19884 : nikomatsakis/rust/issue-19730-perfect-forwarding, r=pnkfelix
Rewrite how the HRTB algorithm matches impls against obligations. Instead of impls providing higher-ranked trait-references, impls now once again only have early-bound regions. The skolemization checks are thus moved out into trait matching itself. This allows to implement "perfect forwarding" impls like those described in #19730. This PR builds on a previous PR that was already reviewed by @pnkfelix. r? @pnkfelix Fixes #19730
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/str.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 28110cf7b1a..8fe41c0bd89 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -21,6 +21,7 @@ pub use self::Searcher::{Naive, TwoWay, TwoWayLong}; use char::Char; use char; +use clone::Clone; use cmp::{Eq, mod}; use default::Default; use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator}; @@ -31,7 +32,7 @@ use mem; use num::Int; use option::Option; use option::Option::{None, Some}; -use ops::FnMut; +use ops::{Fn, FnMut}; use ptr::RawPtr; use raw::{Repr, Slice}; use slice::{mod, SliceExt}; @@ -316,7 +317,23 @@ impl<'a> DoubleEndedIterator<(uint, char)> for CharOffsets<'a> { /// External iterator for a string's bytes. /// Use with the `std::iter` module. -pub type Bytes<'a> = Map<&'a u8, u8, slice::Items<'a, u8>, fn(&u8) -> u8>; +pub type Bytes<'a> = Map<&'a u8, u8, slice::Items<'a, u8>, BytesFn>; + +/// A temporary new type wrapper that ensures that the `Bytes` iterator +/// is cloneable. +#[deriving(Copy)] +#[experimental = "iterator type instability"] +pub struct BytesFn(fn(&u8) -> u8); + +impl<'a> Fn(&'a u8) -> u8 for BytesFn { + extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 { + (self.0)(ptr) + } +} + +impl Clone for BytesFn { + fn clone(&self) -> BytesFn { *self } +} /// An iterator over the substrings of a string, separated by `sep`. #[deriving(Clone)] @@ -2009,7 +2026,7 @@ impl StrPrelude for str { fn bytes(&self) -> Bytes { fn deref(&x: &u8) -> u8 { x } - self.as_bytes().iter().map(deref) + self.as_bytes().iter().map(BytesFn(deref)) } #[inline] |
