]> git.lizzy.rs Git - rust.git/commitdiff
Port of pcwalton removal of `#[unsafe_destructor]` check.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Mon, 27 Oct 2014 11:57:14 +0000 (12:57 +0100)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Sat, 28 Mar 2015 23:19:19 +0000 (00:19 +0100)
Earlier commits impose rules on lifetimes that make generic
destructors safe; thus we no longer need the `#[unsafe_destructor]`
attribute nor its associated check.

----

So remove the check for the unsafe_destructor attribute.

And remove outdated compile-fail tests from when lifetime-parameteric
dtors were disallowed/unsafe.

In addition, when one uses the attribute without the associated
feature, report that the attribute is deprecated.

However, I do not think this is a breaking-change, because the
attribute and feature are still currently accepted by the compiler.
(After the next snapshot that has this commit, we can remove the
feature itself and the attribute as well.)

----

I consider this to:

Fix #22196

(techincally there is still the post snapshot work of removing the
last remants of the feature and the attribute, but the ticket can
still be closed in my opinion).

src/librustc_typeck/check/wf.rs
src/libsyntax/feature_gate.rs
src/test/compile-fail/gated-unsafe-destructor.rs
src/test/compile-fail/issue-13853-3.rs [deleted file]
src/test/compile-fail/issue-13853-4.rs [deleted file]
src/test/compile-fail/issue-16465.rs [deleted file]
src/test/compile-fail/kindck-destructor-owned.rs [deleted file]
src/test/compile-fail/unsafe-destructor-check-crash.rs [deleted file]

index 16da3237c815c6993fc6bf2f29a8f0d36727784f..23e31df5395268971b0c821f8ffd96a08da76d0d 100644 (file)
@@ -23,7 +23,6 @@
 use std::collections::HashSet;
 use syntax::ast;
 use syntax::ast_util::local_def;
-use syntax::attr;
 use syntax::codemap::Span;
 use syntax::parse::token::{self, special_idents};
 use syntax::visit;
@@ -250,22 +249,6 @@ fn check_impl(&mut self,
                                                         &fcx.inh.param_env.free_substs,
                                                         &trait_ref);
 
-            // There are special rules that apply to drop.
-            if
-                fcx.tcx().lang_items.drop_trait() == Some(trait_ref.def_id) &&
-                !attr::contains_name(&item.attrs, "unsafe_destructor")
-            {
-                match self_ty.sty {
-                    ty::ty_struct(def_id, _) |
-                    ty::ty_enum(def_id, _) => {
-                        check_struct_safe_for_destructor(fcx, item.span, def_id);
-                    }
-                    _ => {
-                        // Coherence already reports an error in this case.
-                    }
-                }
-            }
-
             if fcx.tcx().lang_items.copy_trait() == Some(trait_ref.def_id) {
                 // This is checked in coherence.
                 return
@@ -761,22 +744,3 @@ fn filter_to_trait_obligations<'tcx>(bounds: ty::InstantiatedPredicates<'tcx>)
     }
     result
 }
-
-///////////////////////////////////////////////////////////////////////////
-// Special drop trait checking
-
-fn check_struct_safe_for_destructor<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
-                                              span: Span,
-                                              struct_did: ast::DefId) {
-    let struct_tpt = ty::lookup_item_type(fcx.tcx(), struct_did);
-    if struct_tpt.generics.has_type_params(subst::TypeSpace)
-        || struct_tpt.generics.has_region_params(subst::TypeSpace)
-    {
-        span_err!(fcx.tcx().sess, span, E0141,
-                  "cannot implement a destructor on a structure \
-                   with type parameters");
-        span_note!(fcx.tcx().sess, span,
-                   "use \"#[unsafe_destructor]\" on the implementation \
-                    to force the compiler to allow this");
-    }
-}
index c6e6e749860c06d381fcaae6463e452cf681d259..1b03a18072011a2c1f5acf0bbcf306369af6fe28 100644 (file)
@@ -58,7 +58,6 @@
     ("log_syntax", "1.0.0", Active),
     ("trace_macros", "1.0.0", Active),
     ("concat_idents", "1.0.0", Active),
-    ("unsafe_destructor", "1.0.0", Active),
     ("intrinsics", "1.0.0", Active),
     ("lang_items", "1.0.0", Active),
 
     ("start", "1.0.0", Active),
     ("main", "1.0.0", Active),
 
+    // Deprecate after snapshot
+    // SNAP a923278
+    ("unsafe_destructor", "1.0.0", Active),
+
     // A temporary feature gate used to enable parser extensions needed
     // to bootstrap fix for #5723.
     ("issue_5723_bootstrap", "1.0.0", Accepted),
