Skip to content

Commit 119508c

Browse files
committed
Remove drop flags from structs and enums implementing Drop.
1 parent d0654ae commit 119508c

39 files changed

+304
-934
lines changed

src/liballoc/arc.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
121121
/// }
122122
/// ```
123123
124-
#[unsafe_no_drop_flag]
124+
#[cfg_attr(stage0, unsafe_no_drop_flag)]
125125
#[stable(feature = "rust1", since = "1.0.0")]
126126
pub struct Arc<T: ?Sized> {
127127
ptr: Shared<ArcInner<T>>,
@@ -147,7 +147,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
147147
/// nodes behind strong `Arc<T>` pointers, and then storing the parent pointers
148148
/// as `Weak<T>` pointers.
149149
150-
#[unsafe_no_drop_flag]
150+
#[cfg_attr(stage0, unsafe_no_drop_flag)]
151151
#[stable(feature = "arc_weak", since = "1.4.0")]
152152
pub struct Weak<T: ?Sized> {
153153
ptr: Shared<ArcInner<T>>,
@@ -559,15 +559,6 @@ impl<T: ?Sized> Drop for Arc<T> {
559559
#[unsafe_destructor_blind_to_params]
560560
#[inline]
561561
fn drop(&mut self) {
562-
// This structure has #[unsafe_no_drop_flag], so this drop glue may run
563-
// more than once (but it is guaranteed to be zeroed after the first if
564-
// it's run more than once)
565-
let thin = *self.ptr as *const ();
566-
567-
if thin as usize == mem::POST_DROP_USIZE {
568-
return;
569-
}
570-
571562
// Because `fetch_sub` is already atomic, we do not need to synchronize
572563
// with other threads unless we are going to delete the object. This
573564
// same logic applies to the below `fetch_sub` to the `weak` count.
@@ -755,12 +746,6 @@ impl<T: ?Sized> Drop for Weak<T> {
755746
/// ```
756747
fn drop(&mut self) {
757748
let ptr = *self.ptr;
758-
let thin = ptr as *const ();
759-
760-
// see comments above for why this check is here
761-
if thin as usize == mem::POST_DROP_USIZE {
762-
return;
763-
}
764749

765750
// If we find out that we were the last weak pointer, then its time to
766751
// deallocate the data entirely. See the discussion in Arc::drop() about

src/liballoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
#![feature(staged_api)]
8989
#![feature(unboxed_closures)]
9090
#![feature(unique)]
91-
#![feature(unsafe_no_drop_flag, filling_drop)]
91+
#![cfg_attr(stage0, feature(unsafe_no_drop_flag))]
9292
#![feature(unsize)]
9393

9494
#![cfg_attr(not(test), feature(fused, raw, fn_traits, placement_new_protocol))]

src/liballoc/raw_vec.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use core::cmp;
4444
/// `shrink_to_fit`, and `from_box` will actually set RawVec's private capacity
4545
/// field. This allows zero-sized types to not be special-cased by consumers of
4646
/// this type.
47-
#[unsafe_no_drop_flag]
47+
#[cfg_attr(stage0, unsafe_no_drop_flag)]
4848
pub struct RawVec<T> {
4949
ptr: Unique<T>,
5050
cap: usize,
@@ -546,21 +546,14 @@ impl<T> RawVec<T> {
546546
mem::forget(self);
547547
output
548548
}
549-
550-
/// This is a stupid name in the hopes that someone will find this in the
551-
/// not too distant future and remove it with the rest of
552-
/// #[unsafe_no_drop_flag]
553-
pub fn unsafe_no_drop_flag_needs_drop(&self) -> bool {
554-
self.cap != mem::POST_DROP_USIZE
555-
}
556549
}
557550

558551
impl<T> Drop for RawVec<T> {
559552
#[unsafe_destructor_blind_to_params]
560553
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
561554
fn drop(&mut self) {
562555
let elem_size = mem::size_of::<T>();
563-
if elem_size != 0 && self.cap != 0 && self.unsafe_no_drop_flag_needs_drop() {
556+
if elem_size != 0 && self.cap != 0 {
564557
let align = mem::align_of::<T>();
565558

566559
let num_bytes = elem_size * self.cap;

src/liballoc/rc.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct RcBox<T: ?Sized> {
182182
/// A reference-counted pointer type over an immutable value.
183183
///
184184
/// See the [module level documentation](./index.html) for more details.
185-
#[unsafe_no_drop_flag]
185+
#[cfg_attr(stage0, unsafe_no_drop_flag)]
186186
#[stable(feature = "rust1", since = "1.0.0")]
187187
pub struct Rc<T: ?Sized> {
188188
ptr: Shared<RcBox<T>>,
@@ -466,21 +466,18 @@ impl<T: ?Sized> Drop for Rc<T> {
466466
fn drop(&mut self) {
467467
unsafe {
468468
let ptr = *self.ptr;
469-
let thin = ptr as *const ();
470469

471-
if thin as usize != mem::POST_DROP_USIZE {
472-
self.dec_strong();
473-
if self.strong() == 0 {
474-
// destroy the contained object
475-
ptr::drop_in_place(&mut (*ptr).value);
470+
self.dec_strong();
471+
if self.strong() == 0 {
472+
// destroy the contained object
473+
ptr::drop_in_place(&mut (*ptr).value);
476474

477-
// remove the implicit "strong weak" pointer now that we've
478-
// destroyed the contents.
479-
self.dec_weak();
475+
// remove the implicit "strong weak" pointer now that we've
476+
// destroyed the contents.
477+
self.dec_weak();
480478

481-
if self.weak() == 0 {
482-
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr))
483-
}
479+
if self.weak() == 0 {
480+
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr))
484481
}
485482
}
486483
}
@@ -724,7 +721,7 @@ impl<T> From<T> for Rc<T> {
724721
/// dropped.
725722
///
726723
/// See the [module level documentation](./index.html) for more.
727-
#[unsafe_no_drop_flag]
724+
#[cfg_attr(stage0, unsafe_no_drop_flag)]
728725
#[stable(feature = "rc_weak", since = "1.4.0")]
729726
pub struct Weak<T: ?Sized> {
730727
ptr: Shared<RcBox<T>>,
@@ -825,15 +822,12 @@ impl<T: ?Sized> Drop for Weak<T> {
825822
fn drop(&mut self) {
826823
unsafe {
827824
let ptr = *self.ptr;
828-
let thin = ptr as *const ();
829825

830-
if thin as usize != mem::POST_DROP_USIZE {
831-
self.dec_weak();
832-
// the weak count starts at 1, and will only go to zero if all
833-
// the strong pointers have disappeared.
834-
if self.weak() == 0 {
835-
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr))
836-
}
826+
self.dec_weak();
827+
// the weak count starts at 1, and will only go to zero if all
828+
// the strong pointers have disappeared.
829+
if self.weak() == 0 {
830+
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr))
837831
}
838832
}
839833
}

src/libcollections/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#![feature(step_by)]
5353
#![feature(unicode)]
5454
#![feature(unique)]
55-
#![feature(unsafe_no_drop_flag)]
55+
#![cfg_attr(stage0, feature(unsafe_no_drop_flag))]
5656
#![cfg_attr(test, feature(rand, test))]
5757

5858
#![no_std]

src/libcollections/vec.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ use super::range::RangeArgument;
268268
/// Vec does not currently guarantee the order in which elements are dropped
269269
/// (the order has changed in the past, and may change again).
270270
///
271-
#[unsafe_no_drop_flag]
271+
#[cfg_attr(stage0, unsafe_no_drop_flag)]
272272
#[stable(feature = "rust1", since = "1.0.0")]
273273
pub struct Vec<T> {
274274
buf: RawVec<T>,
@@ -1600,11 +1600,9 @@ impl<T: Ord> Ord for Vec<T> {
16001600
impl<T> Drop for Vec<T> {
16011601
#[unsafe_destructor_blind_to_params]
16021602
fn drop(&mut self) {
1603-
if self.buf.unsafe_no_drop_flag_needs_drop() {
1604-
unsafe {
1605-
// use drop for [T]
1606-
ptr::drop_in_place(&mut self[..]);
1607-
}
1603+
unsafe {
1604+
// use drop for [T]
1605+
ptr::drop_in_place(&mut self[..]);
16081606
}
16091607
// RawVec handles deallocation
16101608
}

src/libcore/intrinsics.rs

-13
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,6 @@ extern "rust-intrinsic" {
244244
/// crate it is invoked in.
245245
pub fn type_id<T: ?Sized + 'static>() -> u64;
246246

247-
/// Creates a value initialized to so that its drop flag,
248-
/// if any, says that it has been dropped.
249-
///
250-
/// `init_dropped` is unsafe because it returns a datum with all
251-
/// of its bytes set to the drop flag, which generally does not
252-
/// correspond to a valid value.
253-
///
254-
/// This intrinsic is likely to be deprecated in the future when
255-
/// Rust moves to non-zeroing dynamic drop (and thus removes the
256-
/// embedded drop flags that are being established by this
257-
/// intrinsic).
258-
pub fn init_dropped<T>() -> T;
259-
260247
/// Creates a value initialized to zero.
261248
///
262249
/// `init` is unsafe because it returns a zeroed-out datum,

src/libcore/mem.rs

-71
Original file line numberDiff line numberDiff line change
@@ -241,27 +241,6 @@ pub unsafe fn zeroed<T>() -> T {
241241
intrinsics::init()
242242
}
243243

244-
/// Creates a value initialized to an unspecified series of bytes.
245-
///
246-
/// The byte sequence usually indicates that the value at the memory
247-
/// in question has been dropped. Thus, *if* T carries a drop flag,
248-
/// any associated destructor will not be run when the value falls out
249-
/// of scope.
250-
///
251-
/// Some code at one time used the `zeroed` function above to
252-
/// accomplish this goal.
253-
///
254-
/// This function is expected to be deprecated with the transition
255-
/// to non-zeroing drop.
256-
#[inline]
257-
#[unstable(feature = "filling_drop", issue = "5016")]
258-
pub unsafe fn dropped<T>() -> T {
259-
#[inline(always)]
260-
unsafe fn dropped_impl<T>() -> T { intrinsics::init_dropped() }
261-
262-
dropped_impl()
263-
}
264-
265244
/// Bypasses Rust's normal memory-initialization checks by pretending to
266245
/// produce a value of type T, while doing nothing at all.
267246
///
@@ -518,56 +497,6 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
518497
#[stable(feature = "rust1", since = "1.0.0")]
519498
pub fn drop<T>(_x: T) { }
520499

521-
macro_rules! repeat_u8_as_u16 {
522-
($name:expr) => { (($name as u16) << 8 |
523-
($name as u16)) }
524-
}
525-
macro_rules! repeat_u8_as_u32 {
526-
($name:expr) => { (($name as u32) << 24 |
527-
($name as u32) << 16 |
528-
($name as u32) << 8 |
529-
($name as u32)) }
530-
}
531-
macro_rules! repeat_u8_as_u64 {
532-
($name:expr) => { ((repeat_u8_as_u32!($name) as u64) << 32 |
533-
(repeat_u8_as_u32!($name) as u64)) }
534-
}
535-
536-
// NOTE: Keep synchronized with values used in librustc_trans::trans::adt.
537-
//
538-
// In particular, the POST_DROP_U8 marker must never equal the
539-
// DTOR_NEEDED_U8 marker.
540-
//
541-
// For a while pnkfelix was using 0xc1 here.
542-
// But having the sign bit set is a pain, so 0x1d is probably better.
543-
//
544-
// And of course, 0x00 brings back the old world of zero'ing on drop.
545-
#[unstable(feature = "filling_drop", issue = "5016")]
546-
#[allow(missing_docs)]
547-
pub const POST_DROP_U8: u8 = 0x1d;
548-
#[unstable(feature = "filling_drop", issue = "5016")]
549-
#[allow(missing_docs)]
550-
pub const POST_DROP_U16: u16 = repeat_u8_as_u16!(POST_DROP_U8);
551-
#[unstable(feature = "filling_drop", issue = "5016")]
552-
#[allow(missing_docs)]
553-
pub const POST_DROP_U32: u32 = repeat_u8_as_u32!(POST_DROP_U8);
554-
#[unstable(feature = "filling_drop", issue = "5016")]
555-
#[allow(missing_docs)]
556-
pub const POST_DROP_U64: u64 = repeat_u8_as_u64!(POST_DROP_U8);
557-
558-
#[cfg(target_pointer_width = "16")]
559-
#[unstable(feature = "filling_drop", issue = "5016")]
560-
#[allow(missing_docs)]
561-
pub const POST_DROP_USIZE: usize = POST_DROP_U16 as usize;
562-
#[cfg(target_pointer_width = "32")]
563-
#[unstable(feature = "filling_drop", issue = "5016")]
564-
#[allow(missing_docs)]
565-
pub const POST_DROP_USIZE: usize = POST_DROP_U32 as usize;
566-
#[cfg(target_pointer_width = "64")]
567-
#[unstable(feature = "filling_drop", issue = "5016")]
568-
#[allow(missing_docs)]
569-
pub const POST_DROP_USIZE: usize = POST_DROP_U64 as usize;
570-
571500
/// Interprets `src` as `&U`, and then reads `src` without moving the contained
572501
/// value.
573502
///

src/libcore/ptr.rs

-15
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,6 @@ pub unsafe fn read<T>(src: *const T) -> T {
140140
tmp
141141
}
142142

143-
#[allow(missing_docs)]
144-
#[inline(always)]
145-
#[unstable(feature = "filling_drop",
146-
reason = "may play a larger role in std::ptr future extensions",
147-
issue = "5016")]
148-
pub unsafe fn read_and_drop<T>(dest: *mut T) -> T {
149-
// Copy the data out from `dest`:
150-
let tmp = read(&*dest);
151-
152-
// Now mark `dest` as dropped:
153-
write_bytes(dest, mem::POST_DROP_U8, 1);
154-
155-
tmp
156-
}
157-
158143
/// Overwrites a memory location with the given value without reading or
159144
/// dropping the old value.
160145
///

src/librustc/session/config.rs

-6
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
889889
"adds unstable command line options to rustc interface"),
890890
force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
891891
"force overflow checks on or off"),
892-
force_dropflag_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
893-
"force drop flag checks on or off"),
894892
trace_macros: bool = (false, parse_bool, [UNTRACKED],
895893
"for every macro invocation, print its name and arguments"),
896894
enable_nonzeroing_move_hints: bool = (false, parse_bool, [TRACKED],
@@ -2427,10 +2425,6 @@ mod tests {
24272425
opts.debugging_opts.force_overflow_checks = Some(true);
24282426
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
24292427

2430-
opts = reference.clone();
2431-
opts.debugging_opts.force_dropflag_checks = Some(true);
2432-
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
2433-
24342428
opts = reference.clone();
24352429
opts.debugging_opts.enable_nonzeroing_move_hints = true;
24362430
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

0 commit comments

Comments
 (0)