Skip to content

Commit 55fbc47

Browse files
committed
auto merge of #6148 : erickt/rust/remove-drop, r=pcwalton
The drop block has been deprecated for quite some time. This patch series removes support for parsing it and all the related machinery that made drop work. As a side feature of all this, I also added the ability to annote fields in structs. This allows comments to be properly associated with an individual field. However, I didn't update `rustdoc` to integrate these comment blocks into the documentation it generates.
2 parents f67239f + 7c9d089 commit 55fbc47

37 files changed

+148
-731
lines changed

src/compiletest/header.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,13 @@ pub fn load_props(testfile: &Path) -> TestProps {
8282
}
8383

8484
pub fn is_test_ignored(config: config, testfile: &Path) -> bool {
85-
let mut found = false;
8685
for iter_header(testfile) |ln| {
8786
if parse_name_directive(ln, ~"xfail-test") { return true; }
8887
if parse_name_directive(ln, xfail_target()) { return true; }
8988
if config.mode == common::mode_pretty &&
9089
parse_name_directive(ln, ~"xfail-pretty") { return true; }
9190
};
92-
return found;
91+
return true;
9392

9493
fn xfail_target() -> ~str {
9594
~"xfail-" + str::from_slice(os::SYSNAME)

src/compiletest/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn run_rpass_test(config: config, props: TestProps, testfile: &Path) {
106106
fatal_ProcRes(~"test run failed!", ProcRes);
107107
}
108108
} else {
109-
let mut ProcRes = jit_test(config, props, testfile);
109+
let ProcRes = jit_test(config, props, testfile);
110110
111111
if ProcRes.status != 0 { fatal_ProcRes(~"jit failed!", ProcRes); }
112112
}

src/libcore/core.rc

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ they contained the following prologue:
6363
#[warn(vecs_implicitly_copyable)];
6464
#[deny(non_camel_case_types)];
6565
#[allow(deprecated_mutable_fields)];
66-
#[allow(deprecated_drop)];
6766

6867
// Make core testable by not duplicating lang items. See #2912
6968
#[cfg(test)] extern mod realcore(name = "core", vers = "0.7-pre");

src/libcore/pipes.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ use cast::{forget, transmute, transmute_copy};
8686
use either::{Either, Left, Right};
8787
use kinds::Owned;
8888
use libc;
89+
use ops::Drop;
8990
use option::{None, Option, Some};
91+
use unstable::finally::Finally;
9092
use unstable::intrinsics;
9193
use ptr;
9294
use task;
@@ -395,26 +397,22 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
395397
let p_ = p.unwrap();
396398
let p = unsafe { &*p_ };
397399
398-
#[unsafe_destructor]
399-
struct DropState<'self> {
400-
p: &'self PacketHeader,
401-
402-
drop {
403-
unsafe {
404-
if task::failing() {
405-
self.p.state = Terminated;
406-
let old_task = swap_task(&mut self.p.blocked_task,
407-
ptr::null());
408-
if !old_task.is_null() {
409-
rustrt::rust_task_deref(old_task);
410-
}
400+
do (|| {
401+
try_recv_(p)
402+
}).finally {
403+
unsafe {
404+
if task::failing() {
405+
p.header.state = Terminated;
406+
let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
407+
if !old_task.is_null() {
408+
rustrt::rust_task_deref(old_task);
411409
}
412410
}
413411
}
414-
};
415-
416-
let _drop_state = DropState { p: &p.header };
412+
}
413+
}
417414
415+
fn try_recv_<T:Owned>(p: &Packet<T>) -> Option<T> {
418416
// optimistic path
419417
match p.header.state {
420418
Full => {
@@ -451,7 +449,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
451449
Blocked);
452450
match old_state {
453451
Empty => {
454-
debug!("no data available on %?, going to sleep.", p_);
452+
debug!("no data available on %?, going to sleep.", p);
455453
if count == 0 {
456454
wait_event(this);
457455
}

src/librustc/metadata/common.rs

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ pub static tag_mod_impl_trait: uint = 0x47u;
100100
different tags.
101101
*/
102102
pub static tag_item_impl_method: uint = 0x48u;
103-
pub static tag_item_dtor: uint = 0x49u;
104103
pub static tag_item_trait_method_self_ty: uint = 0x4b;
105104
pub static tag_item_trait_method_self_ty_region: uint = 0x4c;
106105

src/librustc/metadata/csearch.rs

-7
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,6 @@ pub fn get_impl_method(cstore: @mut cstore::CStore,
230230
decoder::get_impl_method(cstore.intr, cdata, def.node, mname)
231231
}
232232

233-
/* If def names a class with a dtor, return it. Otherwise, return none. */
234-
pub fn struct_dtor(cstore: @mut cstore::CStore, def: ast::def_id)
235-
-> Option<ast::def_id> {
236-
let cdata = cstore::get_crate_data(cstore, def.crate);
237-
decoder::struct_dtor(cdata, def.node)
238-
}
239-
240233
pub fn get_item_visibility(cstore: @mut cstore::CStore,
241234
def_id: ast::def_id)
242235
-> ast::visibility {

src/librustc/metadata/decoder.rs

-16
Original file line numberDiff line numberDiff line change
@@ -445,22 +445,6 @@ pub fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
445445
found.get()
446446
}
447447
448-
pub fn struct_dtor(cdata: cmd, id: ast::node_id) -> Option<ast::def_id> {
449-
let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
450-
let mut found = None;
451-
let cls_items = match maybe_find_item(id, items) {
452-
Some(it) => it,
453-
None => fail!(fmt!("struct_dtor: class id not found \
454-
when looking up dtor for %d", id))
455-
};
456-
for reader::tagged_docs(cls_items, tag_item_dtor) |doc| {
457-
let doc1 = reader::get_doc(doc, tag_def_id);
458-
let did = reader::with_doc_data(doc1, |d| parse_def_id(d));
459-
found = Some(translate_def_id(cdata, did));
460-
};
461-
found
462-
}
463-
464448
pub fn get_symbol(data: @~[u8], id: ast::node_id) -> ~str {
465449
return item_symbol(lookup_item(id, data));
466450
}

src/librustc/metadata/encoder.rs

-27
Original file line numberDiff line numberDiff line change
@@ -765,26 +765,6 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: &writer::Encoder,
765765
class itself */
766766
let idx = encode_info_for_struct(ecx, ebml_w, path,
767767
struct_def.fields, index);
768-
/* Encode the dtor */
769-
for struct_def.dtor.each |dtor| {
770-
index.push(entry {val: dtor.node.id, pos: ebml_w.writer.tell()});
771-
encode_info_for_ctor(ecx,
772-
ebml_w,
773-
dtor.node.id,
774-
ecx.tcx.sess.ident_of(
775-
*ecx.tcx.sess.str_of(item.ident) +
776-
~"_dtor"),
777-
path,
778-
if generics.ty_params.len() > 0u {
779-
Some(ii_dtor(copy *dtor,
780-
item.ident,
781-
copy *generics,
782-
local_def(item.id))) }
783-
else {
784-
None
785-
},
786-
generics);
787-
}
788768
789769
/* Index the class*/
790770
add_to_index();
@@ -816,13 +796,6 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: &writer::Encoder,
816796
encode_name(ecx, ebml_w, item.ident);
817797
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
818798
encode_region_param(ecx, ebml_w, item);
819-
/* Encode the dtor */
820-
/* Encode id for dtor */
821-
for struct_def.dtor.each |dtor| {
822-
do ebml_w.wr_tag(tag_item_dtor) {
823-
encode_def_id(ebml_w, local_def(dtor.node.id));
824-
}
825-
};
826799
827800
/* Encode def_ids for each field and method
828801
for methods, write all the stuff get_trait_method

src/librustc/middle/astencode.rs

-26
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,6 @@ fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
327327
ast::ii_foreign(i) => {
328328
ast::ii_foreign(fld.fold_foreign_item(i))
329329
}
330-
ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => {
331-
let dtor_body = fld.fold_block(&dtor.node.body);
332-
ast::ii_dtor(
333-
codemap::spanned {
334-
node: ast::struct_dtor_ { body: dtor_body,
335-
.. /*bad*/copy (*dtor).node },
336-
.. (/*bad*/copy *dtor) },
337-
nm, /*bad*/copy *tps, parent_id)
338-
}
339330
}
340331
}
341332
@@ -363,23 +354,6 @@ fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item)
363354
ast::ii_foreign(i) => {
364355
ast::ii_foreign(fld.fold_foreign_item(i))
365356
}
366-
ast::ii_dtor(ref dtor, nm, ref generics, parent_id) => {
367-
let dtor_body = fld.fold_block(&dtor.node.body);
368-
let dtor_attrs = fld.fold_attributes(/*bad*/copy (*dtor).node.attrs);
369-
let new_generics = fold::fold_generics(generics, fld);
370-
let dtor_id = fld.new_id((*dtor).node.id);
371-
let new_parent = xcx.tr_def_id(parent_id);
372-
let new_self = fld.new_id((*dtor).node.self_id);
373-
ast::ii_dtor(
374-
codemap::spanned {
375-
node: ast::struct_dtor_ { id: dtor_id,
376-
attrs: dtor_attrs,
377-
self_id: new_self,
378-
body: dtor_body },
379-
.. (/*bad*/copy *dtor)
380-
},
381-
nm, new_generics, new_parent)
382-
}
383357
}
384358
}
385359

