From 3f1a588a941d271a157ad78d0c748a1e95d8da63 Mon Sep 17 00:00:00 2001 From: DutchGhost Date: Thu, 2 Apr 2020 21:35:26 +0200 Subject: stabilize BTreeMap::remove_entry --- src/liballoc/collections/btree/map.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/liballoc/collections') diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index bde66c406af..06e10a0c62d 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -894,7 +894,6 @@ impl BTreeMap { /// Basic usage: /// /// ``` - /// #![feature(btreemap_remove_entry)] /// use std::collections::BTreeMap; /// /// let mut map = BTreeMap::new(); @@ -902,7 +901,7 @@ impl BTreeMap { /// assert_eq!(map.remove_entry(&1), Some((1, "a"))); /// assert_eq!(map.remove_entry(&1), None); /// ``` - #[unstable(feature = "btreemap_remove_entry", issue = "66714")] + #[stable(feature = "btreemap_remove_entry", since = "1.44.0")] pub fn remove_entry(&mut self, key: &Q) -> Option<(K, V)> where K: Borrow, -- cgit 1.4.1-3-g733a5 From cdb6bef4fbaf114e3d8546bf0bb213471a8d0f7c Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 15 Apr 2020 15:37:46 +0200 Subject: Deprecate `Box::into_raw_non_null` Per https://github.com/rust-lang/rust/issues/47336#issuecomment-586589016 --- src/liballoc/boxed.rs | 33 +++++++++++++++++++++------------ src/liballoc/collections/linked_list.rs | 16 +++++++--------- src/liballoc/lib.rs | 1 - src/liballoc/rc.rs | 8 +++----- src/liballoc/sync.rs | 2 +- 5 files changed, 32 insertions(+), 28 deletions(-) (limited to 'src/liballoc/collections') diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index db7420954a0..567fd625582 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -428,7 +428,15 @@ impl Box { #[stable(feature = "box_raw", since = "1.4.0")] #[inline] pub fn into_raw(b: Box) -> *mut T { - Box::into_raw_non_null(b).as_ptr() + let b = mem::ManuallyDrop::new(b); + let mut unique = b.0; + // Box is kind-of a library type, but recognized as a "unique pointer" by + // Stacked Borrows. This function here corresponds to "reborrowing to + // a raw pointer", but there is no actual reborrow here -- so + // without some care, the pointer we are returning here still carries + // the tag of `b`, with `Unique` permission. + // We round-trip through a mutable reference to avoid that. + unsafe { unique.as_mut() as *mut T } } /// Consumes the `Box`, returning the wrapped pointer as `NonNull`. @@ -451,6 +459,7 @@ impl Box { /// /// ``` /// #![feature(box_into_raw_non_null)] + /// #![allow(deprecated)] /// /// let x = Box::new(5); /// let ptr = Box::into_raw_non_null(x); @@ -460,24 +469,24 @@ impl Box { /// let x = unsafe { Box::from_raw(ptr.as_ptr()) }; /// ``` #[unstable(feature = "box_into_raw_non_null", issue = "47336")] + #[rustc_deprecated( + since = "1.44.0", + reason = "use `Box::leak(b).into()` or `NonNull::from(Box::leak(b))` instead" + )] #[inline] pub fn into_raw_non_null(b: Box) -> NonNull { - Box::into_unique(b).into() + Box::leak(b).into() } - #[unstable(feature = "ptr_internals", issue = "none", reason = "use into_raw_non_null instead")] + #[unstable( + feature = "ptr_internals", + issue = "none", + reason = "use `Box::leak(b).into()` or `NonNull::from(Box::leak(b))` instead" + )] #[inline] #[doc(hidden)] pub fn into_unique(b: Box) -> Unique { - let b = mem::ManuallyDrop::new(b); - let mut unique = b.0; - // Box is kind-of a library type, but recognized as a "unique pointer" by - // Stacked Borrows. This function here corresponds to "reborrowing to - // a raw pointer", but there is no actual reborrow here -- so - // without some care, the pointer we are returning here still carries - // the tag of `b`, with `Unique` permission. - // We round-trip through a mutable reference to avoid that. - unsafe { Unique::new_unchecked(unique.as_mut() as *mut T) } + Box::leak(b).into() } /// Consumes and leaks the `Box`, returning a mutable reference, diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 53d4f7239b7..623aa592b60 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -143,7 +143,7 @@ impl LinkedList { unsafe { node.next = self.head; node.prev = None; - let node = Some(Box::into_raw_non_null(node)); + let node = Some(Box::leak(node).into()); match self.head { None => self.tail = node, @@ -184,7 +184,7 @@ impl LinkedList { unsafe { node.next = None; node.prev = self.tail; - let node = Some(Box::into_raw_non_null(node)); + let node = Some(Box::leak(node).into()); match self.tail { None => self.head = node, @@ -1133,11 +1133,9 @@ impl IterMut<'_, T> { Some(prev) => prev, }; - let node = Some(Box::into_raw_non_null(box Node { - next: Some(head), - prev: Some(prev), - element, - })); + let node = Some( + Box::leak(box Node { next: Some(head), prev: Some(prev), element }).into(), + ); // Not creating references to entire nodes to not invalidate the // reference to `element` we handed to the user. @@ -1442,7 +1440,7 @@ impl<'a, T> CursorMut<'a, T> { #[unstable(feature = "linked_list_cursors", issue = "58533")] pub fn insert_after(&mut self, item: T) { unsafe { - let spliced_node = Box::into_raw_non_null(Box::new(Node::new(item))); + let spliced_node = Box::leak(Box::new(Node::new(item))).into(); let node_next = match self.current { None => self.list.head, Some(node) => node.as_ref().next, @@ -1462,7 +1460,7 @@ impl<'a, T> CursorMut<'a, T> { #[unstable(feature = "linked_list_cursors", issue = "58533")] pub fn insert_before(&mut self, item: T) { unsafe { - let spliced_node = Box::into_raw_non_null(Box::new(Node::new(item))); + let spliced_node = Box::leak(Box::new(Node::new(item))).into(); let node_prev = match self.current { None => self.list.tail, Some(node) => node.as_ref().prev, diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 121c1cde548..26eee09e6fa 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -77,7 +77,6 @@ #![feature(allocator_api)] #![feature(allow_internal_unstable)] #![feature(arbitrary_self_types)] -#![feature(box_into_raw_non_null)] #![feature(box_patterns)] #![feature(box_syntax)] #![feature(cfg_sanitize)] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index abc4056cf56..653b4573e2a 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -324,11 +324,9 @@ impl Rc { // pointers, which ensures that the weak destructor never frees // the allocation while the strong destructor is running, even // if the weak pointer is stored inside the strong one. - Self::from_inner(Box::into_raw_non_null(box RcBox { - strong: Cell::new(1), - weak: Cell::new(1), - value, - })) + Self::from_inner( + Box::leak(box RcBox { strong: Cell::new(1), weak: Cell::new(1), value }).into(), + ) } /// Constructs a new `Rc` with uninitialized contents. diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index b1b22e46a7c..59bc8686cf4 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -325,7 +325,7 @@ impl Arc { weak: atomic::AtomicUsize::new(1), data, }; - Self::from_inner(Box::into_raw_non_null(x)) + Self::from_inner(Box::leak(x).into()) } /// Constructs a new `Arc` with uninitialized contents. -- cgit 1.4.1-3-g733a5 From b1fbd797c04ae151003372b9d9fb761fff669790 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Sat, 25 Apr 2020 16:33:11 +0800 Subject: Add missing Send and Sync bounds for linked list Cursor and CursorMut. --- src/liballoc/collections/linked_list.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/liballoc/collections') diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index af341e6c1ca..9321d38f3b7 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -1843,3 +1843,15 @@ unsafe impl Send for IterMut<'_, T> {} #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Sync for IterMut<'_, T> {} + +#[unstable(feature = "linked_list_cursors", issue = "58533")] +unsafe impl Send for Cursor<'_, T> {} + +#[unstable(feature = "linked_list_cursors", issue = "58533")] +unsafe impl Sync for Cursor<'_, T> {} + +#[unstable(feature = "linked_list_cursors", issue = "58533")] +unsafe impl Send for CursorMut<'_, T> {} + +#[unstable(feature = "linked_list_cursors", issue = "58533")] +unsafe impl Sync for CursorMut<'_, T> {} -- cgit 1.4.1-3-g733a5 From 78a034d168260ad89695039dcc38934f938650e2 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Sat, 25 Apr 2020 22:48:16 +0800 Subject: Use the correct bound for `Cursor` `Send` Co-Authored-By: Amanieu d'Antras --- src/liballoc/collections/linked_list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/liballoc/collections') diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 9321d38f3b7..fc12e1e7dd9 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -1845,7 +1845,7 @@ unsafe impl Send for IterMut<'_, T> {} unsafe impl Sync for IterMut<'_, T> {} #[unstable(feature = "linked_list_cursors", issue = "58533")] -unsafe impl Send for Cursor<'_, T> {} +unsafe impl Send for Cursor<'_, T> {} #[unstable(feature = "linked_list_cursors", issue = "58533")] unsafe impl Sync for Cursor<'_, T> {} -- cgit 1.4.1-3-g733a5