mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
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 #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.)
This commit is contained in:
parent
9868df2fd5
commit
d778e57bf6
@ -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)]
|
||||
|
@ -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>();
|
||||
|
@ -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};
|
||||
@ -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.
|
||||
|
@ -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 })
|
||||
@ -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.
|
||||
|
@ -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)]
|
||||
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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)]
|
||||
@ -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)]
|
||||
|
@ -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),
|
||||
@ -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")),
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#![feature(dropck_parametricity)]
|
||||
|
||||
trait UserDefined { }
|
||||
|
||||
impl UserDefined for i32 { }
|
||||
@ -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) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user