Skip to content

Commit d70ea7c

Browse files
authored
Rollup merge of rust-lang#62568 - lzutao:replace_may_dangle, r=matthewjasper
Replace unsafe_destructor_blind_to_params with may_dangle This PR will completely remove support for `#[unsafe_destructor_blind_to_params]` attribute, which is deprecated in rust-lang#38970 by `[may_dangle]` unsafe attribute. Closes rust-lang#34761
2 parents e706438 + 8347917 commit d70ea7c

20 files changed

+32
-150
lines changed

src/librustc/ty/util.rs

-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_macros::HashStable;
2222
use std::{cmp, fmt};
2323
use syntax::ast;
2424
use syntax::attr::{self, SignedInt, UnsignedInt};
25-
use syntax::symbol::sym;
2625
use syntax_pos::{Span, DUMMY_SP};
2726

2827
#[derive(Copy, Clone, Debug)]
@@ -435,20 +434,6 @@ impl<'tcx> TyCtxt<'tcx> {
435434
Some(dtor) => dtor.did
436435
};
437436

438-
// RFC 1238: if the destructor method is tagged with the
439-
// attribute `unsafe_destructor_blind_to_params`, then the
440-
// compiler is being instructed to *assume* that the
441-
// destructor will not access borrowed data,
442-
// even if such data is otherwise reachable.
443-
//
444-
// Such access can be in plain sight (e.g., dereferencing
445-
// `*foo.0` of `Foo<'a>(&'a u32)`) or indirectly hidden
446-
// (e.g., calling `foo.0.clone()` of `Foo<T:Clone>`).
447-
if self.has_attr(dtor, sym::unsafe_destructor_blind_to_params) {
448-
debug!("destructor_constraint({:?}) - blind", def.did);
449-
return vec![];
450-
}
451-
452437
let impl_def_id = self.associated_item(dtor).container.id();
453438
let impl_generics = self.generics_of(impl_def_id);
454439

src/librustc_typeck/check/dropck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
246246
///
247247
/// * (1.) `D` has a lifetime- or type-parametric Drop implementation,
248248
/// (where that `Drop` implementation does not opt-out of
249-
/// this check via the `unsafe_destructor_blind_to_params`
249+
/// this check via the `may_dangle`
250250
/// attribute), and
251251
/// * (2.) the structure of `D` can reach a reference of type `&'a _`,
252252
///
@@ -279,7 +279,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
279279
/// instead Drop-Check now simply assumes that if a destructor has
280280
/// access (direct or indirect) to a lifetime parameter, then that
281281
/// lifetime must be forced to outlive that destructor's dynamic
282-
/// extent. We then provide the `unsafe_destructor_blind_to_params`
282+
/// extent. We then provide the `may_dangle`
283283
/// attribute as a way for destructor implementations to opt-out of
284284
/// this conservative assumption (and thus assume the obligation of
285285
/// ensuring that they do not access data nor invoke methods of

src/librustdoc/html/render.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3809,7 +3809,6 @@ const ATTRIBUTE_WHITELIST: &'static [Symbol] = &[
38093809
sym::must_use,
38103810
sym::no_mangle,
38113811
sym::repr,
3812-
sym::unsafe_destructor_blind_to_params,
38133812
sym::non_exhaustive
38143813
];
38153814

