Skip to content

Commit 8b8a706

Browse files
committed
---
yaml --- r: 134973 b: refs/heads/snap-stage3 c: 7119974 h: refs/heads/master i: 134971: f077038 v: v3
1 parent 129f6e6 commit 8b8a706

File tree

7 files changed

+79
-84
lines changed

7 files changed

+79
-84
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 7eb9337dace88c5ded431aa7507f06d50619131b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c31623b0e42e73ef2c9411445d3172e2e9c9e467
4+
refs/heads/snap-stage3: 7119974f82cb239307ed9ea2e885eb66c0edba95
55
refs/heads/try: 14378ea357c06c23607ca61ade44f60a7a64a1c7
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/diagnostics.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ register_diagnostics!(
130130
E0121,
131131
E0122,
132132
E0124,
133-
E0125,
134133
E0126,
135134
E0127,
136135
E0128,

branches/snap-stage3/src/librustc/middle/kind.rs

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
// except according to those terms.
1010

1111
use middle::mem_categorization::Typer;
12-
use middle::subst;
1312
use middle::ty;
14-
use middle::ty_fold::TypeFoldable;
15-
use middle::ty_fold;
1613
use util::ppaux::{ty_to_string};
1714
use util::ppaux::UserString;
1815

1916
use syntax::ast::*;
20-
use syntax::attr;
2117
use syntax::codemap::Span;
2218
use syntax::print::pprust::{expr_to_string, ident_to_string};
2319
use syntax::visit::Visitor;
@@ -48,10 +44,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
4844
check_ty(self, t);
4945
}
5046

51-
fn visit_item(&mut self, i: &Item) {
52-
check_item(self, i);
53-
}
54-
5547
fn visit_pat(&mut self, p: &Pat) {
5648
check_pat(self, p);
5749
}
@@ -65,79 +57,6 @@ pub fn check_crate(tcx: &ty::ctxt) {
6557
tcx.sess.abort_if_errors();
6658
}
6759

