Replace unsafe_destructor_blind_to_params with may_dangle
This commit is contained in:
parent
4bb6b4a5ed
commit
ab3adf380d
@ -1,12 +1,11 @@
|
||||
// run-pass
|
||||
#![allow(deprecated)]
|
||||
|
||||
// Check that item-less traits do not cause dropck to inject extra
|
||||
// region constraints.
|
||||
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#![feature(dropck_parametricity)]
|
||||
#![feature(dropck_eyepatch)]
|
||||
|
||||
trait UserDefined { }
|
||||
|
||||
@ -20,9 +19,8 @@ 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> {
|
||||
#[unsafe_destructor_blind_to_params]
|
||||
struct $Id<T: $Bound>(T);
|
||||
unsafe impl <#[may_dangle] T: $Bound> Drop for $Id<T> {
|
||||
fn drop(&mut self) { }
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,19 @@
|
||||
// run-pass
|
||||
#![allow(deprecated)] // FIXME: switch to `#[may_dangle]` below.
|
||||
|
||||
// Example taken from RFC 1238 text
|
||||
|
||||
// https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md
|
||||
// #example-of-the-unguarded-escape-hatch
|
||||
|
||||
#![feature(dropck_parametricity)]
|
||||
#![feature(dropck_eyepatch)]
|
||||
use std::cell::Cell;
|
||||
|
||||
struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
|
||||
|
||||
struct Foo<T> { data: Vec<T> }
|
||||
|
||||
impl<T> Drop for Foo<T> {
|
||||
// Below is the UGEH attribute
|
||||
#[unsafe_destructor_blind_to_params]
|
||||
// Below is the UGEH attribute
|
||||
unsafe impl<#[may_dangle] T> Drop for Foo<T> {
|
||||
fn drop(&mut self) { }
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
// run-pass
|
||||
#![allow(deprecated)] // FIXME: switch to `#[may_dangle]` below.
|
||||
|
||||
// Demonstrate the use of the unguarded escape hatch with a lifetime param
|
||||
// to assert that destructor will not access any dead data.
|
||||
//
|
||||
// Compare with compile-fail/issue28498-reject-lifetime-param.rs
|
||||
|
||||
#![feature(dropck_parametricity)]
|
||||
#![feature(dropck_eyepatch)]
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ScribbleOnDrop(String);
|
||||
@ -19,10 +18,9 @@ impl Drop for ScribbleOnDrop {
|
||||
|
||||
struct Foo<'a>(u32, &'a ScribbleOnDrop);
|
||||
|
||||
impl<'a> Drop for Foo<'a> {
|
||||
#[unsafe_destructor_blind_to_params]
|
||||
unsafe impl<#[may_dangle] 'a> Drop for Foo<'a> {
|
||||
fn drop(&mut self) {
|
||||
// Use of `unsafe_destructor_blind_to_params` is sound,
|
||||
// Use of `may_dangle` is sound,
|
||||
// because destructor never accesses `self.1`.
|
||||
println!("Dropping Foo({}, _)", self.0);
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
// run-pass
|
||||
#![allow(deprecated)] // FIXME: switch to `#[may_dangle]` below.
|
||||
|
||||
// Demonstrate the use of the unguarded escape hatch with a type param in negative position
|
||||
// to assert that destructor will not access any dead data.
|
||||
@ -11,7 +10,7 @@
|
||||
//
|
||||
// Compare with run-pass/issue28498-ugeh-with-passed-to-fn.rs
|
||||
|
||||
#![feature(dropck_parametricity)]
|
||||
#![feature(dropck_eyepatch)]
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ScribbleOnDrop(String);
|
||||
@ -24,10 +23,9 @@ impl Drop for ScribbleOnDrop {
|
||||
|
||||
struct Foo<T>(u32, T, Box<for <'r> fn(&'r T) -> String>);
|
||||
|
||||
impl<T> Drop for Foo<T> {
|
||||
#[unsafe_destructor_blind_to_params]
|
||||
unsafe impl<#[may_dangle] T> Drop for Foo<T> {
|
||||
fn drop(&mut self) {
|
||||
// Use of `unsafe_destructor_blind_to_params` is sound,
|
||||
// Use of `may_dangle` is sound,
|
||||
// because destructor never passes a `self.1` to the callback
|
||||
// (in `self.2`) despite having it available.
|
||||
println!("Dropping Foo({}, _)", self.0);
|
||||
|
@ -1,12 +1,11 @@
|
||||
// run-pass
|
||||
#![allow(deprecated)] // FIXME: switch to `#[may_dangle]` below.
|
||||
|
||||
// Demonstrate the use of the unguarded escape hatch with a trait bound
|
||||
// to assert that destructor will not access any dead data.
|
||||
//
|
||||
// Compare with compile-fail/issue28498-reject-trait-bound.rs
|
||||
|
||||
#![feature(dropck_parametricity)]
|
||||
#![feature(dropck_eyepatch)]
|
||||
|
||||
use std::fmt;
|
||||
|
||||
@ -19,12 +18,11 @@ impl Drop for ScribbleOnDrop {
|
||||
}
|
||||
}
|
||||
|
||||
struct Foo<T:fmt::Debug>(u32, T);
|
||||
struct Foo<T: fmt::Debug>(u32, T);
|
||||
|
||||
impl<T:fmt::Debug> Drop for Foo<T> {
|
||||
#[unsafe_destructor_blind_to_params]
|
||||
unsafe impl<#[may_dangle] T: fmt::Debug> Drop for Foo<T> {
|
||||
fn drop(&mut self) {
|
||||
// Use of `unsafe_destructor_blind_to_params` is sound,
|
||||
// Use of `may_dangle` is sound,
|
||||
// because destructor never accesses the `Debug::fmt` method
|
||||
// of `T`, despite having it available.
|
||||
println!("Dropping Foo({}, _)", self.0);
|
||||
|
@ -16,7 +16,7 @@ struct Foo<'a>(u32, &'a ScribbleOnDrop);
|
||||
|
||||
impl<'a> Drop for Foo<'a> {
|
||||
fn drop(&mut self) {
|
||||
// Use of `unsafe_destructor_blind_to_params` is unsound,
|
||||
// Use of `may_dangle` is unsound,
|
||||
// because destructor accesses borrowed data in `self.1`
|
||||
// and we must force that to strictly outlive `self`.
|
||||
println!("Dropping Foo({}, {:?})", self.0, self.1);
|
||||
|
@ -16,7 +16,7 @@ struct Foo<T>(u32, T, Box<for <'r> fn(&'r T) -> String>);
|
||||
|
||||
impl<T> Drop for Foo<T> {
|
||||
fn drop(&mut self) {
|
||||
// Use of `unsafe_destructor_blind_to_params` is unsound,
|
||||
// Use of `may_dangle` is unsound,
|
||||
// because we pass `T` to the callback in `self.2`
|
||||
// below, and thus potentially read from borrowed data.
|
||||
println!("Dropping Foo({}, {})", self.0, (self.2)(&self.1));
|
||||
|
@ -14,11 +14,11 @@ impl Drop for ScribbleOnDrop {
|
||||
}
|
||||
}
|
||||
|
||||
struct Foo<T:fmt::Debug>(u32, T);
|
||||
struct Foo<T: fmt::Debug>(u32, T);
|
||||
|
||||
impl<T:fmt::Debug> Drop for Foo<T> {
|
||||
impl<T: fmt::Debug> Drop for Foo<T> {
|
||||
fn drop(&mut self) {
|
||||
// Use of `unsafe_destructor_blind_to_params` is unsound,
|
||||
// Use of `may_dangle` is unsound,
|
||||
// because we access `T` fmt method when we pass `self.1`
|
||||
// below, and thus potentially read from borrowed data.
|
||||
println!("Dropping Foo({}, {:?})", self.0, self.1);
|
||||
|
Loading…
Reference in New Issue
Block a user