diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-02-18 15:34:32 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-02-18 15:34:48 -0800 |
| commit | 2cdbd288ac0606902885434e1ccd8d8bde68913d (patch) | |
| tree | 9a7d37f7dd44424182797c76d49ba0ece99f9513 /src/libstd | |
| parent | 365bd9a9e3b9dafa98e26982353fd28a6ca1efef (diff) | |
| parent | a99e698628cbd396c8100ef776d10ac61d911847 (diff) | |
| download | rust-2cdbd288ac0606902885434e1ccd8d8bde68913d.tar.gz rust-2cdbd288ac0606902885434e1ccd8d8bde68913d.zip | |
rollup merge of #22210: aturon/stab-final-borrow
Conflicts: src/libcollections/btree/map.rs src/libcollections/str.rs src/libcollections/vec.rs src/libcore/borrow.rs src/libcore/hash/mod.rs src/libstd/collections/hash/map.rs src/libstd/collections/hash/set.rs
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 26 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 6 | ||||
| -rw-r--r-- | src/libstd/ffi/os_str.rs | 9 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 2 | ||||
| -rwxr-xr-x | src/libstd/path.rs | 18 |
5 files changed, 33 insertions, 28 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 04f8bb0b0db..ade4f1f0533 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -14,7 +14,7 @@ use self::Entry::*; use self::SearchResult::*; use self::VacantEntryState::*; -use borrow::BorrowFrom; +use borrow::Borrow; use clone::Clone; use cmp::{max, Eq, PartialEq}; use default::Default; @@ -451,18 +451,18 @@ impl<K, V, S> HashMap<K, V, S> /// If you already have the hash for the key lying around, use /// search_hashed. fn search<'a, Q: ?Sized>(&'a self, q: &Q) -> Option<FullBucketImm<'a, K, V>> - where Q: BorrowFrom<K> + Eq + Hash + where K: Borrow<Q>, Q: Eq + Hash { let hash = self.make_hash(q); - search_hashed(&self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k))) + search_hashed(&self.table, hash, |k| q.eq(k.borrow())) .into_option() } fn search_mut<'a, Q: ?Sized>(&'a mut self, q: &Q) -> Option<FullBucketMut<'a, K, V>> - where Q: BorrowFrom<K> + Eq + Hash + where K: Borrow<Q>, Q: Eq + Hash { let hash = self.make_hash(q); - search_hashed(&mut self.table, hash, |k| q.eq(BorrowFrom::borrow_from(k))) + search_hashed(&mut self.table, hash, |k| q.eq(k.borrow())) .into_option() } @@ -1033,7 +1033,7 @@ impl<K, V, S> HashMap<K, V, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> - where Q: Hash + Eq + BorrowFrom<K> + where K: Borrow<Q>, Q: Hash + Eq { self.search(k).map(|bucket| bucket.into_refs().1) } @@ -1056,7 +1056,7 @@ impl<K, V, S> HashMap<K, V, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool - where Q: Hash + Eq + BorrowFrom<K> + where K: Borrow<Q>, Q: Hash + Eq { self.search(k).is_some() } @@ -1082,7 +1082,7 @@ impl<K, V, S> HashMap<K, V, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V> - where Q: Hash + Eq + BorrowFrom<K> + where K: Borrow<Q>, Q: Hash + Eq { self.search_mut(k).map(|bucket| bucket.into_mut_refs().1) } @@ -1134,7 +1134,7 @@ impl<K, V, S> HashMap<K, V, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V> - where Q: Hash + Eq + BorrowFrom<K> + where K: Borrow<Q>, Q: Hash + Eq { if self.table.size() == 0 { return None @@ -1236,8 +1236,8 @@ impl<K, V, S> Default for HashMap<K, V, S> #[stable(feature = "rust1", since = "1.0.0")] impl<K, Q: ?Sized, V, S> Index<Q> for HashMap<K, V, S> - where K: Eq + Hash, - Q: Eq + Hash + BorrowFrom<K>, + where K: Eq + Hash + Borrow<Q>, + Q: Eq + Hash, S: HashState, { type Output = V; @@ -1250,8 +1250,8 @@ impl<K, Q: ?Sized, V, S> Index<Q> for HashMap<K, V, S> #[stable(feature = "rust1", since = "1.0.0")] impl<K, V, S, Q: ?Sized> IndexMut<Q> for HashMap<K, V, S> - where K: Eq + Hash, - Q: Eq + Hash + BorrowFrom<K>, + where K: Eq + Hash + Borrow<Q>, + Q: Eq + Hash, S: HashState, { #[inline] diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 751dc86f533..e0631a64d44 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -10,7 +10,7 @@ // // ignore-lexer-test FIXME #15883 -use borrow::BorrowFrom; +use borrow::Borrow; use clone::Clone; use cmp::{Eq, PartialEq}; use core::marker::Sized; @@ -460,7 +460,7 @@ impl<T, S> HashSet<T, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool - where Q: BorrowFrom<T> + Hash + Eq + where T: Borrow<Q>, Q: Hash + Eq { self.map.contains_key(value) } @@ -570,7 +570,7 @@ impl<T, S> HashSet<T, S> /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool - where Q: BorrowFrom<T> + Hash + Eq + where T: Borrow<Q>, Q: Hash + Eq { self.map.remove(value).is_some() } diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 4e50e1c293f..feace0bd702 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -34,7 +34,7 @@ use core::prelude::*; -use core::borrow::{BorrowFrom, ToOwned}; +use borrow::{Borrow, ToOwned}; use fmt::{self, Debug}; use mem; use string::{String, CowString}; @@ -285,11 +285,12 @@ impl Debug for OsStr { } } -impl BorrowFrom<OsString> for OsStr { - fn borrow_from(owned: &OsString) -> &OsStr { &owned[] } +impl Borrow<OsStr> for OsString { + fn borrow(&self) -> &OsStr { &self[] } } -impl ToOwned<OsString> for OsStr { +impl ToOwned for OsStr { + type Owned = OsString; fn to_owned(&self) -> OsString { self.to_os_string() } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 7c9a8a7b4b5..fbd403ea593 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -161,7 +161,6 @@ extern crate libc; // NB: These reexports are in the order they should be listed in rustdoc pub use core::any; -pub use core::borrow; pub use core::cell; pub use core::clone; #[cfg(not(test))] pub use core::cmp; @@ -184,6 +183,7 @@ pub use core::error; #[cfg(not(test))] pub use alloc::boxed; pub use alloc::rc; +pub use core_collections::borrow; pub use core_collections::fmt; pub use core_collections::slice; pub use core_collections::str; diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 2ad07462f20..3d95d0f19d1 100755 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -108,12 +108,11 @@ use core::prelude::*; use ascii::*; -use borrow::BorrowFrom; +use borrow::{Borrow, ToOwned, Cow}; use cmp; use iter::{self, IntoIterator}; use mem; use ops::{self, Deref}; -use string::CowString; use vec::Vec; use fmt; @@ -982,12 +981,17 @@ impl ops::Deref for PathBuf { } } -impl BorrowFrom<PathBuf> for Path { - fn borrow_from(owned: &PathBuf) -> &Path { - owned.deref() +impl Borrow<Path> for PathBuf { + fn borrow(&self) -> &Path { + self.deref() } } +impl ToOwned for Path { + type Owned = PathBuf; + fn to_owned(&self) -> PathBuf { self.to_path_buf() } +} + impl cmp::PartialEq for PathBuf { fn eq(&self, other: &PathBuf) -> bool { self.components() == other.components() @@ -1066,10 +1070,10 @@ impl Path { self.inner.to_str() } - /// Convert a `Path` to a `CowString`. + /// Convert a `Path` to a `Cow<str>`. /// /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. - pub fn to_string_lossy(&self) -> CowString { + pub fn to_string_lossy(&self) -> Cow<str> { self.inner.to_string_lossy() } |
