Skip to content

Commit 64c48f3

Browse files
committed
Port of pcwalton removal of #[unsafe_destructor] check.
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 rust-lang#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).
1 parent 01f2c67 commit 64c48f3

8 files changed

+12
-185
lines changed

src/librustc_typeck/check/wf.rs

-36
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use util::ppaux::{Repr, UserString};
2323
use std::collections::HashSet;
2424
use syntax::ast;
2525
use syntax::ast_util::local_def;
26-
use syntax::attr;
2726
use syntax::codemap::Span;
2827
use syntax::parse::token::{self, special_idents};
2928
use syntax::visit;
@@ -250,22 +249,6 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
250249
&fcx.inh.param_env.free_substs,
251250
&trait_ref);
252251

253-
// There are special rules that apply to drop.
254-
if
255-
fcx.tcx().lang_items.drop_trait() == Some(trait_ref.def_id) &&
256-
!attr::contains_name(&item.attrs, "unsafe_destructor")
257-
{
258-
match self_ty.sty {
259-
ty::ty_struct(def_id, _) |
260-
ty::ty_enum(def_id, _) => {
261-
check_struct_safe_for_destructor(fcx, item.span, def_id);
262-
}
263-
_ => {
264-
// Coherence already reports an error in this case.
265-
}
266-
}
267-
}
268-
269252
if fcx.tcx().lang_items.copy_trait() == Some(trait_ref.def_id) {
270253
// This is checked in coherence.
271254
return
@@ -761,22 +744,3 @@ fn filter_to_trait_obligations<'tcx>(bounds: ty::InstantiatedPredicates<'tcx>)
761744
}
762745
result
763746
}
764-
765-
///////////////////////////////////////////////////////////////////////////
766-
// Special drop trait checking
767-
768-
fn check_struct_safe_for_destructor<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
769-
span: Span,
770-
struct_did: ast::DefId) {
771-
let struct_tpt = ty::lookup_item_type(fcx.tcx(), struct_did);
772-
if struct_tpt.generics.has_type_params(subst::TypeSpace)
773-
|| struct_tpt.generics.has_region_params(subst::TypeSpace)
774-
{
775-
span_err!(fcx.tcx().sess, span, E0141,
776-
"cannot implement a destructor on a structure \
777-
with type parameters");
778-
span_note!(fcx.tcx().sess, span,
779-
"use \"#[unsafe_destructor]\" on the implementation \
780-
to force the compiler to allow this");
781-
}
782-
}

src/libsyntax/feature_gate.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
5858
("log_syntax", "1.0.0", Active),
5959
("trace_macros", "1.0.0", Active),
6060
("concat_idents", "1.0.0", Active),
61-
("unsafe_destructor", "1.0.0", Active),
6261
("intrinsics", "1.0.0", Active),
6362
("lang_items", "1.0.0", Active),
6463

@@ -92,6 +91,10 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
9291
("start", "1.0.0", Active),
9392
("main", "1.0.0", Active),
9493

94+
// Deprecate after snapshot
95+
// SNAP a923278
96+
("unsafe_destructor", "1.0.0", Active),
97+
9598
// A temporary feature gate used to enable parser extensions needed
9699
// to bootstrap fix for #5723.
97100
("issue_5723_bootstrap", "1.0.0", Accepted),
@@ -193,7 +196,6 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
193196
("repr", Normal),
194197
("path", Normal),
195198
("abi", Normal),
196-
("unsafe_destructor", Normal),
197199
("automatically_derived", Normal),
198200
("no_mangle", Normal),
199201
("no_link", Normal),
@@ -205,7 +207,8 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
205207
("link_args", Normal),
206208
("macro_escape", Normal),
207209

208-
210+
("unsafe_destructor", Gated("unsafe_destructor",
211+
"`#[unsafe_destructor]` does nothing anymore")),
209212
("staged_api", Gated("staged_api",
210213
"staged_api is for use by rustc only")),
211214
("plugin", Gated("plugin",
@@ -571,15 +574,6 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
571574
_ => {}
572575
}
573576

574-
if attr::contains_name(&i.attrs,
575-
"unsafe_destructor") {
576-
self.gate_feature("unsafe_destructor",
577-
i.span,
578-
"`#[unsafe_destructor]` allows too \
579-
many unsafe patterns and may be \
580-
removed in the future");
581-
}
582-
583577
if attr::contains_name(&i.attrs[..],
584578
"old_orphan_check") {
585579
self.gate_feature(

src/test/compile-fail/gated-unsafe-destructor.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010

1111
// Test that `#[unsafe_destructor]` attribute is gated by `unsafe_destructor`
1212
// feature gate.
13+
//
14+
// (This test can be removed entirely when we remove the
15+
// `unsafe_destructor` feature itself.)
1316

1417
struct D<'a>(&'a u32);
1518

1619
#[unsafe_destructor]
20+
//~^ ERROR `#[unsafe_destructor]` does nothing anymore
21+
//~| HELP: add #![feature(unsafe_destructor)] to the crate attributes to enable
22+
// (but of couse there is no point in doing so)
1723
impl<'a> Drop for D<'a> {
18-
//~^ ERROR `#[unsafe_destructor]` allows too many unsafe patterns
1924
fn drop(&mut self) { }
2025
}
21-
//~^ HELP: add #![feature(unsafe_destructor)] to the crate attributes to enable
2226

2327
pub fn main() { }

src/test/compile-fail/issue-13853-3.rs

-36
This file was deleted.

src/test/compile-fail/issue-13853-4.rs

-21
This file was deleted.

src/test/compile-fail/issue-16465.rs

-24
This file was deleted.

src/test/compile-fail/kindck-destructor-owned.rs

-31
This file was deleted.

src/test/compile-fail/unsafe-destructor-check-crash.rs

-23
This file was deleted.

0 commit comments

Comments
 (0)