Skip to content

Commit ab3adf3

Browse files
committed
Replace unsafe_destructor_blind_to_params with may_dangle
1 parent 4bb6b4a commit ab3adf3

8 files changed

+21
-31
lines changed

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// run-pass
2-
#![allow(deprecated)]
32

43
// Check that item-less traits do not cause dropck to inject extra
54
// region constraints.
65

76
#![allow(non_camel_case_types)]
87

9-
#![feature(dropck_parametricity)]
8+
#![feature(dropck_eyepatch)]
109

1110
trait UserDefined { }
1211

@@ -20,9 +19,8 @@ impl<'a, T> UserDefined for &'a T { }
2019
// ```
2120
macro_rules! impl_drop {
2221
($Bound:ident, $Id:ident) => {
23-
struct $Id<T:$Bound>(T);
24-
impl <T:$Bound> Drop for $Id<T> {
25-
#[unsafe_destructor_blind_to_params]
22+
struct $Id<T: $Bound>(T);
23+
unsafe impl <#[may_dangle] T: $Bound> Drop for $Id<T> {
2624
fn drop(&mut self) { }
2725
}
2826
}

src/test/run-pass/issues/issue-28498-ugeh-ex1.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
// run-pass
2-
#![allow(deprecated)] // FIXME: switch to `#[may_dangle]` below.
32

43
// Example taken from RFC 1238 text
54

65
// https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md
76
// #example-of-the-unguarded-escape-hatch
87

9-
#![feature(dropck_parametricity)]
8+
#![feature(dropck_eyepatch)]
109
use std::cell::Cell;
1110

1211
struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
1312

1413
struct Foo<T> { data: Vec<T> }
1514

16-
impl<T> Drop for Foo<T> {
17-
// Below is the UGEH attribute
18-
#[unsafe_destructor_blind_to_params]
15+
// Below is the UGEH attribute
16+
unsafe impl<#[may_dangle] T> Drop for Foo<T> {
1917
fn drop(&mut self) { }
2018
}
2119

src/test/run-pass/issues/issue-28498-ugeh-with-lifetime-param.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// run-pass
2-
#![allow(deprecated)] // FIXME: switch to `#[may_dangle]` below.
32

43
// Demonstrate the use of the unguarded escape hatch with a lifetime param
54
// to assert that destructor will not access any dead data.
65
//
76
// Compare with compile-fail/issue28498-reject-lifetime-param.rs
87

9-
#![feature(dropck_parametricity)]
8+
#![feature(dropck_eyepatch)]
109

1110
#[derive(Debug)]
1211
struct ScribbleOnDrop(String);
@@ -19,10 +18,9 @@ impl Drop for ScribbleOnDrop {
1918

2019
struct Foo<'a>(u32, &'a ScribbleOnDrop);
2120

22-
impl<'a> Drop for Foo<'a> {
23-
#[unsafe_destructor_blind_to_params]
21+
unsafe impl<#[may_dangle] 'a> Drop for Foo<'a> {
2422
fn drop(&mut self) {
25-
// Use of `unsafe_destructor_blind_to_params` is sound,
23+
// Use of `may_dangle` is sound,
2624
// because destructor never accesses `self.1`.
2725
println!("Dropping Foo({}, _)", self.0);
2826
}

src/test/run-pass/issues/issue-28498-ugeh-with-passed-to-fn.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// run-pass
2-
#![allow(deprecated)] // FIXME: switch to `#[may_dangle]` below.
32

43
// Demonstrate the use of the unguarded escape hatch with a type param in negative position
54
// to assert that destructor will not access any dead data.
@@ -11,7 +10,7 @@
1110
//
1211
// Compare with run-pass/issue28498-ugeh-with-passed-to-fn.rs
1312

14-
#![feature(dropck_parametricity)]
13+
#![feature(dropck_eyepatch)]
1514

1615
#[derive(Debug)]
1716
struct ScribbleOnDrop(String);
@@ -24,10 +23,9 @@ impl Drop for ScribbleOnDrop {
2423

2524
struct Foo<T>(u32, T, Box<for <'r> fn(&'r T) -> String>);
2625

27-
impl<T> Drop for Foo<T> {
28-
#[unsafe_destructor_blind_to_params]
26+
unsafe impl<#[may_dangle] T> Drop for Foo<T> {
2927
fn drop(&mut self) {
30-
// Use of `unsafe_destructor_blind_to_params` is sound,
28+
// Use of `may_dangle` is sound,
3129
// because destructor never passes a `self.1` to the callback
3230
// (in `self.2`) despite having it available.
3331
println!("Dropping Foo({}, _)", self.0);

src/test/run-pass/issues/issue-28498-ugeh-with-trait-bound.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// run-pass
2-
#![allow(deprecated)] // FIXME: switch to `#[may_dangle]` below.
32

43
// Demonstrate the use of the unguarded escape hatch with a trait bound
54
// to assert that destructor will not access any dead data.
65
//
76
// Compare with compile-fail/issue28498-reject-trait-bound.rs
87

9-
#![feature(dropck_parametricity)]
8+
#![feature(dropck_eyepatch)]
109

1110
use std::fmt;
1211

@@ -19,12 +18,11 @@ impl Drop for ScribbleOnDrop {
1918
}
2019
}
2120

22-
struct Foo<T:fmt::Debug>(u32, T);
21+
struct Foo<T: fmt::Debug>(u32, T);
2322

24-
impl<T:fmt::Debug> Drop for Foo<T> {
25-
#[unsafe_destructor_blind_to_params]
23+
unsafe impl<#[may_dangle] T: fmt::Debug> Drop for Foo<T> {
2624
fn drop(&mut self) {
27-
// Use of `unsafe_destructor_blind_to_params` is sound,
25+
// Use of `may_dangle` is sound,
2826
// because destructor never accesses the `Debug::fmt` method
2927
// of `T`, despite having it available.
3028
println!("Dropping Foo({}, _)", self.0);

src/test/ui/span/issue28498-reject-lifetime-param.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Foo<'a>(u32, &'a ScribbleOnDrop);
1616

1717
impl<'a> Drop for Foo<'a> {
1818
fn drop(&mut self) {
19-
// Use of `unsafe_destructor_blind_to_params` is unsound,
19+
// Use of `may_dangle` is unsound,
2020
// because destructor accesses borrowed data in `self.1`
2121
// and we must force that to strictly outlive `self`.
2222
println!("Dropping Foo({}, {:?})", self.0, self.1);

src/test/ui/span/issue28498-reject-passed-to-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Foo<T>(u32, T, Box<for <'r> fn(&'r T) -> String>);
1616

1717
impl<T> Drop for Foo<T> {
1818
fn drop(&mut self) {
19-
// Use of `unsafe_destructor_blind_to_params` is unsound,
19+
// Use of `may_dangle` is unsound,
2020
// because we pass `T` to the callback in `self.2`
2121
// below, and thus potentially read from borrowed data.
2222
println!("Dropping Foo({}, {})", self.0, (self.2)(&self.1));

src/test/ui/span/issue28498-reject-trait-bound.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ impl Drop for ScribbleOnDrop {
1414
}
1515
}
1616

17-
struct Foo<T:fmt::Debug>(u32, T);
17+
struct Foo<T: fmt::Debug>(u32, T);
1818

19-
impl<T:fmt::Debug> Drop for Foo<T> {
19+
impl<T: fmt::Debug> Drop for Foo<T> {
2020
fn drop(&mut self) {
21-
// Use of `unsafe_destructor_blind_to_params` is unsound,
21+
// Use of `may_dangle` is unsound,
2222
// because we access `T` fmt method when we pass `self.1`
2323
// below, and thus potentially read from borrowed data.
2424
println!("Dropping Foo({}, {:?})", self.0, self.1);

0 commit comments

Comments
 (0)