68-
struct EmptySubstsFolder<'a, 'tcx: 'a> {
69-
tcx: &'a ty::ctxt<'tcx>
70-
}
71-
impl<'a, 'tcx> ty_fold::TypeFolder<'tcx> for EmptySubstsFolder<'a, 'tcx> {
72-
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> {
73-
self.tcx
74-
}
75-
fn fold_substs(&mut self, _: &subst::Substs) -> subst::Substs {
76-
subst::Substs::empty()
77-
}
78-
}
79-
80-
fn check_struct_safe_for_destructor(cx: &mut Context,
81-
span: Span,
82-
struct_did: DefId) {
83-
let struct_tpt = ty::lookup_item_type(cx.tcx, struct_did);
84-
if !struct_tpt.generics.has_type_params(subst::TypeSpace)
85-
&& !struct_tpt.generics.has_region_params(subst::TypeSpace) {
86-
let mut folder = EmptySubstsFolder { tcx: cx.tcx };
87-
if !ty::type_is_sendable(cx.tcx, struct_tpt.ty.fold_with(&mut folder)) {
88-
span_err!(cx.tcx.sess, span, E0125,
89-
"cannot implement a destructor on a \
90-
structure or enumeration that does not satisfy Send");
91-
span_note!(cx.tcx.sess, span,
92-
"use \"#[unsafe_destructor]\" on the implementation \
93-
to force the compiler to allow this");
94-
}
95-
} else {
96-
span_err!(cx.tcx.sess, span, E0141,
97-
"cannot implement a destructor on a structure \
98-
with type parameters");
99-
span_note!(cx.tcx.sess, span,
100-
"use \"#[unsafe_destructor]\" on the implementation \
101-
to force the compiler to allow this");
102-
}
103-
}
104-
105-
fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_type: &Ty) {
106-
let ast_trait_def = *cx.tcx.def_map.borrow()
107-
.find(&trait_ref.ref_id)
108-
.expect("trait ref not in def map!");
109-
let trait_def_id = ast_trait_def.def_id();
110-
111-
// If this is a destructor, check kinds.
112-
if cx.tcx.lang_items.drop_trait() == Some(trait_def_id) &&
113-
!attr::contains_name(it.attrs.as_slice(), "unsafe_destructor")
114-
{
115-
match self_type.node {
116-
TyPath(_, ref bounds, path_node_id) => {
117-
assert!(bounds.is_none());
118-
let struct_def = cx.tcx.def_map.borrow().get_copy(&path_node_id);
119-
let struct_did = struct_def.def_id();
120-
check_struct_safe_for_destructor(cx, self_type.span, struct_did);
121-
}
122-
_ => {
123-
cx.tcx.sess.span_bug(self_type.span,
124-
"the self type for the Drop trait impl is not a path");
125-
}
126-
}
127-
}
128-
}
129-
130-
fn check_item(cx: &mut Context, item: &Item) {
131-
match item.node {
132-
ItemImpl(_, Some(ref trait_ref), ref self_type, _) => {
133-
check_impl_of_trait(cx, item, trait_ref, &**self_type);
134-
}
135-
_ => {}
136-
}
137-
138-
visit::walk_item(cx, item)
139-
}
140-
14160
// Yields the appropriate function to check the kind of closed over
14261
// variables. `id` is the NodeId for some expression that creates the
14362
// closure.

branches/snap-stage3/src/librustc/middle/traits/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ pub enum ObligationCauseCode {
6969
/// Obligation incurred due to an object cast.
7070
ObjectCastObligation(/* Object type */ ty::t),
7171

72+
/// To implement drop, type must be sendable.
73+
DropTrait,
74+
7275
/// Various cases where expressions must be sized/copy/etc:
7376
AssignmentLhsSized, // L = X implies that L is Sized
7477
StructInitializerSized, // S { ... } must be Sized

branches/snap-stage3/src/librustc/middle/typeck/check/vtable2.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,5 +390,13 @@ fn note_obligation_cause(fcx: &FnCtxt,
390390
obligation.cause.span,
391391
"structs must have a statically known size to be initialized");
392392
}
393+
traits::DropTrait => {
394+
span_note!(tcx.sess, obligation.cause.span,
395+
"cannot implement a destructor on a \
396+
structure or enumeration that does not satisfy Send");
397+
span_note!(tcx.sess, obligation.cause.span,
398+
"use \"#[unsafe_destructor]\" on the implementation \
399+
to force the compiler to allow this");
400+
}
393401
}
394402
}

branches/snap-stage3/src/librustc/middle/typeck/check/wf.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use middle::subst;
1112
use middle::subst::{Subst};
1213
use middle::traits;
1314
use middle::ty;
@@ -21,6 +22,7 @@ use util::ppaux::Repr;
2122
use std::collections::HashSet;
2223
use syntax::ast;
2324
use syntax::ast_util::{local_def};
25+
use syntax::attr;
2426
use syntax::codemap::Span;
2527
use syntax::visit;
2628
use syntax::visit::Visitor;
@@ -165,6 +167,22 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
165167
};
166168
let trait_ref = (*trait_ref).subst(fcx.tcx(), &fcx.inh.param_env.free_substs);
167169

170+
// There are special rules that apply to drop.
171+
if
172+
fcx.tcx().lang_items.drop_trait() == Some(trait_ref.def_id) &&
173+
!attr::contains_name(item.attrs.as_slice(), "unsafe_destructor")
174+
{
175+
match ty::get(self_ty).sty {
176+
ty::ty_struct(def_id, _) |
177+
ty::ty_enum(def_id, _) => {
178+
check_struct_safe_for_destructor(fcx, item.span, self_ty, def_id);
179+
}
180+
_ => {
181+
// Coherence already reports an error in this case.
182+
}
183+
}
184+
}
185+
168186
// We are stricter on the trait-ref in an impl than the
169187
// self-type. In particular, we enforce region
170188
// relationships. The reason for this is that (at least
@@ -362,3 +380,31 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
362380
t // we're not folding to produce a new type, so just return `t` here
363381
}
364382
}
383+
384+
///////////////////////////////////////////////////////////////////////////
385+
// Special drop trait checking
386+
387+
fn check_struct_safe_for_destructor(fcx: &FnCtxt,
388+
span: Span,
389+
self_ty: ty::t,
390+
struct_did: ast::DefId) {
391+
let struct_tpt = ty::lookup_item_type(fcx.tcx(), struct_did);
392+
if !struct_tpt.generics.has_type_params(subst::TypeSpace)
393+
&& !struct_tpt.generics.has_region_params(subst::TypeSpace)
394+
{
395+
let cause = traits::ObligationCause::new(span, traits::DropTrait);
396+
fcx.register_obligation(
397+
traits::obligation_for_builtin_bound(
398+
fcx.tcx(),
399+
cause,
400+
self_ty,
401+
ty::BoundSend));
402+
} else {
403+
span_err!(fcx.tcx().sess, span, E0141,
404+
"cannot implement a destructor on a structure \
405+
with type parameters");
406+
span_note!(fcx.tcx().sess, span,
407+
"use \"#[unsafe_destructor]\" on the implementation \
408+
to force the compiler to allow this");
409+
}
410+
}

branches/snap-stage3/src/test/compile-fail/kindck-destructor-owned.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,27 @@ struct Foo {
1616
}
1717

1818
impl Drop for Foo {
19-
//~^ ERROR cannot implement a destructor on a structure or enumeration that does not satisfy Send
19+
//~^ ERROR the trait `core::kinds::Send` is not implemented for the type `Foo`
20+
//~^^ NOTE cannot implement a destructor on a structure or enumeration that does not satisfy Send
21+
fn drop(&mut self) {
22+
}
23+
}
24+
25+
struct Bar<'a> {
26+
f: &'a int,
27+
}
28+
29+
impl<'a> Drop for Bar<'a> {
30+
//~^ ERROR E0141
31+
fn drop(&mut self) {
32+
}
33+
}
34+
35+
struct Baz {
36+
f: &'static int,
37+
}
38+
39+
impl Drop for Baz {
2040
fn drop(&mut self) {
2141
}
2242
}

0 commit comments

Comments
 (0)