@@ -193,7 +196,6 @@ enum Status {
     ("repr", Normal),
     ("path", Normal),
     ("abi", Normal),
-    ("unsafe_destructor", Normal),
     ("automatically_derived", Normal),
     ("no_mangle", Normal),
     ("no_link", Normal),
@@ -205,7 +207,8 @@ enum Status {
     ("link_args", Normal),
     ("macro_escape", Normal),
 
-
+    ("unsafe_destructor", Gated("unsafe_destructor",
+                                "`#[unsafe_destructor]` does nothing anymore")),
     ("staged_api", Gated("staged_api",
                          "staged_api is for use by rustc only")),
     ("plugin", Gated("plugin",
@@ -571,15 +574,6 @@ fn visit_item(&mut self, i: &ast::Item) {
                     _ => {}
                 }
 
-                if attr::contains_name(&i.attrs,
-                                       "unsafe_destructor") {
-                    self.gate_feature("unsafe_destructor",
-                                      i.span,
-                                      "`#[unsafe_destructor]` allows too \
-                                       many unsafe patterns and may be \
-                                       removed in the future");
-                }
-
                 if attr::contains_name(&i.attrs[..],
                                        "old_orphan_check") {
                     self.gate_feature(
index 6024fef9fb81f043256f4f189995349a6943e8b4..2aebbf3d54b9cd08d6151d071685887cde875098 100644 (file)
 
 // Test that `#[unsafe_destructor]` attribute is gated by `unsafe_destructor`
 // feature gate.
+//
+// (This test can be removed entirely when we remove the
+// `unsafe_destructor` feature itself.)
 
 struct D<'a>(&'a u32);
 
 #[unsafe_destructor]
+//~^ ERROR `#[unsafe_destructor]` does nothing anymore
+//~| HELP: add #![feature(unsafe_destructor)] to the crate attributes to enable
+// (but of couse there is no point in doing so)
 impl<'a> Drop for D<'a> {
-    //~^ ERROR `#[unsafe_destructor]` allows too many unsafe patterns
     fn drop(&mut self) { }
 }
-//~^ HELP: add #![feature(unsafe_destructor)] to the crate attributes to enable
 
 pub fn main() { }
diff --git a/src/test/compile-fail/issue-13853-3.rs b/src/test/compile-fail/issue-13853-3.rs
deleted file mode 100644 (file)
index 7ca158c..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_type = "lib"]
-
-use std::marker::PhantomData;
-
-enum NodeContents<'a> {
-    Children(Vec<Node<'a>>),
-}
-
-impl<'a> Drop for NodeContents<'a> {
-    //~^ ERROR cannot implement a destructor on a structure with type parameters
-    fn drop( &mut self ) {
-    }
-}
-
-struct Node<'a> {
-    contents: NodeContents<'a>,
-    marker: PhantomData<&'a ()>,
-}
-
-impl<'a> Node<'a> {
-    fn noName(contents: NodeContents<'a>) -> Node<'a> {
-        Node { contents: contents, marker: PhantomData }
-    }
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/issue-13853-4.rs b/src/test/compile-fail/issue-13853-4.rs
deleted file mode 100644 (file)
index b0db9e5..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-struct AutoBuilder<'a> {
-    context: &'a isize
-}
-
-impl<'a> Drop for AutoBuilder<'a> {
-    //~^ ERROR cannot implement a destructor on a structure with type parameters
-    fn drop(&mut self) {
-    }
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/issue-16465.rs b/src/test/compile-fail/issue-16465.rs
deleted file mode 100644 (file)
index 825b40c..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Used to cause an ICE
-
-struct Foo<T>{
-    x : T
-}
-
-type FooInt = Foo<isize>;
-
-impl Drop for FooInt {
-//~^ ERROR cannot implement a destructor on a structure with type parameters
-    fn drop(&mut self){}
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/kindck-destructor-owned.rs b/src/test/compile-fail/kindck-destructor-owned.rs
deleted file mode 100644 (file)
index 7f37041..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-struct Bar<'a> {
-    f: &'a isize,
-}
-
-impl<'a> Drop for Bar<'a> {
-//~^ ERROR E0141
-    fn drop(&mut self) {
-    }
-}
-
-struct Baz {
-    f: &'static isize,
-}
-
-impl Drop for Baz {
-    fn drop(&mut self) {
-    }
-}
-
-fn main() { }
diff --git a/src/test/compile-fail/unsafe-destructor-check-crash.rs b/src/test/compile-fail/unsafe-destructor-check-crash.rs
deleted file mode 100644 (file)
index af67558..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-
-// Regression test for issue #15557
-
-#![allow(dead_code)]
-struct AReg1<'a>(&'a u32);
-
-impl<'a> Drop for AReg1<'a> {
-//~^ ERROR: cannot implement a destructor on a structure with type parameters
-  fn drop(&mut self) {}
-}
-
-fn main() {}