Skip to content

Commit

Permalink
Add RFC 1238's unsafe_destructor_blind_to_params (UGEH) where needed.
Browse files Browse the repository at this point in the history
I needed it in `RawVec`, `Vec`, and `TypedArena` for `rustc` to
bootstrap; but of course that alone was not sufficient for `make
check`.

Later I added `unsafe_destructor_blind_to_params` to collections, in
particular `LinkedList` and `RawTable` (the backing representation for
`HashMap` and `HashSet`), to get the regression tests exercising
cyclic structure from PR #27185 building.

----

Note that the feature is `dropck_parametricity` (which is not the same
as the attribute's name). We will almost certainly vary our strategy
here in the future, so it makes some sense to have a not-as-ugly name
for the feature gate. (The attribute name was deliberately selected to
be ugly looking.)
  • Loading branch information
pnkfelix committed Oct 6, 2015
1 parent 9868df2 commit d778e57
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/liballoc/lib.rs
Expand Up @@ -94,6 +94,11 @@
#![feature(unboxed_closures)]
#![feature(unique)]
#![feature(unsafe_no_drop_flag, filling_drop)]
// SNAP 1af31d4
#![allow(unused_features)]
// SNAP 1af31d4
#![allow(unused_attributes)]
#![feature(dropck_parametricity)]
#![feature(unsize)]
#![feature(core_slice_ext)]
#![feature(core_str_ext)]
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/raw_vec.rs
Expand Up @@ -445,6 +445,7 @@ impl<T> RawVec<T> {
}

impl<T> Drop for RawVec<T> {
#[unsafe_destructor_blind_to_params]
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
fn drop(&mut self) {
let elem_size = mem::size_of::<T>();
Expand Down
7 changes: 7 additions & 0 deletions src/libarena/lib.rs
Expand Up @@ -38,8 +38,14 @@
#![feature(ptr_as_ref)]
#![feature(raw)]
#![feature(staged_api)]
#![feature(dropck_parametricity)]
#![cfg_attr(test, feature(test))]

// SNAP 1af31d4
#![allow(unused_features)]
// SNAP 1af31d4
#![allow(unused_attributes)]

extern crate alloc;

use std::cell::{Cell, RefCell};
Expand Down Expand Up @@ -510,6 +516,7 @@ impl<T> TypedArena<T> {
}

impl<T> Drop for TypedArena<T> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
unsafe {
// Determine how much was filled.
Expand Down
3 changes: 3 additions & 0 deletions src/libcollections/btree/node.rs
Expand Up @@ -275,12 +275,14 @@ impl<T> DoubleEndedIterator for RawItems<T> {
}

impl<T> Drop for RawItems<T> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
for _ in self {}
}
}

impl<K, V> Drop for Node<K, V> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
if self.keys.is_null() ||
(unsafe { self.keys.get() as *const K as usize == mem::POST_DROP_USIZE })
Expand Down Expand Up @@ -1419,6 +1421,7 @@ impl<K, V> TraversalImpl for MoveTraversalImpl<K, V> {
}

impl<K, V> Drop for MoveTraversalImpl<K, V> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
// We need to cleanup the stored values manually, as the RawItems destructor would run
// after our deallocation.
Expand Down
6 changes: 6 additions & 0 deletions src/libcollections/lib.rs
Expand Up @@ -32,6 +32,11 @@
#![allow(trivial_casts)]
#![cfg_attr(test, allow(deprecated))] // rand

// SNAP 1af31d4
#![allow(unused_features)]
// SNAP 1af31d4
#![allow(unused_attributes)]

#![feature(alloc)]
#![feature(box_patterns)]
#![feature(box_syntax)]
Expand Down Expand Up @@ -59,6 +64,7 @@
#![feature(unboxed_closures)]
#![feature(unicode)]
#![feature(unique)]
#![feature(dropck_parametricity)]
#![feature(unsafe_no_drop_flag, filling_drop)]
#![feature(decode_utf16)]
#![feature(utf8_error)]
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/linked_list.rs
Expand Up @@ -655,6 +655,7 @@ impl<T> LinkedList<T> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for LinkedList<T> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
// Dissolve the linked_list in a loop.
// Just dropping the list_head can lead to stack exhaustion
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/vec.rs
Expand Up @@ -1385,6 +1385,7 @@ impl<T: Ord> Ord for Vec<T> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for Vec<T> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
// NOTE: this is currently abusing the fact that ZSTs can't impl Drop.
// Or rather, that impl'ing Drop makes them not zero-sized. This is
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/vec_deque.rs
Expand Up @@ -64,6 +64,7 @@ impl<T: Clone> Clone for VecDeque<T> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for VecDeque<T> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
self.clear();
// RawVec handles deallocation
Expand Down
1 change: 1 addition & 0 deletions src/libstd/collections/hash/table.rs
Expand Up @@ -999,6 +999,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> {
}

impl<K, V> Drop for RawTable<K, V> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
if self.capacity == 0 || self.capacity == mem::POST_DROP_USIZE {
return;
Expand Down
6 changes: 6 additions & 0 deletions src/libstd/lib.rs
Expand Up @@ -199,6 +199,11 @@
test(no_crate_inject, attr(deny(warnings))),
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]

// SNAP 1af31d4
#![allow(unused_features)]
// SNAP 1af31d4
#![allow(unused_attributes)]

#![feature(alloc)]
#![feature(allow_internal_unstable)]
#![feature(associated_consts)]
Expand Down Expand Up @@ -241,6 +246,7 @@
#![feature(unboxed_closures)]
#![feature(unicode)]
#![feature(unique)]
#![feature(dropck_parametricity)]
#![feature(unsafe_no_drop_flag, filling_drop)]
#![feature(decode_utf16)]
#![feature(unwind_attributes)]
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -136,9 +136,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status
// switch to Accepted; see RFC 320)
("unsafe_no_drop_flag", "1.0.0", None, Active),

// Allows using the unsafe_destructor_blind_to_params attribute
// (Needs an RFC link)
("unsafe_destructor_blind_to_params", "1.3.0", Some(28498), Active),
// Allows using the unsafe_destructor_blind_to_params attribute;
// RFC 1238
("dropck_parametricity", "1.3.0", Some(28498), Active),

// Allows the use of custom attributes; RFC 572
("custom_attribute", "1.0.0", None, Active),
Expand Down Expand Up @@ -345,7 +345,7 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGat
and may be removed in the future")),
("unsafe_destructor_blind_to_params",
Normal,
Gated("unsafe_destructor_blind_to_params",
Gated("dropck_parametricity",
"unsafe_destructor_blind_to_params has unstable semantics \
and may be removed in the future")),
("unwind", Whitelisted, Gated("unwind_attributes", "#[unwind] is experimental")),
Expand Down
7 changes: 6 additions & 1 deletion src/test/run-pass/issue-24805-dropck-itemless.rs
Expand Up @@ -13,6 +13,8 @@

#![allow(non_camel_case_types)]

#![feature(dropck_parametricity)]

trait UserDefined { }

impl UserDefined for i32 { }
Expand All @@ -26,7 +28,10 @@ impl<'a, T> UserDefined for &'a T { }
macro_rules! impl_drop {
($Bound:ident, $Id:ident) => {
struct $Id<T:$Bound>(T);
impl <T:$Bound> Drop for $Id<T> { fn drop(&mut self) { } }
impl <T:$Bound> Drop for $Id<T> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) { }
}
}
}

Expand Down

0 comments on commit d778e57

Please sign in to comment.