diff options
| author | bors <bors@rust-lang.org> | 2018-01-09 04:22:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-09 04:22:50 +0000 |
| commit | 74966b5cb84934737d21bd9001db07bd93fa5d64 (patch) | |
| tree | 91adae4383a3e9a5dcbd68543a78ef9adcda5b29 /src/libstd | |
| parent | b5392f54503fdaf04df4b9578510b2baa944f4af (diff) | |
| parent | 9ef98545c9d55e109242b6b3489060ebc690ab05 (diff) | |
| download | rust-74966b5cb84934737d21bd9001db07bd93fa5d64.tar.gz rust-74966b5cb84934737d21bd9001db07bd93fa5d64.zip | |
Auto merge of #47276 - kennytm:rollup, r=kennytm
Rollup of 10 pull requests - Successful merges: #47210, #47233, #47246, #47254, #47256, #47258, #47259, #47263, #47270, #47272 - Failed merges: #47248
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 50 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 21 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/wasm/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/windows/c.rs | 14 |
5 files changed, 67 insertions, 20 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 7a79a472d58..4e5385c17e9 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1241,6 +1241,46 @@ impl<K, V, S> HashMap<K, V, S> self.search_mut(k).into_occupied_bucket().map(|bucket| pop_internal(bucket).1) } + /// Removes a key from the map, returning the stored key and value if the + /// key was previously in the map. + /// + /// The key may be any borrowed form of the map's key type, but + /// [`Hash`] and [`Eq`] on the borrowed form *must* match those for + /// the key type. + /// + /// [`Eq`]: ../../std/cmp/trait.Eq.html + /// [`Hash`]: ../../std/hash/trait.Hash.html + /// + /// # Examples + /// + /// ``` + /// #![feature(hash_map_remove_entry)] + /// use std::collections::HashMap; + /// + /// # fn main() { + /// let mut map = HashMap::new(); + /// map.insert(1, "a"); + /// assert_eq!(map.remove_entry(&1), Some((1, "a"))); + /// assert_eq!(map.remove(&1), None); + /// # } + /// ``` + #[unstable(feature = "hash_map_remove_entry", issue = "46344")] + pub fn remove_entry<Q: ?Sized>(&mut self, k: &Q) -> Option<(K, V)> + where K: Borrow<Q>, + Q: Hash + Eq + { + if self.table.size() == 0 { + return None; + } + + self.search_mut(k) + .into_occupied_bucket() + .map(|bucket| { + let (k, v, _) = pop_internal(bucket); + (k, v) + }) + } + /// Retains only the elements specified by the predicate. /// /// In other words, remove all pairs `(k, v)` such that `f(&k,&mut v)` returns `false`. @@ -3040,7 +3080,7 @@ mod test_map { } #[test] - fn test_pop() { + fn test_remove() { let mut m = HashMap::new(); m.insert(1, 2); assert_eq!(m.remove(&1), Some(2)); @@ -3048,6 +3088,14 @@ mod test_map { } #[test] + fn test_remove_entry() { + let mut m = HashMap::new(); + m.insert(1, 2); + assert_eq!(m.remove_entry(&1), Some((1, 2))); + assert_eq!(m.remove(&1), None); + } + + #[test] fn test_iterate() { let mut m = HashMap::with_capacity(4); for i in 0..32 { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index ad9cf1eed70..33d11ebb350 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -997,9 +997,9 @@ pub trait Write { /// /// Calls to `write` are not guaranteed to block waiting for data to be /// written, and a write which would otherwise block can be indicated through - /// an `Err` variant. + /// an [`Err`] variant. /// - /// If the return value is `Ok(n)` then it must be guaranteed that + /// If the return value is [`Ok(n)`] then it must be guaranteed that /// `0 <= n <= buf.len()`. A return value of `0` typically means that the /// underlying object is no longer able to accept bytes and will likely not /// be able to in the future as well, or that the buffer provided is empty. @@ -1013,9 +1013,13 @@ pub trait Write { /// It is **not** considered an error if the entire buffer could not be /// written to this writer. /// - /// An error of the `ErrorKind::Interrupted` kind is non-fatal and the + /// An error of the [`ErrorKind::Interrupted`] kind is non-fatal and the /// write operation should be retried if there is nothing else to do. /// + /// [`Err`]: ../../std/result/enum.Result.html#variant.Err + /// [`Ok(n)`]: ../../std/result/enum.Result.html#variant.Ok + /// [`ErrorKind::Interrupted`]: ../../std/io/enum.ErrorKind.html#variant.Interrupted + /// /// # Examples /// /// ``` @@ -1061,17 +1065,20 @@ pub trait Write { /// Attempts to write an entire buffer into this write. /// - /// This method will continuously call `write` until there is no more data - /// to be written or an error of non-`ErrorKind::Interrupted` kind is + /// This method will continuously call [`write`] until there is no more data + /// to be written or an error of non-[`ErrorKind::Interrupted`] kind is /// returned. This method will not return until the entire buffer has been /// successfully written or such an error occurs. The first error that is - /// not of `ErrorKind::Interrupted` kind generated from this method will be + /// not of [`ErrorKind::Interrupted`] kind generated from this method will be /// returned. /// /// # Errors /// /// This function will return the first error of - /// non-`ErrorKind::Interrupted` kind that `write` returns. + /// non-[`ErrorKind::Interrupted`] kind that [`write`] returns. + /// + /// [`ErrorKind::Interrupted`]: ../../std/io/enum.ErrorKind.html#variant.Interrupted + /// [`write`]: #tymethod.write /// /// # Examples /// diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 29ea87aaf78..3b79e0c4f82 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -296,7 +296,6 @@ #![feature(rand)] #![feature(raw)] #![feature(repr_align)] -#![feature(repr_simd)] #![feature(rustc_attrs)] #![feature(shared)] #![feature(sip_hash_13)] diff --git a/src/libstd/sys/wasm/mod.rs b/src/libstd/sys/wasm/mod.rs index b838dbafd6f..ba3d6a2813a 100644 --- a/src/libstd/sys/wasm/mod.rs +++ b/src/libstd/sys/wasm/mod.rs @@ -39,6 +39,7 @@ use os::raw::c_char; const DEBUG: bool = false; pub mod args; +#[cfg(feature = "backtrace")] pub mod backtrace; pub mod cmath; pub mod condvar; diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 6e0cccff001..66b44f1402f 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -20,11 +20,6 @@ use os::raw::c_ulonglong; use libc::{wchar_t, size_t, c_void}; use ptr; -#[repr(simd)] -#[repr(C)] -#[cfg(target_arch = "x86_64")] -struct u64x2(u64, u64); - pub use self::FILE_INFO_BY_HANDLE_CLASS::*; pub use self::EXCEPTION_DISPOSITION::*; @@ -700,9 +695,8 @@ pub struct FLOATING_SAVE_AREA { } #[cfg(target_arch = "x86_64")] -#[repr(C)] +#[repr(C, align(16))] pub struct CONTEXT { - _align_hack: [u64x2; 0], // FIXME align on 16-byte pub P1Home: DWORDLONG, pub P2Home: DWORDLONG, pub P3Home: DWORDLONG, @@ -760,17 +754,15 @@ pub struct CONTEXT { } #[cfg(target_arch = "x86_64")] -#[repr(C)] +#[repr(C, align(16))] pub struct M128A { - _align_hack: [u64x2; 0], // FIXME align on 16-byte pub Low: c_ulonglong, pub High: c_longlong } #[cfg(target_arch = "x86_64")] -#[repr(C)] +#[repr(C, align(16))] pub struct FLOATING_SAVE_AREA { - _align_hack: [u64x2; 0], // FIXME align on 16-byte _Dummy: [u8; 512] // FIXME: Fill this out } |
