Skip to content

Port of pcwalton removal of #[unsafe_destructor] check. #23819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions src/librustc_typeck/check/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use util::ppaux::{Repr, UserString};
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;
Expand Down Expand Up @@ -250,22 +249,6 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
&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
Expand Down Expand Up @@ -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");
}
}
18 changes: 6 additions & 12 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
("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),

Expand Down Expand Up @@ -92,6 +91,10 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
("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),
Expand Down Expand Up @@ -193,7 +196,6 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
("repr", Normal),
("path", Normal),
("abi", Normal),
("unsafe_destructor", Normal),
("automatically_derived", Normal),
("no_mangle", Normal),
("no_link", Normal),
Expand All @@ -205,7 +207,8 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
("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",
Expand Down Expand Up @@ -571,15 +574,6 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
_ => {}
}

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(
Expand Down
8 changes: 6 additions & 2 deletions src/test/compile-fail/gated-unsafe-destructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@

// 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() { }
36 changes: 0 additions & 36 deletions src/test/compile-fail/issue-13853-3.rs

This file was deleted.

21 changes: 0 additions & 21 deletions src/test/compile-fail/issue-13853-4.rs

This file was deleted.

24 changes: 0 additions & 24 deletions src/test/compile-fail/issue-16465.rs

This file was deleted.

31 changes: 0 additions & 31 deletions src/test/compile-fail/kindck-destructor-owned.rs

This file was deleted.

23 changes: 0 additions & 23 deletions src/test/compile-fail/unsafe-destructor-check-crash.rs

This file was deleted.