diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index a3b99f143d055..56cb89b5144ac 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -22,7 +22,6 @@ use rustc_macros::HashStable; use std::{cmp, fmt}; use syntax::ast; use syntax::attr::{self, SignedInt, UnsignedInt}; -use syntax::symbol::sym; use syntax_pos::{Span, DUMMY_SP}; #[derive(Copy, Clone, Debug)] @@ -435,20 +434,6 @@ impl<'tcx> TyCtxt<'tcx> { Some(dtor) => dtor.did }; - // RFC 1238: if the destructor method is tagged with the - // attribute `unsafe_destructor_blind_to_params`, then the - // compiler is being instructed to *assume* that the - // destructor will not access borrowed data, - // even if such data is otherwise reachable. - // - // Such access can be in plain sight (e.g., dereferencing - // `*foo.0` of `Foo<'a>(&'a u32)`) or indirectly hidden - // (e.g., calling `foo.0.clone()` of `Foo`). - if self.has_attr(dtor, sym::unsafe_destructor_blind_to_params) { - debug!("destructor_constraint({:?}) - blind", def.did); - return vec![]; - } - let impl_def_id = self.associated_item(dtor).container.id(); let impl_generics = self.generics_of(impl_def_id); diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index c4c4e10a14cc0..babffe479bc2e 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -246,7 +246,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( /// /// * (1.) `D` has a lifetime- or type-parametric Drop implementation, /// (where that `Drop` implementation does not opt-out of -/// this check via the `unsafe_destructor_blind_to_params` +/// this check via the `may_dangle` /// attribute), and /// * (2.) the structure of `D` can reach a reference of type `&'a _`, /// @@ -279,7 +279,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( /// instead Drop-Check now simply assumes that if a destructor has /// access (direct or indirect) to a lifetime parameter, then that /// lifetime must be forced to outlive that destructor's dynamic -/// extent. We then provide the `unsafe_destructor_blind_to_params` +/// extent. We then provide the `may_dangle` /// attribute as a way for destructor implementations to opt-out of /// this conservative assumption (and thus assume the obligation of /// ensuring that they do not access data nor invoke methods of diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 5c6847b414136..3cd520fd4b50b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -3809,7 +3809,6 @@ const ATTRIBUTE_WHITELIST: &'static [Symbol] = &[ sym::must_use, sym::no_mangle, sym::repr, - sym::unsafe_destructor_blind_to_params, sym::non_exhaustive ]; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 84a012f03c9d3..e3628d908fb1e 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -199,9 +199,6 @@ declare_features! ( // no-tracking-issue-end - // Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238). - (active, dropck_parametricity, "1.3.0", Some(28498), None), - // no-tracking-issue-start // Allows using `#[omit_gdb_pretty_printer_section]`. @@ -641,6 +638,8 @@ declare_features! ( (removed, extern_in_paths, "1.33.0", Some(55600), None, Some("subsumed by `::foo::bar` paths")), (removed, quote, "1.33.0", Some(29601), None, None), + // Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238). + (removed, dropck_parametricity, "1.38.0", Some(28498), None, None), // ------------------------------------------------------------------------- // feature-group-end: removed features @@ -1447,15 +1446,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ cfg_fn!(omit_gdb_pretty_printer_section) ) ), - (sym::unsafe_destructor_blind_to_params, - Normal, - template!(Word), - Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761", - Some("replace this attribute with `#[may_dangle]`")), - sym::dropck_parametricity, - "unsafe_destructor_blind_to_params has been replaced by \ - may_dangle and will be removed in the future", - cfg_fn!(dropck_parametricity))), (sym::may_dangle, Normal, template!(Word), diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 581fd47c4b3b5..a983180ac01e1 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -695,7 +695,6 @@ symbols! { unmarked_api, unreachable_code, unrestricted_attribute_tokens, - unsafe_destructor_blind_to_params, unsafe_no_drop_flag, unsized_locals, unsized_tuple_coercion, diff --git a/src/test/run-pass/issues/issue-24805-dropck-itemless.rs b/src/test/run-pass/issues/issue-24805-dropck-itemless.rs index db427ed3d3194..555eefeb3a1f8 100644 --- a/src/test/run-pass/issues/issue-24805-dropck-itemless.rs +++ b/src/test/run-pass/issues/issue-24805-dropck-itemless.rs @@ -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); - impl Drop for $Id { - #[unsafe_destructor_blind_to_params] + struct $Id(T); + unsafe impl <#[may_dangle] T: $Bound> Drop for $Id { fn drop(&mut self) { } } } diff --git a/src/test/run-pass/issues/issue-28498-ugeh-ex1.rs b/src/test/run-pass/issues/issue-28498-ugeh-ex1.rs index c4f249c45f13c..90cf2cddcf02a 100644 --- a/src/test/run-pass/issues/issue-28498-ugeh-ex1.rs +++ b/src/test/run-pass/issues/issue-28498-ugeh-ex1.rs @@ -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>>); struct Foo { data: Vec } -impl Drop for Foo { - // Below is the UGEH attribute - #[unsafe_destructor_blind_to_params] +// Below is the UGEH attribute +unsafe impl<#[may_dangle] T> Drop for Foo { fn drop(&mut self) { } } diff --git a/src/test/run-pass/issues/issue-28498-ugeh-with-lifetime-param.rs b/src/test/run-pass/issues/issue-28498-ugeh-with-lifetime-param.rs index 573ec8f6131f7..aea9fde5309e2 100644 --- a/src/test/run-pass/issues/issue-28498-ugeh-with-lifetime-param.rs +++ b/src/test/run-pass/issues/issue-28498-ugeh-with-lifetime-param.rs @@ -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,11 +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, - // because destructor never accesses `self.1`. + // Use of `may_dangle` is sound, because destructor never accesses `self.1`. println!("Dropping Foo({}, _)", self.0); } } diff --git a/src/test/run-pass/issues/issue-28498-ugeh-with-passed-to-fn.rs b/src/test/run-pass/issues/issue-28498-ugeh-with-passed-to-fn.rs index e0863fa9947ed..91ef5a7c98d6d 100644 --- a/src/test/run-pass/issues/issue-28498-ugeh-with-passed-to-fn.rs +++ b/src/test/run-pass/issues/issue-28498-ugeh-with-passed-to-fn.rs @@ -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,12 +23,10 @@ impl Drop for ScribbleOnDrop { struct Foo(u32, T, Box fn(&'r T) -> String>); -impl Drop for Foo { - #[unsafe_destructor_blind_to_params] +unsafe impl<#[may_dangle] T> Drop for Foo { fn drop(&mut self) { - // Use of `unsafe_destructor_blind_to_params` is sound, - // because destructor never passes a `self.1` to the callback - // (in `self.2`) despite having it available. + // 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); } } diff --git a/src/test/run-pass/issues/issue-28498-ugeh-with-trait-bound.rs b/src/test/run-pass/issues/issue-28498-ugeh-with-trait-bound.rs index 01d884584f640..808f3b6e81e52 100644 --- a/src/test/run-pass/issues/issue-28498-ugeh-with-trait-bound.rs +++ b/src/test/run-pass/issues/issue-28498-ugeh-with-trait-bound.rs @@ -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,14 +18,12 @@ impl Drop for ScribbleOnDrop { } } -struct Foo(u32, T); +struct Foo(u32, T); -impl Drop for Foo { - #[unsafe_destructor_blind_to_params] +unsafe impl<#[may_dangle] T: fmt::Debug> Drop for Foo { fn drop(&mut self) { - // Use of `unsafe_destructor_blind_to_params` is sound, - // because destructor never accesses the `Debug::fmt` method - // of `T`, despite having it available. + // 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); } } diff --git a/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.rs b/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.rs deleted file mode 100644 index 33252019e71e6..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![deny(deprecated)] -#![feature(dropck_parametricity)] - -struct Foo; - -impl Drop for Foo { - #[unsafe_destructor_blind_to_params] - //~^ ERROR use of deprecated attribute `dropck_parametricity` - fn drop(&mut self) {} -} - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.stderr b/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.stderr deleted file mode 100644 index b6a474575c677..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-dropck-ugeh-2.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: use of deprecated attribute `dropck_parametricity`: unsafe_destructor_blind_to_params has been replaced by may_dangle and will be removed in the future. See https://github.com/rust-lang/rust/issues/34761 - --> $DIR/feature-gate-dropck-ugeh-2.rs:7:5 - | -LL | #[unsafe_destructor_blind_to_params] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[may_dangle]` - | -note: lint level defined here - --> $DIR/feature-gate-dropck-ugeh-2.rs:1:9 - | -LL | #![deny(deprecated)] - | ^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/feature-gates/feature-gate-dropck-ugeh.rs b/src/test/ui/feature-gates/feature-gate-dropck-ugeh.rs deleted file mode 100644 index a2377cda9bd66..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-dropck-ugeh.rs +++ /dev/null @@ -1,29 +0,0 @@ -// gate-test-dropck_parametricity - -// Ensure that attempts to use the unsafe attribute are feature-gated. -// Example adapted from RFC 1238 text (just left out the feature gate). - -// https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md -// #example-of-the-unguarded-escape-hatch - -use std::cell::Cell; - -struct Concrete<'a>(u32, Cell>>); - -struct Foo { data: Vec } - -impl Drop for Foo { - #[unsafe_destructor_blind_to_params] // This is the UGEH attribute - //~^ ERROR unsafe_destructor_blind_to_params has been replaced - //~| WARN use of deprecated attribute `dropck_parametricity` - fn drop(&mut self) { } -} - -fn main() { - let mut foo = Foo { data: Vec::new() }; - foo.data.push(Concrete(0, Cell::new(None))); - foo.data.push(Concrete(0, Cell::new(None))); - - foo.data[0].1.set(Some(&foo.data[1])); - foo.data[1].1.set(Some(&foo.data[0])); -} diff --git a/src/test/ui/feature-gates/feature-gate-dropck-ugeh.stderr b/src/test/ui/feature-gates/feature-gate-dropck-ugeh.stderr deleted file mode 100644 index 581b760ba4f47..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-dropck-ugeh.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0658]: unsafe_destructor_blind_to_params has been replaced by may_dangle and will be removed in the future - --> $DIR/feature-gate-dropck-ugeh.rs:16:5 - | -LL | #[unsafe_destructor_blind_to_params] // This is the UGEH attribute - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/28498 - = help: add `#![feature(dropck_parametricity)]` to the crate attributes to enable - -warning: use of deprecated attribute `dropck_parametricity`: unsafe_destructor_blind_to_params has been replaced by may_dangle and will be removed in the future. See https://github.com/rust-lang/rust/issues/34761 - --> $DIR/feature-gate-dropck-ugeh.rs:16:5 - | -LL | #[unsafe_destructor_blind_to_params] // This is the UGEH attribute - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[may_dangle]` - | - = note: #[warn(deprecated)] on by default - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/span/issue28498-reject-lifetime-param.rs b/src/test/ui/span/issue28498-reject-lifetime-param.rs index 9bc01766be564..1e7190157856c 100644 --- a/src/test/ui/span/issue28498-reject-lifetime-param.rs +++ b/src/test/ui/span/issue28498-reject-lifetime-param.rs @@ -16,9 +16,8 @@ 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, - // because destructor accesses borrowed data in `self.1` - // and we must force that to strictly outlive `self`. + // 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); } } diff --git a/src/test/ui/span/issue28498-reject-lifetime-param.stderr b/src/test/ui/span/issue28498-reject-lifetime-param.stderr index 1dcb40e5d9cb7..3119ddd03cc26 100644 --- a/src/test/ui/span/issue28498-reject-lifetime-param.stderr +++ b/src/test/ui/span/issue28498-reject-lifetime-param.stderr @@ -1,5 +1,5 @@ error[E0597]: `first_dropped` does not live long enough - --> $DIR/issue28498-reject-lifetime-param.rs:33:19 + --> $DIR/issue28498-reject-lifetime-param.rs:32:19 | LL | foo1 = Foo(1, &first_dropped); | ^^^^^^^^^^^^^^ borrowed value does not live long enough diff --git a/src/test/ui/span/issue28498-reject-passed-to-fn.rs b/src/test/ui/span/issue28498-reject-passed-to-fn.rs index c59de5df41170..dcd2e9ad4ba98 100644 --- a/src/test/ui/span/issue28498-reject-passed-to-fn.rs +++ b/src/test/ui/span/issue28498-reject-passed-to-fn.rs @@ -16,8 +16,7 @@ struct Foo(u32, T, Box fn(&'r T) -> String>); impl Drop for Foo { fn drop(&mut self) { - // Use of `unsafe_destructor_blind_to_params` is unsound, - // because we pass `T` to the callback in `self.2` + // 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)); } diff --git a/src/test/ui/span/issue28498-reject-passed-to-fn.stderr b/src/test/ui/span/issue28498-reject-passed-to-fn.stderr index 214a6f6d65ca5..60e8a648cd597 100644 --- a/src/test/ui/span/issue28498-reject-passed-to-fn.stderr +++ b/src/test/ui/span/issue28498-reject-passed-to-fn.stderr @@ -1,5 +1,5 @@ error[E0597]: `first_dropped` does not live long enough - --> $DIR/issue28498-reject-passed-to-fn.rs:35:19 + --> $DIR/issue28498-reject-passed-to-fn.rs:34:19 | LL | foo1 = Foo(1, &first_dropped, Box::new(callback)); | ^^^^^^^^^^^^^^ borrowed value does not live long enough diff --git a/src/test/ui/span/issue28498-reject-trait-bound.rs b/src/test/ui/span/issue28498-reject-trait-bound.rs index 8813180c8919f..444cebb19a73d 100644 --- a/src/test/ui/span/issue28498-reject-trait-bound.rs +++ b/src/test/ui/span/issue28498-reject-trait-bound.rs @@ -14,13 +14,12 @@ impl Drop for ScribbleOnDrop { } } -struct Foo(u32, T); +struct Foo(u32, T); -impl Drop for Foo { +impl Drop for Foo { fn drop(&mut self) { - // Use of `unsafe_destructor_blind_to_params` is unsound, - // because we access `T` fmt method when we pass `self.1` - // below, and thus potentially read from borrowed data. + // 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); } } diff --git a/src/test/ui/span/issue28498-reject-trait-bound.stderr b/src/test/ui/span/issue28498-reject-trait-bound.stderr index d4fe291bef398..22e4a8205b617 100644 --- a/src/test/ui/span/issue28498-reject-trait-bound.stderr +++ b/src/test/ui/span/issue28498-reject-trait-bound.stderr @@ -1,5 +1,5 @@ error[E0597]: `first_dropped` does not live long enough - --> $DIR/issue28498-reject-trait-bound.rs:35:19 + --> $DIR/issue28498-reject-trait-bound.rs:34:19 | LL | foo1 = Foo(1, &first_dropped); | ^^^^^^^^^^^^^^ borrowed value does not live long enough