Skip to content

Commit 994793f

Browse files
committed
PR fixup
1 parent d2cbe21 commit 994793f

File tree

19 files changed

+86
-62
lines changed

19 files changed

+86
-62
lines changed

compiler/rustc_ty_utils/src/needs_drop.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,22 @@ fn adt_significant_drop_tys(
240240
def_id: DefId,
241241
) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
242242
let adt_has_dtor = |adt_def: &ty::AdtDef| {
243-
adt_def.destructor(tcx).map(|dtor| {
244-
if tcx.has_attr(dtor.did, sym::rustc_insignificant_dtor) {
245-
DtorType::Insignificant
246-
} else {
247-
DtorType::Significant
248-
}
249-
})
243+
let is_marked_insig = tcx.has_attr(adt_def.did, sym::rustc_insignificant_dtor);
244+
if is_marked_insig {
245+
// In some cases like `std::collections::HashMap` where the struct is a wrapper around
246+
// a type that is a Drop type, and the wrapped type (eg: `hashbrown::HashMap`) lies
247+
// outside stdlib, we might choose to still annotate the the wrapper (std HashMap) with
248+
// `rustc_insignificant_dtor`, even if the type itself doesn't have a `Drop` impl.
249+
Some(DtorType::Insignificant)
250+
} else if adt_def.destructor(tcx).is_some() {
251+
// There is a Drop impl and the type isn't marked insignificant, therefore Drop must be
252+
// significant.
253+
Some(DtorType::Significant)
254+
} else {
255+
// No destructor found nor the type is annotated with `rustc_insignificant_dtor`, we
256+
// treat this as the simple case of Drop impl for type.
257+
None
258+
}
250259
};
251260
adt_drop_tys_helper(tcx, def_id, adt_has_dtor)
252261
}

library/alloc/src/collections/btree/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
155155
/// ```
156156
#[stable(feature = "rust1", since = "1.0.0")]
157157
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeMap")]
158+
#[rustc_insignificant_dtor]
158159
pub struct BTreeMap<K, V> {
159160
root: Option<Root<K, V>>,
160161
length: usize,
161162
}
162163

