diff --git a/src/ci/scripts/symlink-build-dir.sh b/src/ci/scripts/symlink-build-dir.sh index c77059c00ac2a..50178b9c33ed4 100755 --- a/src/ci/scripts/symlink-build-dir.sh +++ b/src/ci/scripts/symlink-build-dir.sh @@ -24,4 +24,10 @@ elif isLinux && isGitHubActions; then mv "${current_dir}" /mnt/more-space/workspace ln -s /mnt/more-space/workspace "${current_dir}" cd "${current_dir}" + + # Move the Docker data directory to /mnt + sudo systemctl stop docker.service + sudo mv /var/lib/docker /mnt/docker + sudo ln -s /mnt/docker /var/lib/docker + sudo systemctl start docker.service fi diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index 70968964f476e..fc7e91ce47b52 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -653,11 +653,7 @@ impl BTreeMap { /// assert_eq!(map.first_key_value(), Some((&1, &"b"))); /// ``` #[unstable(feature = "map_first_last", issue = "62924")] - pub fn first_key_value(&self) -> Option<(&K, &V)> - where - T: Ord, - K: Borrow, - { + pub fn first_key_value(&self) -> Option<(&K, &V)> { let front = self.root.as_ref()?.as_ref().first_leaf_edge(); front.right_kv().ok().map(Handle::into_kv) } @@ -667,8 +663,6 @@ impl BTreeMap { /// /// # Examples /// - /// Contrived way to `clear` a map: - /// /// ``` /// #![feature(map_first_last)] /// use std::collections::BTreeMap; @@ -676,27 +670,47 @@ impl BTreeMap { /// let mut map = BTreeMap::new(); /// map.insert(1, "a"); /// map.insert(2, "b"); - /// while let Some(entry) = map.first_entry() { - /// let (key, val) = entry.remove_entry(); - /// assert!(!map.contains_key(&key)); + /// if let Some(mut entry) = map.first_entry() { + /// if *entry.key() > 0 { + /// entry.insert("first"); + /// } /// } + /// assert_eq!(*map.get(&1).unwrap(), "first"); + /// assert_eq!(*map.get(&2).unwrap(), "b"); /// ``` #[unstable(feature = "map_first_last", issue = "62924")] - pub fn first_entry(&mut self) -> Option> - where - T: Ord, - K: Borrow, - { + pub fn first_entry(&mut self) -> Option> { let front = self.root.as_mut()?.as_mut().first_leaf_edge(); - if let Ok(kv) = front.right_kv() { - Some(OccupiedEntry { - handle: kv.forget_node_type(), - length: &mut self.length, - _marker: PhantomData, - }) - } else { - None - } + let kv = front.right_kv().ok()?; + Some(OccupiedEntry { + handle: kv.forget_node_type(), + length: &mut self.length, + _marker: PhantomData, + }) + } + + /// Removes and returns the first element in the map. + /// The key of this element is the minimum key that was in the map. + /// + /// # Examples + /// + /// Draining elements in ascending order, while keeping a usable map each iteration. + /// + /// ``` + /// #![feature(map_first_last)] + /// use std::collections::BTreeMap; + /// + /// let mut map = BTreeMap::new(); + /// map.insert(1, "a"); + /// map.insert(2, "b"); + /// while let Some((key, _val)) = map.pop_first() { + /// assert!(map.iter().all(|(k, _v)| *k > key)); + /// } + /// assert!(map.is_empty()); + /// ``` + #[unstable(feature = "map_first_last", issue = "62924")] + pub fn pop_first(&mut self) -> Option<(K, V)> { + self.first_entry().map(|entry| entry.remove_entry()) } /// Returns the last key-value pair in the map. @@ -716,11 +730,7 @@ impl BTreeMap { /// assert_eq!(map.last_key_value(), Some((&2, &"a"))); /// ``` #[unstable(feature = "map_first_last", issue = "62924")] - pub fn last_key_value(&self) -> Option<(&K, &V)> - where - T: Ord, - K: Borrow, - { + pub fn last_key_value(&self) -> Option<(&K, &V)> { let back = self.root.as_ref()?.as_ref().last_leaf_edge(); back.left_kv().ok().map(Handle::into_kv) } @@ -730,8 +740,6 @@ impl BTreeMap { /// /// # Examples /// - /// Contrived way to `clear` a map: - /// /// ``` /// #![feature(map_first_last)] /// use std::collections::BTreeMap; @@ -739,27 +747,47 @@ impl BTreeMap { /// let mut map = BTreeMap::new(); /// map.insert(1, "a"); /// map.insert(2, "b"); - /// while let Some(entry) = map.last_entry() { - /// let (key, val) = entry.remove_entry(); - /// assert!(!map.contains_key(&key)); + /// if let Some(mut entry) = map.last_entry() { + /// if *entry.key() > 0 { + /// entry.insert("last"); + /// } /// } + /// assert_eq!(*map.get(&1).unwrap(), "a"); + /// assert_eq!(*map.get(&2).unwrap(), "last"); /// ``` #[unstable(feature = "map_first_last", issue = "62924")] - pub fn last_entry(&mut self) -> Option> - where - T: Ord, - K: Borrow, - { + pub fn last_entry(&mut self) -> Option> { let back = self.root.as_mut()?.as_mut().last_leaf_edge(); - if let Ok(kv) = back.left_kv() { - Some(OccupiedEntry { - handle: kv.forget_node_type(), - length: &mut self.length, - _marker: PhantomData, - }) - } else { - None - } + let kv = back.left_kv().ok()?; + Some(OccupiedEntry { + handle: kv.forget_node_type(), + length: &mut self.length, + _marker: PhantomData, + }) + } + + /// Removes and returns the last element in the map. + /// The key of this element is the maximum key that was in the map. + /// + /// # Examples + /// + /// Draining elements in descending order, while keeping a usable map each iteration. + /// + /// ``` + /// #![feature(map_first_last)] + /// use std::collections::BTreeMap; + /// + /// let mut map = BTreeMap::new(); + /// map.insert(1, "a"); + /// map.insert(2, "b"); + /// while let Some((key, _val)) = map.pop_last() { + /// assert!(map.iter().all(|(k, _v)| *k < key)); + /// } + /// assert!(map.is_empty()); + /// ``` + #[unstable(feature = "map_first_last", issue = "62924")] + pub fn pop_last(&mut self) -> Option<(K, V)> { + self.last_entry().map(|entry| entry.remove_entry()) } /// Returns `true` if the map contains a value for the specified key. @@ -1699,28 +1727,22 @@ impl Clone for Values<'_, K, V> { #[unstable(feature = "btree_drain_filter", issue = "70530")] pub struct DrainFilter<'a, K, V, F> where - K: 'a + Ord, // This Ord bound should be removed before stabilization. + K: 'a, V: 'a, F: 'a + FnMut(&K, &mut V) -> bool, { pred: F, inner: DrainFilterInner<'a, K, V>, } -pub(super) struct DrainFilterInner<'a, K, V> -where - K: 'a + Ord, - V: 'a, -{ +pub(super) struct DrainFilterInner<'a, K: 'a, V: 'a> { length: &'a mut usize, cur_leaf_edge: Option, K, V, marker::Leaf>, marker::Edge>>, } #[unstable(feature = "btree_drain_filter", issue = "70530")] -impl<'a, K, V, F> Drop for DrainFilter<'a, K, V, F> +impl Drop for DrainFilter<'_, K, V, F> where - K: 'a + Ord, - V: 'a, - F: 'a + FnMut(&K, &mut V) -> bool, + F: FnMut(&K, &mut V) -> bool, { fn drop(&mut self) { self.for_each(drop); @@ -1728,11 +1750,11 @@ where } #[unstable(feature = "btree_drain_filter", issue = "70530")] -impl<'a, K, V, F> fmt::Debug for DrainFilter<'a, K, V, F> +impl fmt::Debug for DrainFilter<'_, K, V, F> where - K: 'a + fmt::Debug + Ord, - V: 'a + fmt::Debug, - F: 'a + FnMut(&K, &mut V) -> bool, + K: fmt::Debug, + V: fmt::Debug, + F: FnMut(&K, &mut V) -> bool, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("DrainFilter").field(&self.inner.peek()).finish() @@ -1740,11 +1762,9 @@ where } #[unstable(feature = "btree_drain_filter", issue = "70530")] -impl<'a, K, V, F> Iterator for DrainFilter<'a, K, V, F> +impl Iterator for DrainFilter<'_, K, V, F> where - K: 'a + Ord, - V: 'a, - F: 'a + FnMut(&K, &mut V) -> bool, + F: FnMut(&K, &mut V) -> bool, { type Item = (K, V); @@ -1757,11 +1777,7 @@ where } } -impl<'a, K, V> DrainFilterInner<'a, K, V> -where - K: 'a + Ord, - V: 'a, -{ +impl<'a, K: 'a, V: 'a> DrainFilterInner<'a, K, V> { /// Allow Debug implementations to predict the next element. pub(super) fn peek(&self) -> Option<(&K, &V)> { let edge = self.cur_leaf_edge.as_ref()?; @@ -1800,12 +1816,7 @@ where } #[unstable(feature = "btree_drain_filter", issue = "70530")] -impl FusedIterator for DrainFilter<'_, K, V, F> -where - K: Ord, - F: FnMut(&K, &mut V) -> bool, -{ -} +impl FusedIterator for DrainFilter<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {} #[stable(feature = "btree_range", since = "1.17.0")] impl<'a, K, V> Iterator for Range<'a, K, V> { diff --git a/src/liballoc/collections/btree/set.rs b/src/liballoc/collections/btree/set.rs index 0b02223def4f8..9bf483f269f6e 100644 --- a/src/liballoc/collections/btree/set.rs +++ b/src/liballoc/collections/btree/set.rs @@ -1094,7 +1094,7 @@ impl<'a, T> IntoIterator for &'a BTreeSet { #[unstable(feature = "btree_drain_filter", issue = "70530")] pub struct DrainFilter<'a, T, F> where - T: 'a + Ord, + T: 'a, F: 'a + FnMut(&T) -> bool, { pred: F, @@ -1102,10 +1102,9 @@ where } #[unstable(feature = "btree_drain_filter", issue = "70530")] -impl<'a, T, F> Drop for DrainFilter<'a, T, F> +impl Drop for DrainFilter<'_, T, F> where - T: 'a + Ord, - F: 'a + FnMut(&T) -> bool, + F: FnMut(&T) -> bool, { fn drop(&mut self) { self.for_each(drop); @@ -1113,10 +1112,10 @@ where } #[unstable(feature = "btree_drain_filter", issue = "70530")] -impl<'a, T, F> fmt::Debug for DrainFilter<'a, T, F> +impl fmt::Debug for DrainFilter<'_, T, F> where - T: 'a + Ord + fmt::Debug, - F: 'a + FnMut(&T) -> bool, + T: fmt::Debug, + F: FnMut(&T) -> bool, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("DrainFilter").field(&self.inner.peek().map(|(k, _)| k)).finish() @@ -1124,10 +1123,9 @@ where } #[unstable(feature = "btree_drain_filter", issue = "70530")] -impl<'a, 'f, T, F> Iterator for DrainFilter<'a, T, F> +impl<'a, T, F> Iterator for DrainFilter<'_, T, F> where - T: 'a + Ord, - F: 'a + 'f + FnMut(&T) -> bool, + F: 'a + FnMut(&T) -> bool, { type Item = T; @@ -1143,12 +1141,7 @@ where } #[unstable(feature = "btree_drain_filter", issue = "70530")] -impl<'a, T, F> FusedIterator for DrainFilter<'a, T, F> -where - T: 'a + Ord, - F: 'a + FnMut(&T) -> bool, -{ -} +impl FusedIterator for DrainFilter<'_, T, F> where F: FnMut(&T) -> bool {} #[stable(feature = "rust1", since = "1.0.0")] impl Extend for BTreeSet { diff --git a/src/librustc_error_codes/error_codes/E0507.md b/src/librustc_error_codes/error_codes/E0507.md index 1e3457e96c5f8..254751fc45e30 100644 --- a/src/librustc_error_codes/error_codes/E0507.md +++ b/src/librustc_error_codes/error_codes/E0507.md @@ -1,9 +1,4 @@ -You tried to move out of a value which was borrowed. - -This can also happen when using a type implementing `Fn` or `FnMut`, as neither -allows moving out of them (they usually represent closures which can be called -more than once). Much of the text following applies equally well to non-`FnOnce` -closure bodies. +A borrowed value was moved out. Erroneous code example: @@ -32,6 +27,11 @@ you have three choices: * Somehow reclaim the ownership. * Implement the `Copy` trait on the type. +This can also happen when using a type implementing `Fn` or `FnMut`, as neither +allows moving out of them (they usually represent closures which can be called +more than once). Much of the text following applies equally well to non-`FnOnce` +closure bodies. + Examples: ```