about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-05-05 02:51:41 +0000
committerbors <bors@rust-lang.org>2020-05-05 02:51:41 +0000
commit04689e22e946879f2f5e2c73849d2f4e1f2b4b32 (patch)
treeff298794d1db2312cfc0fe0f29fbb9d2cb8c01f6 /src/liballoc
parent2454a68cfbb63aa7b8e09fe05114d5f98b2f9740 (diff)
parent8b781b0ffdc751924520f5a705c4e60e7dd4ab36 (diff)
downloadrust-04689e22e946879f2f5e2c73849d2f4e1f2b4b32.tar.gz
rust-04689e22e946879f2f5e2c73849d2f4e1f2b4b32.zip
Auto merge of #71907 - Dylan-DPC:rollup-z8iaqlv, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #71587 (Report cannot move errors in promoted MIR)
 - #71711 (Updates to some ignored tests)
 - #71845 (Add const examples)
 - #71878 (Add remove_current_as_list to LinkedList's CursorMut)
 - #71881 (Correctly handle UEFI targets as Windows-like when emitting sections for LLVM bitcode)
 - #71883 (add a missing "at" in a comment)
 - #71891 (¬∃x. ¬y => ∀x. y)
 - #71892 (Update btree_map::VacantEntry::insert docs to actually call insert)
 - #71902 (Suggest to add missing feature when using gated const features)
 - #71904 (fix typo in function name)

Failed merges:

r? @ghost
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/collections/btree/map.rs11
-rw-r--r--src/liballoc/collections/linked_list.rs25
2 files changed, 30 insertions, 6 deletions
diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs
index c0b976565e4..b8f1a4199c6 100644
--- a/src/liballoc/collections/btree/map.rs
+++ b/src/liballoc/collections/btree/map.rs
@@ -2499,15 +2499,14 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
     ///
     /// ```
     /// use std::collections::BTreeMap;
+    /// use std::collections::btree_map::Entry;
     ///
-    /// let mut count: BTreeMap<&str, usize> = BTreeMap::new();
+    /// let mut map: BTreeMap<&str, u32> = BTreeMap::new();
     ///
-    /// // count the number of occurrences of letters in the vec
-    /// for x in vec!["a","b","a","c","a","b"] {
-    ///     *count.entry(x).or_insert(0) += 1;
+    /// if let Entry::Vacant(o) = map.entry("poneyland") {
+    ///     o.insert(37);
     /// }
-    ///
-    /// assert_eq!(count["a"], 3);
+    /// assert_eq!(map["poneyland"], 37);
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn insert(self, value: V) -> &'a mut V {
diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs
index bfa4045787f..cc0f07b8227 100644
--- a/src/liballoc/collections/linked_list.rs
+++ b/src/liballoc/collections/linked_list.rs
@@ -1496,6 +1496,31 @@ impl<'a, T> CursorMut<'a, T> {
         }
     }
 
+    /// Removes the current element from the `LinkedList` without deallocating the list node.
+    ///
+    /// The node that was removed is returned as a new `LinkedList` containing only this node.
+    /// The cursor is moved to point to the next element in the current `LinkedList`.
+    ///
+    /// If the cursor is currently pointing to the "ghost" non-element then no element
+    /// is removed and `None` is returned.
+    #[unstable(feature = "linked_list_cursors", issue = "58533")]
+    pub fn remove_current_as_list(&mut self) -> Option<LinkedList<T>> {
+        let mut unlinked_node = self.current?;
+        unsafe {
+            self.current = unlinked_node.as_ref().next;
+            self.list.unlink_node(unlinked_node);
+
+            unlinked_node.as_mut().prev = None;
+            unlinked_node.as_mut().next = None;
+            Some(LinkedList {
+                head: Some(unlinked_node),
+                tail: Some(unlinked_node),
+                len: 1,
+                marker: PhantomData,
+            })
+        }
+    }
+
     /// Inserts the elements from the given `LinkedList` after the current one.
     ///
     /// If the cursor is pointing at the "ghost" non-element then the new elements are