From 099a34cd95bf54e859f7dd03a21fe8202a5e3f70 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Tue, 21 Sep 2021 04:04:50 -0400 Subject: [PATCH] 2229: Annotate stdlib with insignficant dtors --- library/alloc/src/collections/btree/map.rs | 2 ++ library/alloc/src/collections/linked_list.rs | 1 + library/alloc/src/collections/vec_deque/mod.rs | 1 + library/alloc/src/rc.rs | 1 + library/alloc/src/vec/into_iter.rs | 1 + library/alloc/src/vec/mod.rs | 1 + library/core/src/array/iter.rs | 1 + library/std/src/lazy.rs | 1 + 8 files changed, 9 insertions(+) diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 501a604e7f7..5486f862718 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -162,6 +162,7 @@ pub struct BTreeMap { #[stable(feature = "btree_drop", since = "1.7.0")] unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap { + #[rustc_insignificant_dtor] fn drop(&mut self) { drop(unsafe { ptr::read(self) }.into_iter()) } @@ -1459,6 +1460,7 @@ impl IntoIterator for BTreeMap { #[stable(feature = "btree_drop", since = "1.7.0")] impl Drop for IntoIter { + #[rustc_insignificant_dtor] fn drop(&mut self) { struct DropGuard<'a, K, V>(&'a mut IntoIter); diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 9d45c5082db..9f390cfc955 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -975,6 +975,7 @@ impl LinkedList { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<#[may_dangle] T> Drop for LinkedList { + #[rustc_insignificant_dtor] fn drop(&mut self) { struct DropGuard<'a, T>(&'a mut LinkedList); diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 10144cc17bf..a79aac39c71 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -130,6 +130,7 @@ impl Clone for VecDeque { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<#[may_dangle] T, A: Allocator> Drop for VecDeque { + #[rustc_insignificant_dtor] fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or /// during unwinding). diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 0814652a5d4..8b0d7f19b19 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1441,6 +1441,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc { /// drop(foo); // Doesn't print anything /// drop(foo2); // Prints "dropped!" /// ``` + #[rustc_insignificant_dtor] fn drop(&mut self) { unsafe { self.inner().dec_strong(); diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 0bd152f17a6..36ef96e6595 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -246,6 +246,7 @@ impl Clone for IntoIter { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter { + #[rustc_insignificant_dtor] fn drop(&mut self) { struct DropGuard<'a, T, A: Allocator>(&'a mut IntoIter); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 87a0d371815..ef44b6ef82f 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2746,6 +2746,7 @@ impl Ord for Vec { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec { + #[rustc_insignificant_dtor] fn drop(&mut self) { unsafe { // use drop for [T] diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index ecdbf098819..06867fd8b84 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -180,6 +180,7 @@ impl DoubleEndedIterator for IntoIter { #[stable(feature = "array_value_iter_impls", since = "1.40.0")] impl Drop for IntoIter { + #[rustc_insignificant_dtor] fn drop(&mut self) { // SAFETY: This is safe: `as_mut_slice` returns exactly the sub-slice // of elements that have not been moved out yet and that remain diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs index 5afdb799f0c..3bb4cacb02a 100644 --- a/library/std/src/lazy.rs +++ b/library/std/src/lazy.rs @@ -492,6 +492,7 @@ impl SyncOnceCell { } unsafe impl<#[may_dangle] T> Drop for SyncOnceCell { + #[rustc_insignificant_dtor] fn drop(&mut self) { if self.is_initialized() { // SAFETY: The cell is initialized and being dropped, so it can't