src/libsyntax/feature_gate.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ declare_features! (
199199

200200
// no-tracking-issue-end
201201

202-
// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
203-
(active, dropck_parametricity, "1.3.0", Some(28498), None),
204-
205202
// no-tracking-issue-start
206203

207204
// Allows using `#[omit_gdb_pretty_printer_section]`.
@@ -641,6 +638,8 @@ declare_features! (
641638
(removed, extern_in_paths, "1.33.0", Some(55600), None,
642639
Some("subsumed by `::foo::bar` paths")),
643640
(removed, quote, "1.33.0", Some(29601), None, None),
641+
// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
642+
(removed, dropck_parametricity, "1.38.0", Some(28498), None, None),
644643

645644
// -------------------------------------------------------------------------
646645
// feature-group-end: removed features
@@ -1447,15 +1446,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
14471446
cfg_fn!(omit_gdb_pretty_printer_section)
14481447
)
14491448
),
1450-
(sym::unsafe_destructor_blind_to_params,
1451-
Normal,
1452-
template!(Word),
1453-
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761",
1454-
Some("replace this attribute with `#[may_dangle]`")),
1455-
sym::dropck_parametricity,
1456-
"unsafe_destructor_blind_to_params has been replaced by \
1457-
may_dangle and will be removed in the future",
1458-
cfg_fn!(dropck_parametricity))),
14591449
(sym::may_dangle,
14601450
Normal,
14611451
template!(Word),

src/libsyntax_pos/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ symbols! {
695695
unmarked_api,
696696
unreachable_code,
697697
unrestricted_attribute_tokens,
698-
unsafe_destructor_blind_to_params,
699698
unsafe_no_drop_flag,
700699
unsized_locals,
701700
unsized_tuple_coercion,

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-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 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,11 +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,
26-
// because destructor never accesses `self.1`.
23+
// Use of `may_dangle` is sound, because destructor never accesses `self.1`.
2724
println!("Dropping Foo({}, _)", self.0);
2825
}
2926
}

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

+4-7
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,12 +23,10 @@ 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,
31-
// because destructor never passes a `self.1` to the callback
32-
// (in `self.2`) despite having it available.
28+
// Use of `may_dangle` is sound, because destructor never passes a `self.1`
29+
// to the callback (in `self.2`) despite having it available.
3330
println!("Dropping Foo({}, _)", self.0);
3431
}
3532
}

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

+5-8
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,14 +18,12 @@ 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,
28-
// because destructor never accesses the `Debug::fmt` method
29-
// of `T`, despite having it available.
25+
// Use of `may_dangle` is sound, because destructor never accesses
26+
// the `Debug::fmt` method of `T`, despite having it available.
3027
println!("Dropping Foo({}, _)", self.0);
3128
}
3229
}

src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.rs

-12
This file was deleted.

src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.stderr

-14
This file was deleted.

src/test/ui/feature-gates/feature-gate-dropck-ugeh.rs

-29
This file was deleted.

src/test/ui/feature-gates/feature-gate-dropck-ugeh.stderr

-20
This file was deleted.

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ 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,
20-
// because destructor accesses borrowed data in `self.1`
21-
// and we must force that to strictly outlive `self`.
19+
// Use of `may_dangle` is unsound, because destructor accesses borrowed data
20+
// in `self.1` and we must force that to strictly outlive `self`.
2221
println!("Dropping Foo({}, {:?})", self.0, self.1);
2322
}
2423
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0597]: `first_dropped` does not live long enough
2-
--> $DIR/issue28498-reject-lifetime-param.rs:33:19
2+
--> $DIR/issue28498-reject-lifetime-param.rs:32:19
33
|
44
LL | foo1 = Foo(1, &first_dropped);
55
| ^^^^^^^^^^^^^^ borrowed value does not live long enough

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +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,
20-
// because we pass `T` to the callback in `self.2`
19+
// Use of `may_dangle` is unsound, because we pass `T` to the callback in `self.2`
2120
// below, and thus potentially read from borrowed data.
2221
println!("Dropping Foo({}, {})", self.0, (self.2)(&self.1));
2322
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0597]: `first_dropped` does not live long enough
2-
--> $DIR/issue28498-reject-passed-to-fn.rs:35:19
2+
--> $DIR/issue28498-reject-passed-to-fn.rs:34:19
33
|
44
LL | foo1 = Foo(1, &first_dropped, Box::new(callback));
55
| ^^^^^^^^^^^^^^ borrowed value does not live long enough

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ 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,
22-
// because we access `T` fmt method when we pass `self.1`
23-
// below, and thus potentially read from borrowed data.
21+
// Use of `may_dangle` is unsound, because we access `T` fmt method when we pass
22+
// `self.1` below, and thus potentially read from borrowed data.
2423
println!("Dropping Foo({}, {:?})", self.0, self.1);
2524
}
2625
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0597]: `first_dropped` does not live long enough
2-
--> $DIR/issue28498-reject-trait-bound.rs:35:19
2+
--> $DIR/issue28498-reject-trait-bound.rs:34:19
33
|
44
LL | foo1 = Foo(1, &first_dropped);
55
| ^^^^^^^^^^^^^^ borrowed value does not live long enough

0 commit comments

Comments
 (0)