src/librustc/middle/borrowck/check_loans.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,7 @@ fn check_loans_in_fn(fk: &visit::fn_kind,
629629
630630
let declared_purity, src;
631631
match *fk {
632-
visit::fk_item_fn(*) | visit::fk_method(*) |
633-
visit::fk_dtor(*) => {
632+
visit::fk_item_fn(*) | visit::fk_method(*) => {
634633
declared_purity = ty::ty_fn_purity(fty);
635634
src = id;
636635
}
@@ -658,8 +657,7 @@ fn check_loans_in_fn(fk: &visit::fn_kind,
658657
// inherits the fn_args from enclosing ctxt
659658
}
660659
visit::fk_anon(*) | visit::fk_fn_block(*) |
661-
visit::fk_method(*) | visit::fk_item_fn(*) |
662-
visit::fk_dtor(*) => {
660+
visit::fk_method(*) | visit::fk_item_fn(*) => {
663661
let mut fn_args = ~[];
664662
for decl.inputs.each |input| {
665663
// For the purposes of purity, only consider function-

src/librustc/middle/borrowck/gather_loans.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ fn req_loans_in_fn(fk: &visit::fn_kind,
104104

105105
match *fk {
106106
visit::fk_anon(*) | visit::fk_fn_block(*) => {}
107-
visit::fk_item_fn(*) | visit::fk_method(*) |
108-
visit::fk_dtor(*) => {
107+
visit::fk_item_fn(*) | visit::fk_method(*) => {
109108
self.item_ub = body.node.id;
110109
}
111110
}

src/librustc/middle/kind.rs

-11
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,6 @@ fn check_item(item: @item, cx: Context, visitor: visit::vt<Context>) {
153153
}
154154
}
155155
}
156-
item_struct(struct_def, _) => {
157-
match struct_def.dtor {
158-
None => {}
159-
Some(ref dtor) => {
160-
let struct_did = def_id { crate: 0, node: item.id };
161-
check_struct_safe_for_destructor(cx,
162-
dtor.span,
163-
struct_did);
164-
}
165-
}
166-
}
167156
_ => {}
168157
}
169158
}

src/librustc/middle/lint.rs

-29
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub enum lint {
5757
type_limits,
5858
default_methods,
5959
deprecated_mutable_fields,
60-
deprecated_drop,
6160
unused_unsafe,
6261

6362
managed_heap_memory,
@@ -210,13 +209,6 @@ pub fn get_lint_dict() -> LintDict {
210209
default: deny
211210
}),
212211

213-
(~"deprecated_drop",
214-
LintSpec {
215-
lint: deprecated_drop,
216-
desc: "deprecated \"drop\" notation for the destructor",
217-
default: deny
218-
}),
219-
220212
(~"unused_unsafe",
221213
LintSpec {
222214
lint: unused_unsafe,
@@ -463,7 +455,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
463455
check_item_type_limits(cx, i);
464456
check_item_default_methods(cx, i);
465457
check_item_deprecated_mutable_fields(cx, i);
466-
check_item_deprecated_drop(cx, i);
467458
check_item_unused_unsafe(cx, i);
468459
check_item_unused_mut(cx, i);
469460
}
@@ -668,26 +659,6 @@ fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
668659
}
669660
}
670661

671-
fn check_item_deprecated_drop(cx: ty::ctxt, item: @ast::item) {
672-
match item.node {
673-
ast::item_struct(struct_def, _) => {
674-
match struct_def.dtor {
675-
None => {}
676-
Some(ref dtor) => {
677-
cx.sess.span_lint(deprecated_drop,
678-
item.id,
679-
item.id,
680-
dtor.span,
681-
~"`drop` notation for destructors is \
682-
deprecated; implement the `Drop` \
683-
trait instead");
684-
}
685-
}
686-
}
687-
_ => {}
688-
}
689-
}
690-
691662
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
692663

693664
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,

src/librustc/middle/liveness.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ use syntax::ast::*;
117117
use syntax::codemap::span;
118118
use syntax::parse::token::special_idents;
119119
use syntax::print::pprust::{expr_to_str, block_to_str};
120-
use syntax::visit::{fk_anon, fk_dtor, fk_fn_block, fk_item_fn, fk_method};
120+
use syntax::visit::{fk_anon, fk_fn_block, fk_item_fn, fk_method};
121121
use syntax::visit::{vt};
122122
use syntax::{visit, ast_util};
123123

@@ -440,9 +440,6 @@ fn visit_fn(fk: &visit::fn_kind,
440440
sty_static => {}
441441
}
442442
}
443-
fk_dtor(_, _, self_id, _) => {
444-
fn_maps.add_variable(Arg(self_id, special_idents::self_));
445-
}
446443
fk_item_fn(*) | fk_anon(*) | fk_fn_block(*) => {}
447444
}
448445

src/librustc/middle/region.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,7 @@ pub fn resolve_fn(fk: &visit::fn_kind,
438438
cx: ctxt,
439439
visitor: visit::vt<ctxt>) {
440440
let fn_cx = match *fk {
441-
visit::fk_item_fn(*) | visit::fk_method(*) |
442-
visit::fk_dtor(*) => {
441+
visit::fk_item_fn(*) | visit::fk_method(*) => {
443442
// Top-level functions are a root scope.
444443
ctxt {parent: Some(id),.. cx}
445444
}

src/librustc/middle/resolve.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident};
4747
use syntax::ast::{Path, pat_lit, pat_range, pat_struct};
4848
use syntax::ast::{prim_ty, private, provided};
4949
use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl};
50-
use syntax::ast::{struct_dtor, struct_field, struct_variant_kind};
50+
use syntax::ast::{struct_field, struct_variant_kind};
5151
use syntax::ast::{sty_static, subtract, trait_ref, tuple_variant_kind, Ty};
5252
use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i};
5353
use syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, TyParam, ty_path};
@@ -3512,7 +3512,6 @@ pub impl Resolver {
35123512
self.resolve_struct(item.id,
35133513
generics,
35143514
struct_def.fields,
3515-
&struct_def.dtor,
35163515
visitor);
35173516
}
35183517

@@ -3770,7 +3769,6 @@ pub impl Resolver {
37703769
id: node_id,
37713770
generics: &Generics,
37723771
fields: &[@struct_field],
3773-
optional_destructor: &Option<struct_dtor>,
37743772
visitor: ResolveVisitor) {
37753773
// If applicable, create a rib for the type parameters.
37763774
do self.with_type_parameter_rib(HasTypeParameters
@@ -3784,23 +3782,6 @@ pub impl Resolver {
37843782
for fields.each |field| {
37853783
self.resolve_type(field.node.ty, visitor);
37863784
}
3787-
3788-
// Resolve the destructor, if applicable.
3789-
match *optional_destructor {
3790-
None => {
3791-
// Nothing to do.
3792-
}
3793-
Some(ref destructor) => {
3794-
self.resolve_function(NormalRibKind,
3795-
None,
3796-
NoTypeParameters,
3797-
&destructor.node.body,
3798-
HasSelfBinding
3799-
((*destructor).node.self_id,
3800-
true),
3801-
visitor);
3802-
}
3803-
}
38043785
}
38053786
}
38063787

0 commit comments

Comments
 (0)