163164
#[stable(feature = "btree_drop", since = "1.7.0")]
164165
unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap<K, V> {
165-
#[rustc_insignificant_dtor]
166166
fn drop(&mut self) {
167167
drop(unsafe { ptr::read(self) }.into_iter())
168168
}
@@ -331,6 +331,7 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IterMut<'_, K, V> {
331331
///
332332
/// [`into_iter`]: IntoIterator::into_iter
333333
#[stable(feature = "rust1", since = "1.0.0")]
334+
#[rustc_insignificant_dtor]
334335
pub struct IntoIter<K, V> {
335336
range: LazyLeafRange<marker::Dying, K, V>,
336337
length: usize,
@@ -1460,7 +1461,6 @@ impl<K, V> IntoIterator for BTreeMap<K, V> {
14601461

14611462
#[stable(feature = "btree_drop", since = "1.7.0")]
14621463
impl<K, V> Drop for IntoIter<K, V> {
1463-
#[rustc_insignificant_dtor]
14641464
fn drop(&mut self) {
14651465
struct DropGuard<'a, K, V>(&'a mut IntoIter<K, V>);
14661466

library/alloc/src/collections/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mod tests;
4343
/// more memory efficient, and make better use of CPU cache.
4444
#[stable(feature = "rust1", since = "1.0.0")]
4545
#[cfg_attr(not(test), rustc_diagnostic_item = "LinkedList")]
46+
#[rustc_insignificant_dtor]
4647
pub struct LinkedList<T> {
4748
head: Option<NonNull<Node<T>>>,
4849
tail: Option<NonNull<Node<T>>>,
@@ -975,7 +976,6 @@ impl<T> LinkedList<T> {
975976

976977
#[stable(feature = "rust1", since = "1.0.0")]
977978
unsafe impl<#[may_dangle] T> Drop for LinkedList<T> {
978-
#[rustc_insignificant_dtor]
979979
fn drop(&mut self) {
980980
struct DropGuard<'a, T>(&'a mut LinkedList<T>);
981981

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const MAXIMUM_ZST_CAPACITY: usize = 1 << (usize::BITS - 1); // Largest possible
9090
/// [`make_contiguous`]: VecDeque::make_contiguous
9191
#[cfg_attr(not(test), rustc_diagnostic_item = "vecdeque_type")]
9292
#[stable(feature = "rust1", since = "1.0.0")]
93+
#[rustc_insignificant_dtor]
9394
pub struct VecDeque<
9495
T,
9596
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
@@ -130,7 +131,6 @@ impl<T: Clone, A: Allocator + Clone> Clone for VecDeque<T, A> {
130131

131132
#[stable(feature = "rust1", since = "1.0.0")]
132133
unsafe impl<#[may_dangle] T, A: Allocator> Drop for VecDeque<T, A> {
133-
#[rustc_insignificant_dtor]
134134
fn drop(&mut self) {
135135
/// Runs the destructor for all items in the slice when it gets dropped (normally or
136136
/// during unwinding).

library/alloc/src/rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ struct RcBox<T: ?Sized> {
305305
/// [get_mut]: Rc::get_mut
306306
#[cfg_attr(not(test), rustc_diagnostic_item = "Rc")]
307307
#[stable(feature = "rust1", since = "1.0.0")]
308+
#[rustc_insignificant_dtor]
308309
pub struct Rc<T: ?Sized> {
309310
ptr: NonNull<RcBox<T>>,
310311
phantom: PhantomData<RcBox<T>>,
@@ -1441,7 +1442,6 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
14411442
/// drop(foo); // Doesn't print anything
14421443
/// drop(foo2); // Prints "dropped!"
14431444
/// ```
1444-
#[rustc_insignificant_dtor]
14451445
fn drop(&mut self) {
14461446
unsafe {
14471447
self.inner().dec_strong();

library/alloc/src/vec/into_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use core::slice::{self};
2222
/// let iter: std::vec::IntoIter<_> = v.into_iter();
2323
/// ```
2424
#[stable(feature = "rust1", since = "1.0.0")]
25+
#[rustc_insignificant_dtor]
2526
pub struct IntoIter<
2627
T,
2728
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
@@ -246,7 +247,6 @@ impl<T: Clone, A: Allocator + Clone> Clone for IntoIter<T, A> {
246247

247248
#[stable(feature = "rust1", since = "1.0.0")]
248249
unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter<T, A> {
249-
#[rustc_insignificant_dtor]
250250
fn drop(&mut self) {
251251
struct DropGuard<'a, T, A: Allocator>(&'a mut IntoIter<T, A>);
252252

library/alloc/src/vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ mod spec_extend;
394394
/// [owned slice]: Box
395395
#[stable(feature = "rust1", since = "1.0.0")]
396396
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_type")]
397+
#[rustc_insignificant_dtor]
397398
pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
398399
buf: RawVec<T, A>,
399400
len: usize,
@@ -2746,7 +2747,6 @@ impl<T: Ord, A: Allocator> Ord for Vec<T, A> {
27462747

27472748
#[stable(feature = "rust1", since = "1.0.0")]
27482749
unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
2749-
#[rustc_insignificant_dtor]
27502750
fn drop(&mut self) {
27512751
unsafe {
27522752
// use drop for [T]

library/core/src/array/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010

1111
/// A by-value [array] iterator.
1212
#[stable(feature = "array_value_iter", since = "1.51.0")]
13+
#[rustc_insignificant_dtor]
1314
pub struct IntoIter<T, const N: usize> {
1415
/// This is the array we are iterating over.
1516
///
@@ -180,7 +181,6 @@ impl<T, const N: usize> DoubleEndedIterator for IntoIter<T, N> {
180181

181182
#[stable(feature = "array_value_iter_impls", since = "1.40.0")]
182183
impl<T, const N: usize> Drop for IntoIter<T, N> {
183-
#[rustc_insignificant_dtor]
184184
fn drop(&mut self) {
185185
// SAFETY: This is safe: `as_mut_slice` returns exactly the sub-slice
186186
// of elements that have not been moved out yet and that remain

library/std/src/collections/hash/map.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ use crate::sys;
205205
206206
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_type")]
207207
#[stable(feature = "rust1", since = "1.0.0")]
208+
#[rustc_insignificant_dtor]
208209
pub struct HashMap<K, V, S = RandomState> {
209210
base: base::HashMap<K, V, S>,
210211
}

library/std/src/lazy.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ impl<T> SyncOnceCell<T> {
492492
}
493493

494494
unsafe impl<#[may_dangle] T> Drop for SyncOnceCell<T> {
495-
#[rustc_insignificant_dtor]
496495
fn drop(&mut self) {
497496
if self.is_initialized() {
498497
// SAFETY: The cell is initialized and being dropped, so it can't

0 commit comments

Comments
 (0)