Skip to content

Commit d778e57

Browse files
committed
Add RFC 1238's unsafe_destructor_blind_to_params (UGEH) where needed.
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 rust-lang#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.)
1 parent 9868df2 commit d778e57

File tree

12 files changed

+42
-5
lines changed

12 files changed

+42
-5
lines changed

src/liballoc/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
#![feature(unboxed_closures)]
9595
#![feature(unique)]
9696
#![feature(unsafe_no_drop_flag, filling_drop)]
97+
// SNAP 1af31d4
98+
#![allow(unused_features)]
99+
// SNAP 1af31d4
100+
#![allow(unused_attributes)]
101+
#![feature(dropck_parametricity)]
97102
#![feature(unsize)]
98103
#![feature(core_slice_ext)]
99104
#![feature(core_str_ext)]

src/liballoc/raw_vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ impl<T> RawVec<T> {
445445
}
446446

447447
impl<T> Drop for RawVec<T> {
448+
#[unsafe_destructor_blind_to_params]
448449
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
449450
fn drop(&mut self) {
450451
let elem_size = mem::size_of::<T>();

src/libarena/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@
3838
#![feature(ptr_as_ref)]
3939
#![feature(raw)]
4040
#![feature(staged_api)]
41+
#![feature(dropck_parametricity)]
4142
#![cfg_attr(test, feature(test))]
4243

44+
// SNAP 1af31d4
45+
#![allow(unused_features)]
46+
// SNAP 1af31d4
47+
#![allow(unused_attributes)]
48+
4349
extern crate alloc;
4450

4551
use std::cell::{Cell, RefCell};
@@ -510,6 +516,7 @@ impl<T> TypedArena<T> {
510516
}
511517

512518
impl<T> Drop for TypedArena<T> {
519+
#[unsafe_destructor_blind_to_params]
513520
fn drop(&mut self) {
514521
unsafe {
515522
// Determine how much was filled.

src/libcollections/btree/node.rs

+3
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,14 @@ impl<T> DoubleEndedIterator for RawItems<T> {
275275
}
276276

277277
impl<T> Drop for RawItems<T> {
278+
#[unsafe_destructor_blind_to_params]
278279
fn drop(&mut self) {
279280
for _ in self {}
280281
}
281282
}
282283

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

14211423
impl<K, V> Drop for MoveTraversalImpl<K, V> {
1424+
#[unsafe_destructor_blind_to_params]
14221425
fn drop(&mut self) {
14231426
// We need to cleanup the stored values manually, as the RawItems destructor would run
14241427
// after our deallocation.

src/libcollections/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
#![allow(trivial_casts)]
3333
#![cfg_attr(test, allow(deprecated))] // rand
3434

35+
// SNAP 1af31d4
36+
#![allow(unused_features)]
37+
// SNAP 1af31d4
38+
#![allow(unused_attributes)]
39+
3540
#![feature(alloc)]
3641
#![feature(box_patterns)]
3742
#![feature(box_syntax)]
@@ -59,6 +64,7 @@
5964
#![feature(unboxed_closures)]
6065
#![feature(unicode)]
6166
#![feature(unique)]
67+
#![feature(dropck_parametricity)]
6268
#![feature(unsafe_no_drop_flag, filling_drop)]
6369
#![feature(decode_utf16)]
6470
#![feature(utf8_error)]

src/libcollections/linked_list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ impl<T> LinkedList<T> {
655655

656656
#[stable(feature = "rust1", since = "1.0.0")]
657657
impl<T> Drop for LinkedList<T> {
658+
#[unsafe_destructor_blind_to_params]
658659
fn drop(&mut self) {
659660
// Dissolve the linked_list in a loop.
660661
// Just dropping the list_head can lead to stack exhaustion

src/libcollections/vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ impl<T: Ord> Ord for Vec<T> {
13851385

13861386
#[stable(feature = "rust1", since = "1.0.0")]
13871387
impl<T> Drop for Vec<T> {
1388+
#[unsafe_destructor_blind_to_params]
13881389
fn drop(&mut self) {
13891390
// NOTE: this is currently abusing the fact that ZSTs can't impl Drop.
13901391
// Or rather, that impl'ing Drop makes them not zero-sized. This is

src/libcollections/vec_deque.rs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ impl<T: Clone> Clone for VecDeque<T> {
6464

6565
#[stable(feature = "rust1", since = "1.0.0")]
6666
impl<T> Drop for VecDeque<T> {
67+
#[unsafe_destructor_blind_to_params]
6768
fn drop(&mut self) {
6869
self.clear();
6970
// RawVec handles deallocation

src/libstd/collections/hash/table.rs

+1
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> {
999999
}
10001000

10011001
impl<K, V> Drop for RawTable<K, V> {
1002+
#[unsafe_destructor_blind_to_params]
10021003
fn drop(&mut self) {
10031004
if self.capacity == 0 || self.capacity == mem::POST_DROP_USIZE {
10041005
return;

src/libstd/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@
199199
test(no_crate_inject, attr(deny(warnings))),
200200
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
201201

202+
// SNAP 1af31d4
203+
#![allow(unused_features)]
204+
// SNAP 1af31d4
205+
#![allow(unused_attributes)]
206+
202207
#![feature(alloc)]
203208
#![feature(allow_internal_unstable)]
204209
#![feature(associated_consts)]
@@ -241,6 +246,7 @@
241246
#![feature(unboxed_closures)]
242247
#![feature(unicode)]
243248
#![feature(unique)]
249+
#![feature(dropck_parametricity)]
244250
#![feature(unsafe_no_drop_flag, filling_drop)]
245251
#![feature(decode_utf16)]
246252
#![feature(unwind_attributes)]

src/libsyntax/feature_gate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status
136136
// switch to Accepted; see RFC 320)
137137
("unsafe_no_drop_flag", "1.0.0", None, Active),
138138

139-
// Allows using the unsafe_destructor_blind_to_params attribute
140-
// (Needs an RFC link)
141-
("unsafe_destructor_blind_to_params", "1.3.0", Some(28498), Active),
139+
// Allows using the unsafe_destructor_blind_to_params attribute;
140+
// RFC 1238
141+
("dropck_parametricity", "1.3.0", Some(28498), Active),
142142

143143
// Allows the use of custom attributes; RFC 572
144144
("custom_attribute", "1.0.0", None, Active),
@@ -345,7 +345,7 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGat
345345
and may be removed in the future")),
346346
("unsafe_destructor_blind_to_params",
347347
Normal,
348-
Gated("unsafe_destructor_blind_to_params",
348+
Gated("dropck_parametricity",
349349
"unsafe_destructor_blind_to_params has unstable semantics \
350350
and may be removed in the future")),
351351
("unwind", Whitelisted, Gated("unwind_attributes", "#[unwind] is experimental")),

src/test/run-pass/issue-24805-dropck-itemless.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#![allow(non_camel_case_types)]
1515

16+
#![feature(dropck_parametricity)]
17+
1618
trait UserDefined { }
1719

1820
impl UserDefined for i32 { }
@@ -26,7 +28,10 @@ impl<'a, T> UserDefined for &'a T { }
2628
macro_rules! impl_drop {
2729
($Bound:ident, $Id:ident) => {
2830
struct $Id<T:$Bound>(T);
29-
impl <T:$Bound> Drop for $Id<T> { fn drop(&mut self) { } }
31+
impl <T:$Bound> Drop for $Id<T> {
32+
#[unsafe_destructor_blind_to_params]
33+
fn drop(&mut self) { }
34+
}
3035
}
3136
}
3237

0 commit comments

Comments
 (0)