From 5d79f94a2f74a0502f665c5eb432aa7231666392 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 30 Apr 2013 18:03:09 -0700 Subject: [PATCH 1/8] core: Remove use of deprecated `drop` --- src/libcore/core.rc | 1 - src/libcore/pipes.rs | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libcore/core.rc b/src/libcore/core.rc index f9a56f613d542..7ccf5cb6a9125 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -63,7 +63,6 @@ they contained the following prologue: #[warn(vecs_implicitly_copyable)]; #[deny(non_camel_case_types)]; #[allow(deprecated_mutable_fields)]; -#[allow(deprecated_drop)]; // Make core testable by not duplicating lang items. See #2912 #[cfg(test)] extern mod realcore(name = "core", vers = "0.7-pre"); diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 95b24d20a4bc2..82dc598c750eb 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -86,6 +86,7 @@ use cast::{forget, transmute, transmute_copy}; use either::{Either, Left, Right}; use kinds::Owned; use libc; +use ops::Drop; use option::{None, Option, Some}; use unstable::intrinsics; use ptr; @@ -395,11 +396,13 @@ pub fn try_recv(p: RecvPacketBuffered) let p_ = p.unwrap(); let p = unsafe { &*p_ }; - #[unsafe_destructor] struct DropState<'self> { p: &'self PacketHeader, + } - drop { + #[unsafe_destructor] + impl<'self> Drop for DropState<'self> { + fn finalize(&self) { unsafe { if task::failing() { self.p.state = Terminated; @@ -411,7 +414,7 @@ pub fn try_recv(p: RecvPacketBuffered) } } } - }; + } let _drop_state = DropState { p: &p.header }; From 7d6d0029ba0392bc0e8f2e7211f58a77cf85a231 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 30 Apr 2013 21:00:30 -0700 Subject: [PATCH 2/8] syntax: remove parsing destructors --- src/libsyntax/parse/parser.rs | 92 ++++++----------------------------- 1 file changed, 14 insertions(+), 78 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 50bdfb2f55726..1a4a15b3bf522 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -102,11 +102,6 @@ enum restriction { RESTRICT_NO_BAR_OR_DOUBLEBAR_OP, } -// So that we can distinguish a class dtor from other class members - -enum class_contents { dtor_decl(blk, ~[attribute], codemap::span), - members(~[@struct_field]) } - type arg_or_capture_item = Either; type item_info = (ident, item_, Option<~[attribute]>); @@ -3299,7 +3294,6 @@ pub impl Parser { } let mut fields: ~[@struct_field]; - let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None; let is_tuple_like; if self.eat(&token::LBRACE) { @@ -3307,26 +3301,8 @@ pub impl Parser { is_tuple_like = false; fields = ~[]; while *self.token != token::RBRACE { - match self.parse_struct_decl_field() { - dtor_decl(ref blk, ref attrs, s) => { - match the_dtor { - Some((_, _, s_first)) => { - self.span_note(s, fmt!("Duplicate destructor \ - declaration for class %s", - *self.interner.get(class_name))); - self.span_fatal(copy s_first, ~"First destructor \ - declared here"); - } - None => { - the_dtor = Some((copy *blk, copy *attrs, s)); - } - } - } - members(mms) => { - for mms.each |struct_field| { - fields.push(*struct_field) - } - } + for self.parse_struct_decl_field().each |struct_field| { + fields.push(*struct_field) } } if fields.len() == 0 { @@ -3365,19 +3341,12 @@ pub impl Parser { ); } - let actual_dtor = do the_dtor.map |dtor| { - let (d_body, d_attrs, d_s) = copy *dtor; - codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(), - attrs: d_attrs, - self_id: self.get_id(), - body: d_body}, - span: d_s}}; let _ = self.get_id(); // XXX: Workaround for crazy bug. let new_id = self.get_id(); (class_name, item_struct(@ast::struct_def { fields: fields, - dtor: actual_dtor, + dtor: None, ctor_id: if is_tuple_like { Some(new_id) } else { None } }, generics), None) @@ -3420,34 +3389,28 @@ pub impl Parser { } // parse an element of a struct definition - fn parse_struct_decl_field(&self) -> class_contents { + fn parse_struct_decl_field(&self) -> ~[@struct_field] { if self.try_parse_obsolete_priv_section() { - return members(~[]); + return ~[]; } - let attrs = self.parse_outer_attributes(); + // Need this to parse comments on fields. + let _attrs = self.parse_outer_attributes(); if self.eat_keyword(&~"priv") { - return members(~[self.parse_single_struct_field(private)]) + return ~[self.parse_single_struct_field(private)] } if self.eat_keyword(&~"pub") { - return members(~[self.parse_single_struct_field(public)]); + return ~[self.parse_single_struct_field(public)]; } if self.try_parse_obsolete_struct_ctor() { - return members(~[]); + return ~[]; } - if self.eat_keyword(&~"drop") { - let lo = self.last_span.lo; - let body = self.parse_block(); - return dtor_decl(body, attrs, mk_sp(lo, self.last_span.hi)) - } - else { - return members(~[self.parse_single_struct_field(inherited)]); - } + return ~[self.parse_single_struct_field(inherited)]; } // parse visiility: PUB, PRIV, or nothing @@ -3830,44 +3793,17 @@ pub impl Parser { // parse a structure-like enum variant definition // this should probably be renamed or refactored... fn parse_struct_def(&self) -> @struct_def { - let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None; let mut fields: ~[@struct_field] = ~[]; while *self.token != token::RBRACE { - match self.parse_struct_decl_field() { - dtor_decl(ref blk, ref attrs, s) => { - match the_dtor { - Some((_, _, s_first)) => { - self.span_note(s, ~"duplicate destructor \ - declaration"); - self.span_fatal(copy s_first, - ~"first destructor \ - declared here"); - } - None => { - the_dtor = Some((copy *blk, copy *attrs, s)); - } - } - } - members(mms) => { - for mms.each |struct_field| { - fields.push(*struct_field); - } - } + for self.parse_struct_decl_field().each |struct_field| { + fields.push(*struct_field); } } self.bump(); - let actual_dtor = do the_dtor.map |dtor| { - let (d_body, d_attrs, d_s) = copy *dtor; - codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(), - attrs: d_attrs, - self_id: self.get_id(), - body: d_body }, - span: d_s } - }; return @ast::struct_def { fields: fields, - dtor: actual_dtor, + dtor: None, ctor_id: None }; } From c2e1f47955571fab24fc731c0af97e4c71f4ada9 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 30 Apr 2013 21:00:45 -0700 Subject: [PATCH 3/8] rustc: remove the rest of drop Removes: ast::struct_def::dtor syntax::ast::ii_dtor syntax::visit::fk_dtor syntax::ast_map::node_dtor syntax:struct_dtor --- src/librustc/metadata/common.rs | 1 - src/librustc/metadata/csearch.rs | 7 -- src/librustc/metadata/decoder.rs | 16 --- src/librustc/metadata/encoder.rs | 27 ---- src/librustc/middle/astencode.rs | 26 ---- src/librustc/middle/borrowck/check_loans.rs | 6 +- src/librustc/middle/borrowck/gather_loans.rs | 3 +- src/librustc/middle/kind.rs | 11 -- src/librustc/middle/lint.rs | 29 ----- src/librustc/middle/liveness.rs | 5 +- src/librustc/middle/region.rs | 3 +- src/librustc/middle/resolve.rs | 21 +--- src/librustc/middle/trans/base.rs | 124 +------------------ src/librustc/middle/trans/debuginfo.rs | 3 - src/librustc/middle/trans/inline.rs | 4 - src/librustc/middle/trans/monomorphize.rs | 15 +-- src/librustc/middle/trans/reachable.rs | 13 +- src/librustc/middle/trans/type_use.rs | 3 - src/librustc/middle/ty.rs | 27 +--- src/librustc/middle/typeck/check/mod.rs | 29 +---- src/librustc/middle/typeck/collect.rs | 25 ---- src/librustdoc/tystr_pass.rs | 8 +- src/libsyntax/ast.rs | 18 +-- src/libsyntax/ast_map.rs | 29 +---- src/libsyntax/ast_util.rs | 26 ---- src/libsyntax/ext/pipes/pipec.rs | 1 - src/libsyntax/fold.rs | 26 ---- src/libsyntax/parse/parser.rs | 2 - src/libsyntax/print/pprust.rs | 7 -- src/libsyntax/visit.rs | 44 +------ 30 files changed, 21 insertions(+), 538 deletions(-) diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index 8e689f3147b6b..111c201d5023c 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -100,7 +100,6 @@ pub static tag_mod_impl_trait: uint = 0x47u; different tags. */ pub static tag_item_impl_method: uint = 0x48u; -pub static tag_item_dtor: uint = 0x49u; pub static tag_item_trait_method_self_ty: uint = 0x4b; pub static tag_item_trait_method_self_ty_region: uint = 0x4c; diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 5626714260b87..f8dc34f9cee3a 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -230,13 +230,6 @@ pub fn get_impl_method(cstore: @mut cstore::CStore, decoder::get_impl_method(cstore.intr, cdata, def.node, mname) } -/* If def names a class with a dtor, return it. Otherwise, return none. */ -pub fn struct_dtor(cstore: @mut cstore::CStore, def: ast::def_id) - -> Option { - let cdata = cstore::get_crate_data(cstore, def.crate); - decoder::struct_dtor(cdata, def.node) -} - pub fn get_item_visibility(cstore: @mut cstore::CStore, def_id: ast::def_id) -> ast::visibility { diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index cfe31360d321b..fb7b3f9c8b129 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -445,22 +445,6 @@ pub fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id, found.get() } -pub fn struct_dtor(cdata: cmd, id: ast::node_id) -> Option { - let items = reader::get_doc(reader::Doc(cdata.data), tag_items); - let mut found = None; - let cls_items = match maybe_find_item(id, items) { - Some(it) => it, - None => fail!(fmt!("struct_dtor: class id not found \ - when looking up dtor for %d", id)) - }; - for reader::tagged_docs(cls_items, tag_item_dtor) |doc| { - let doc1 = reader::get_doc(doc, tag_def_id); - let did = reader::with_doc_data(doc1, |d| parse_def_id(d)); - found = Some(translate_def_id(cdata, did)); - }; - found -} - pub fn get_symbol(data: @~[u8], id: ast::node_id) -> ~str { return item_symbol(lookup_item(id, data)); } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index dd4ef0d2e688f..ba6a4f30857eb 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -765,26 +765,6 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: &writer::Encoder, class itself */ let idx = encode_info_for_struct(ecx, ebml_w, path, struct_def.fields, index); - /* Encode the dtor */ - for struct_def.dtor.each |dtor| { - index.push(entry {val: dtor.node.id, pos: ebml_w.writer.tell()}); - encode_info_for_ctor(ecx, - ebml_w, - dtor.node.id, - ecx.tcx.sess.ident_of( - *ecx.tcx.sess.str_of(item.ident) + - ~"_dtor"), - path, - if generics.ty_params.len() > 0u { - Some(ii_dtor(copy *dtor, - item.ident, - copy *generics, - local_def(item.id))) } - else { - None - }, - generics); - } /* Index the class*/ add_to_index(); @@ -816,13 +796,6 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: &writer::Encoder, encode_name(ecx, ebml_w, item.ident); encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); encode_region_param(ecx, ebml_w, item); - /* Encode the dtor */ - /* Encode id for dtor */ - for struct_def.dtor.each |dtor| { - do ebml_w.wr_tag(tag_item_dtor) { - encode_def_id(ebml_w, local_def(dtor.node.id)); - } - }; /* Encode def_ids for each field and method for methods, write all the stuff get_trait_method diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index c7c9c110586c7..2f753523a7bc0 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -327,15 +327,6 @@ fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item { ast::ii_foreign(i) => { ast::ii_foreign(fld.fold_foreign_item(i)) } - ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => { - let dtor_body = fld.fold_block(&dtor.node.body); - ast::ii_dtor( - codemap::spanned { - node: ast::struct_dtor_ { body: dtor_body, - .. /*bad*/copy (*dtor).node }, - .. (/*bad*/copy *dtor) }, - nm, /*bad*/copy *tps, parent_id) - } } } @@ -363,23 +354,6 @@ fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item) ast::ii_foreign(i) => { ast::ii_foreign(fld.fold_foreign_item(i)) } - ast::ii_dtor(ref dtor, nm, ref generics, parent_id) => { - let dtor_body = fld.fold_block(&dtor.node.body); - let dtor_attrs = fld.fold_attributes(/*bad*/copy (*dtor).node.attrs); - let new_generics = fold::fold_generics(generics, fld); - let dtor_id = fld.new_id((*dtor).node.id); - let new_parent = xcx.tr_def_id(parent_id); - let new_self = fld.new_id((*dtor).node.self_id); - ast::ii_dtor( - codemap::spanned { - node: ast::struct_dtor_ { id: dtor_id, - attrs: dtor_attrs, - self_id: new_self, - body: dtor_body }, - .. (/*bad*/copy *dtor) - }, - nm, new_generics, new_parent) - } } } diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 07b6c80d4201c..526a5a3a9dd4c 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -629,8 +629,7 @@ fn check_loans_in_fn(fk: &visit::fn_kind, let declared_purity, src; match *fk { - visit::fk_item_fn(*) | visit::fk_method(*) | - visit::fk_dtor(*) => { + visit::fk_item_fn(*) | visit::fk_method(*) => { declared_purity = ty::ty_fn_purity(fty); src = id; } @@ -658,8 +657,7 @@ fn check_loans_in_fn(fk: &visit::fn_kind, // inherits the fn_args from enclosing ctxt } visit::fk_anon(*) | visit::fk_fn_block(*) | - visit::fk_method(*) | visit::fk_item_fn(*) | - visit::fk_dtor(*) => { + visit::fk_method(*) | visit::fk_item_fn(*) => { let mut fn_args = ~[]; for decl.inputs.each |input| { // For the purposes of purity, only consider function- diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index e40d0e63eb38e..da04853411865 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -104,8 +104,7 @@ fn req_loans_in_fn(fk: &visit::fn_kind, match *fk { visit::fk_anon(*) | visit::fk_fn_block(*) => {} - visit::fk_item_fn(*) | visit::fk_method(*) | - visit::fk_dtor(*) => { + visit::fk_item_fn(*) | visit::fk_method(*) => { self.item_ub = body.node.id; } } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index cf488b0ac8939..0925e8cdd6375 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -153,17 +153,6 @@ fn check_item(item: @item, cx: Context, visitor: visit::vt) { } } } - item_struct(struct_def, _) => { - match struct_def.dtor { - None => {} - Some(ref dtor) => { - let struct_did = def_id { crate: 0, node: item.id }; - check_struct_safe_for_destructor(cx, - dtor.span, - struct_did); - } - } - } _ => {} } } diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index faf4b1c31061b..b67d74bc272b6 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -57,7 +57,6 @@ pub enum lint { type_limits, default_methods, deprecated_mutable_fields, - deprecated_drop, unused_unsafe, managed_heap_memory, @@ -210,13 +209,6 @@ pub fn get_lint_dict() -> LintDict { default: deny }), - (~"deprecated_drop", - LintSpec { - lint: deprecated_drop, - desc: "deprecated \"drop\" notation for the destructor", - default: deny - }), - (~"unused_unsafe", LintSpec { lint: unused_unsafe, @@ -463,7 +455,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) { check_item_type_limits(cx, i); check_item_default_methods(cx, i); check_item_deprecated_mutable_fields(cx, i); - check_item_deprecated_drop(cx, i); check_item_unused_unsafe(cx, i); check_item_unused_mut(cx, i); } @@ -668,26 +659,6 @@ fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) { } } -fn check_item_deprecated_drop(cx: ty::ctxt, item: @ast::item) { - match item.node { - ast::item_struct(struct_def, _) => { - match struct_def.dtor { - None => {} - Some(ref dtor) => { - cx.sess.span_lint(deprecated_drop, - item.id, - item.id, - dtor.span, - ~"`drop` notation for destructors is \ - deprecated; implement the `Drop` \ - trait instead"); - } - } - } - _ => {} - } -} - fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id, diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 94d82d0acb8e4..0df10c59a8aac 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -117,7 +117,7 @@ use syntax::ast::*; use syntax::codemap::span; use syntax::parse::token::special_idents; use syntax::print::pprust::{expr_to_str, block_to_str}; -use syntax::visit::{fk_anon, fk_dtor, fk_fn_block, fk_item_fn, fk_method}; +use syntax::visit::{fk_anon, fk_fn_block, fk_item_fn, fk_method}; use syntax::visit::{vt}; use syntax::{visit, ast_util}; @@ -440,9 +440,6 @@ fn visit_fn(fk: &visit::fn_kind, sty_static => {} } } - fk_dtor(_, _, self_id, _) => { - fn_maps.add_variable(Arg(self_id, special_idents::self_)); - } fk_item_fn(*) | fk_anon(*) | fk_fn_block(*) => {} } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index f32998281711f..88e201fb5f438 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -438,8 +438,7 @@ pub fn resolve_fn(fk: &visit::fn_kind, cx: ctxt, visitor: visit::vt) { let fn_cx = match *fk { - visit::fk_item_fn(*) | visit::fk_method(*) | - visit::fk_dtor(*) => { + visit::fk_item_fn(*) | visit::fk_method(*) => { // Top-level functions are a root scope. ctxt {parent: Some(id),.. cx} } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 294a21fac2c23..1d2ca59b8aa31 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -47,7 +47,7 @@ use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident}; use syntax::ast::{Path, pat_lit, pat_range, pat_struct}; use syntax::ast::{prim_ty, private, provided}; use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl}; -use syntax::ast::{struct_dtor, struct_field, struct_variant_kind}; +use syntax::ast::{struct_field, struct_variant_kind}; use syntax::ast::{sty_static, subtract, trait_ref, tuple_variant_kind, Ty}; use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i}; use syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, TyParam, ty_path}; @@ -3512,7 +3512,6 @@ pub impl Resolver { self.resolve_struct(item.id, generics, struct_def.fields, - &struct_def.dtor, visitor); } @@ -3770,7 +3769,6 @@ pub impl Resolver { id: node_id, generics: &Generics, fields: &[@struct_field], - optional_destructor: &Option, visitor: ResolveVisitor) { // If applicable, create a rib for the type parameters. do self.with_type_parameter_rib(HasTypeParameters @@ -3784,23 +3782,6 @@ pub impl Resolver { for fields.each |field| { self.resolve_type(field.node.ty, visitor); } - - // Resolve the destructor, if applicable. - match *optional_destructor { - None => { - // Nothing to do. - } - Some(ref destructor) => { - self.resolve_function(NormalRibKind, - None, - NoTypeParameters, - &destructor.node.body, - HasSelfBinding - ((*destructor).node.self_id, - true), - visitor); - } - } } } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index efa10dfc2aa34..b3f7ab8b00a0e 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2093,53 +2093,6 @@ pub fn trans_tuple_struct(ccx: @CrateContext, finish_fn(fcx, lltop); } -pub fn trans_struct_dtor(ccx: @CrateContext, - path: path, - body: &ast::blk, - dtor_id: ast::node_id, - psubsts: Option<@param_substs>, - hash_id: Option, - parent_id: ast::def_id) - -> ValueRef { - let tcx = ccx.tcx; - /* Look up the parent class's def_id */ - let mut class_ty = ty::lookup_item_type(tcx, parent_id).ty; - /* Substitute in the class type if necessary */ - for psubsts.each |ss| { - class_ty = ty::subst_tps(tcx, ss.tys, ss.self_ty, class_ty); - } - - /* The dtor takes a (null) output pointer, and a self argument, - and returns () */ - let lldty = type_of_dtor(ccx, class_ty); - - // XXX: Bad copies. - let s = get_dtor_symbol(ccx, copy path, dtor_id, psubsts); - - /* Register the dtor as a function. It has external linkage */ - let lldecl = decl_internal_cdecl_fn(ccx.llmod, s, lldty); - lib::llvm::SetLinkage(lldecl, lib::llvm::ExternalLinkage); - - /* If we're monomorphizing, register the monomorphized decl - for the dtor */ - for hash_id.each |h_id| { - ccx.monomorphized.insert(*h_id, lldecl); - } - /* Translate the dtor body */ - let decl = ast_util::dtor_dec(); - trans_fn(ccx, - path, - &decl, - body, - lldecl, - impl_self(class_ty), - psubsts, - dtor_id, - None, - []); - lldecl -} - pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::enum_def, id: ast::node_id, path: @ast_map::path, vi: @~[ty::VariantInfo], @@ -2158,8 +2111,7 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::enum_def, // Nothing to do. } ast::struct_variant_kind(struct_def) => { - trans_struct_def(ccx, struct_def, path, - variant.node.id); + trans_struct_def(ccx, struct_def); } } } @@ -2228,22 +2180,14 @@ pub fn trans_item(ccx: @CrateContext, item: &ast::item) { } ast::item_struct(struct_def, ref generics) => { if !generics.is_type_parameterized() { - trans_struct_def(ccx, struct_def, path, item.id); + trans_struct_def(ccx, struct_def); } } _ => {/* fall through */ } } } -pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::struct_def, - path: @ast_map::path, - id: ast::node_id) { - // Translate the destructor. - for struct_def.dtor.each |dtor| { - trans_struct_dtor(ccx, /*bad*/copy *path, &dtor.node.body, - dtor.node.id, None, None, local_def(id)); - }; - +pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::struct_def) { // If this is a tuple-like struct, translate the constructor. match struct_def.ctor_id { // We only need to translate a constructor if there are fields; @@ -2477,46 +2421,6 @@ pub fn item_path(ccx: @CrateContext, i: @ast::item) -> path { vec::append(/*bad*/copy *base, ~[path_name(i.ident)]) } -/* If there's already a symbol for the dtor with and substs , - return it; otherwise, create one and register it, returning it as well */ -pub fn get_dtor_symbol(ccx: @CrateContext, - path: path, - id: ast::node_id, - substs: Option<@param_substs>) - -> ~str { - let t = ty::node_id_to_type(ccx.tcx, id); - match ccx.item_symbols.find(&id) { - Some(s) => (/*bad*/copy *s), - None if substs.is_none() => { - let s = mangle_exported_name( - ccx, - vec::append(path, ~[path_name((ccx.names)(~"dtor"))]), - t); - // XXX: Bad copy, use `@str`? - ccx.item_symbols.insert(id, copy s); - s - } - None => { - // Monomorphizing, so just make a symbol, don't add - // this to item_symbols - match substs { - Some(ss) => { - let mono_ty = ty::subst_tps(ccx.tcx, ss.tys, ss.self_ty, t); - mangle_exported_name( - ccx, - vec::append(path, - ~[path_name((ccx.names)(~"dtor"))]), - mono_ty) - } - None => { - ccx.sess.bug(fmt!("get_dtor_symbol: not monomorphizing and \ - couldn't find a symbol for dtor %?", path)); - } - } - } - } -} - pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef { debug!("get_item_val(id=`%?`)", id); let tcx = ccx.tcx; @@ -2602,28 +2506,6 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef { } } } - ast_map::node_dtor(_, dt, parent_id, pt) => { - /* - Don't just call register_fn, since we don't want to add - the implicit self argument automatically (we want to make sure - it has the right type) - */ - // Want parent_id and not id, because id is the dtor's type - let class_ty = ty::lookup_item_type(tcx, parent_id).ty; - // This code shouldn't be reached if the class is generic - assert!(!ty::type_has_params(class_ty)); - let lldty = T_fn(~[ - T_ptr(T_i8()), - T_ptr(type_of(ccx, class_ty)) - ], - T_nil()); - let s = get_dtor_symbol(ccx, /*bad*/copy *pt, dt.node.id, None); - - /* Make the declaration for the dtor */ - let llfn = decl_internal_cdecl_fn(ccx.llmod, s, lldty); - lib::llvm::SetLinkage(llfn, lib::llvm::ExternalLinkage); - llfn - } ast_map::node_variant(ref v, enm, pth) => { let llfn; diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 2a2bf7ba4ad68..58fc5ea3be647 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -983,9 +983,6 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata { expected an expr_fn_block here") } } - ast_map::node_dtor(_, _, did, _) => { - ((dbg_cx.names)(~"dtor"), ast_util::dtor_ty(), did.node) - } _ => fcx.ccx.sess.bug(~"create_function: unexpected \ sort of node") }; diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index 7a7f03c2273e1..ad06a9715b4af 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -118,10 +118,6 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id, } local_def(mth.id) } - csearch::found(ast::ii_dtor(ref dtor, _, _, _)) => { - ccx.external.insert(fn_id, Some((*dtor).node.id)); - local_def((*dtor).node.id) - } } } } diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 72ad6dde4f17d..aa49915d1759b 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -13,7 +13,7 @@ use driver::session; use lib::llvm::ValueRef; use middle::trans::base::{get_insn_ctxt}; use middle::trans::base::{set_inline_hint_if_appr, set_inline_hint}; -use middle::trans::base::{trans_enum_variant, trans_struct_dtor}; +use middle::trans::base::{trans_enum_variant}; use middle::trans::base::{trans_fn, decl_internal_cdecl_fn}; use middle::trans::base::{get_item_val, no_self}; use middle::trans::base; @@ -35,7 +35,6 @@ use syntax::ast_map; use syntax::ast_map::path_name; use syntax::ast_util::local_def; use syntax::opt_vec; -use syntax::parse::token::special_idents; use syntax::abi::AbiSet; pub fn monomorphic_fn(ccx: @CrateContext, @@ -116,8 +115,6 @@ pub fn monomorphic_fn(ccx: @CrateContext, // Foreign externs don't have to be monomorphized. return (get_item_val(ccx, fn_id.node), true); } - ast_map::node_dtor(_, dtor, _, pt) => - (pt, special_idents::dtor, dtor.span), ast_map::node_trait_method(@ast::provided(m), _, pt) => { (pt, m.ident, m.span) } @@ -243,16 +240,6 @@ pub fn monomorphic_fn(ccx: @CrateContext, meth::trans_method(ccx, pt, mth, psubsts, None, d, impl_did); d } - ast_map::node_dtor(_, dtor, _, pt) => { - let parent_id = match ty::ty_to_def_id(ty::node_id_to_type(ccx.tcx, - dtor.node.self_id)) { - Some(did) => did, - None => ccx.sess.span_bug(dtor.span, ~"Bad self ty in \ - dtor") - }; - trans_struct_dtor(ccx, /*bad*/copy *pt, &dtor.node.body, - dtor.node.id, psubsts, Some(hash_id), parent_id) - } ast_map::node_trait_method(@ast::provided(mth), _, pt) => { let d = mk_lldecl(); set_inline_hint_if_appr(/*bad*/copy mth.attrs, d); diff --git a/src/librustc/middle/trans/reachable.rs b/src/librustc/middle/trans/reachable.rs index 3ccef0dbc4aca..234473dd35b60 100644 --- a/src/librustc/middle/trans/reachable.rs +++ b/src/librustc/middle/trans/reachable.rs @@ -124,18 +124,10 @@ fn traverse_public_item(cx: &ctx, item: @item) { } } } - item_struct(ref struct_def, ref generics) => { + item_struct(ref struct_def, _) => { for struct_def.ctor_id.each |&ctor_id| { cx.rmap.insert(ctor_id); } - for struct_def.dtor.each |dtor| { - cx.rmap.insert(dtor.node.id); - if generics.ty_params.len() > 0u || - attr::find_inline_attr(dtor.node.attrs) != attr::ia_none - { - traverse_inline_body(cx, &dtor.node.body); - } - } } item_ty(t, _) => { traverse_ty(t, cx, @@ -239,9 +231,6 @@ fn traverse_all_resources_and_impls(cx: &ctx, crate_mod: &_mod) { visit_item: |i, cx, v| { visit::visit_item(i, cx, v); match i.node { - item_struct(sdef, _) if sdef.dtor.is_some() => { - traverse_public_item(cx, i); - } item_impl(*) => { traverse_public_item(cx, i); } diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index 33145dd4334a5..e19eba6ca98f9 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -157,9 +157,6 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) for uint::range(0u, n_tps) |n| { cx.uses[n] |= flags;} } } - ast_map::node_dtor(_, ref dtor, _, _) => { - handle_body(cx, &dtor.node.body); - } ast_map::node_struct_ctor(*) => { // Similarly to node_variant, this monomorphized function just uses // the representations of all of its type parameters. diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index c7fb1e94adf4c..5b8e0e03b628c 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3748,28 +3748,8 @@ pub impl DtorKind { Otherwise return none. */ pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind { match cx.destructor_for_type.find(&struct_id) { - Some(&method_def_id) => return TraitDtor(method_def_id), - None => {} // Continue. - } - - if is_local(struct_id) { - match cx.items.find(&struct_id.node) { - Some(&ast_map::node_item(@ast::item { - node: ast::item_struct(@ast::struct_def { dtor: Some(ref dtor), - _ }, - _), - _ - }, _)) => - LegacyDtor(local_def((*dtor).node.id)), - _ => - NoDtor - } - } - else { - match csearch::struct_dtor(cx.sess.cstore, struct_id) { + Some(&method_def_id) => TraitDtor(method_def_id), None => NoDtor, - Some(did) => LegacyDtor(did), - } } } @@ -3819,11 +3799,6 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { ast_map::path_name((*variant).node.name)) } - ast_map::node_dtor(_, _, _, path) => { - vec::append_one(/*bad*/copy *path, ast_map::path_name( - syntax::parse::token::special_idents::literally_dtor)) - } - ast_map::node_struct_ctor(_, item, path) => { vec::append_one(/*bad*/copy *path, ast_map::path_name(item.ident)) } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index b9f3de873cf07..d1c5ae18bc30b 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -557,30 +557,7 @@ pub fn check_no_duplicate_fields(tcx: ty::ctxt, } } -pub fn check_struct(ccx: @mut CrateCtxt, - struct_def: @ast::struct_def, - id: ast::node_id, - span: span) { - let tcx = ccx.tcx; - let self_ty = ty::node_id_to_type(tcx, id); - - for struct_def.dtor.each |dtor| { - let class_t = SelfInfo { - self_ty: self_ty, - self_id: dtor.node.self_id, - span: dtor.span, - }; - // typecheck the dtor - let dtor_dec = ast_util::dtor_dec(); - check_bare_fn( - ccx, - &dtor_dec, - &dtor.node.body, - dtor.node.id, - Some(class_t) - ); - }; - +pub fn check_struct(ccx: @mut CrateCtxt, id: ast::node_id, span: span) { // Check that the class is instantiable check_instantiable(ccx.tcx, span, id); } @@ -623,8 +600,8 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) { } } } - ast::item_struct(struct_def, _) => { - check_struct(ccx, struct_def, it.id, it.span); + ast::item_struct(*) => { + check_struct(ccx, it.id, it.span); } ast::item_ty(t, ref generics) => { let tpt_ty = ty::node_id_to_type(ccx.tcx, it.id); diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 0ffd398d03c19..10537711b3289 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -49,7 +49,6 @@ use syntax::ast::{RegionTyParamBound, TraitTyParamBound}; use syntax::ast; use syntax::ast_map; use syntax::ast_util::{local_def, split_trait_methods}; -use syntax::ast_util; use syntax::codemap::span; use syntax::codemap; use syntax::print::pprust::{path_to_str, self_ty_to_str}; @@ -897,30 +896,6 @@ pub fn convert_struct(ccx: &CrateCtxt, id: ast::node_id) { let tcx = ccx.tcx; - for struct_def.dtor.each |dtor| { - let region_parameterization = - RegionParameterization::from_variance_and_generics(rp, generics); - - // Write the dtor type - let t_dtor = ty::mk_bare_fn( - tcx, - astconv::ty_of_bare_fn( - ccx, - &type_rscope(region_parameterization), - ast::impure_fn, - AbiSet::Rust(), - &opt_vec::Empty, - &ast_util::dtor_dec())); - write_ty_to_tcx(tcx, dtor.node.id, t_dtor); - tcx.tcache.insert(local_def(dtor.node.id), - ty_param_bounds_and_ty { - generics: ty::Generics { - type_param_defs: tpt.generics.type_param_defs, - region_param: rp - }, - ty: t_dtor}); - }; - // Write the type of each of the members for struct_def.fields.each |f| { convert_field(ccx, rp, tpt.generics.type_param_defs, *f, generics); diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index 303bdc53b6982..a6fbee81bc8af 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -332,13 +332,7 @@ fn fold_struct( /// what I actually want fn strip_struct_extra_stuff(item: @ast::item) -> @ast::item { let node = match copy item.node { - ast::item_struct(def, tys) => { - let def = @ast::struct_def { - dtor: None, // Remove the drop { } block - .. copy *def - }; - ast::item_struct(def, tys) - } + ast::item_struct(def, tys) => ast::item_struct(def, tys), _ => fail!(~"not a struct") }; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index ba6fe1cda4f31..71fd506ebede3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1174,10 +1174,7 @@ pub enum struct_field_kind { #[auto_decode] #[deriving(Eq)] pub struct struct_def { - fields: ~[@struct_field], /* fields */ - /* (not including ctor or dtor) */ - /* dtor is optional */ - dtor: Option, + fields: ~[@struct_field], /* fields, not including ctor */ /* ID of the constructor. This is only used for tuple- or enum-like * structs. */ ctor_id: Option @@ -1230,18 +1227,6 @@ impl to_bytes::IterBytes for struct_mutability { } } -pub type struct_dtor = spanned; - -#[auto_encode] -#[auto_decode] -#[deriving(Eq)] -pub struct struct_dtor_ { - id: node_id, - attrs: ~[attribute], - self_id: node_id, - body: blk, -} - #[auto_encode] #[auto_decode] #[deriving(Eq)] @@ -1272,7 +1257,6 @@ pub enum inlined_item { ii_item(@item), ii_method(def_id /* impl id */, @method), ii_foreign(@foreign_item), - ii_dtor(struct_dtor, ident, Generics, def_id /* parent id */) } /* hold off on tests ... they appear in a later merge. diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index f9828ad2b9e4e..d2125cebb5e48 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -14,7 +14,6 @@ use ast; use ast_util::{inlined_item_utils, stmt_id}; use ast_util; use codemap; -use codemap::spanned; use diagnostic::span_handler; use parse::token::ident_interner; use print::pprust; @@ -93,8 +92,6 @@ pub enum ast_node { // order they are introduced. node_arg(arg, uint), node_local(uint), - // Destructor for a struct - node_dtor(Generics, @struct_dtor, def_id, @path), node_block(blk), node_struct_ctor(@struct_def, @item, @path), } @@ -163,7 +160,7 @@ pub fn map_decoded_item(diag: @span_handler, // don't decode and instantiate the impl, but just the method, we have to // add it to the table now: match *ii { - ii_item(*) | ii_dtor(*) => { /* fallthrough */ } + ii_item(*) => { /* fallthrough */ } ii_foreign(i) => { cx.map.insert(i.id, node_foreign_item(i, AbiSet::Intrinsic(), @@ -193,27 +190,6 @@ pub fn map_fn( node_arg(/* FIXME (#2543) */ copy *a, cx.local_id)); cx.local_id += 1u; } - match *fk { - visit::fk_dtor(generics, ref attrs, self_id, parent_id) => { - let dt = @spanned { - node: ast::struct_dtor_ { - id: id, - attrs: /* FIXME (#2543) */ vec::from_slice(*attrs), - self_id: self_id, - body: /* FIXME (#2543) */ copy *body, - }, - span: sp, - }; - cx.map.insert( - id, - node_dtor( - /* FIXME (#2543) */ copy *generics, - dt, - parent_id, - @/* FIXME (#2543) */ copy cx.path)); - } - _ => () - } visit::visit_fn(fk, decl, body, sp, id, cx, v); } @@ -411,9 +387,6 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { Some(&node_local(_)) => { // add more info here fmt!("local (id=%?)", id) } - Some(&node_dtor(*)) => { // add more info here - fmt!("node_dtor (id=%?)", id) - } Some(&node_block(_)) => { fmt!("block") } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 148b713a4f58f..bf5381831d054 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -302,7 +302,6 @@ impl inlined_item_utils for inlined_item { ii_item(i) => /* FIXME (#2543) */ copy i.ident, ii_foreign(i) => /* FIXME (#2543) */ copy i.ident, ii_method(_, m) => /* FIXME (#2543) */ copy m.ident, - ii_dtor(_, nm, _, _) => /* FIXME (#2543) */ copy nm } } @@ -311,7 +310,6 @@ impl inlined_item_utils for inlined_item { ii_item(i) => i.id, ii_foreign(i) => i.id, ii_method(_, m) => m.id, - ii_dtor(ref dtor, _, _, _) => (*dtor).node.id } } @@ -320,10 +318,6 @@ impl inlined_item_utils for inlined_item { ii_item(i) => (v.visit_item)(i, e, v), ii_foreign(i) => (v.visit_foreign_item)(i, e, v), ii_method(_, m) => visit::visit_method_helper(m, e, v), - ii_dtor(/*bad*/ copy dtor, _, ref generics, parent_id) => { - visit::visit_struct_dtor_helper(dtor, generics, - parent_id, e, v); - } } } } @@ -359,20 +353,6 @@ pub fn operator_prec(op: ast::binop) -> uint { /// not appearing in the prior table. pub static as_prec: uint = 11u; -pub fn dtor_ty() -> @ast::Ty { - @ast::Ty {id: 0, node: ty_nil, span: dummy_sp()} -} - -pub fn dtor_dec() -> fn_decl { - let nil_t = dtor_ty(); - // dtor has no args - ast::fn_decl { - inputs: ~[], - output: nil_t, - cf: return_val, - } -} - pub fn empty_generics() -> Generics { Generics {lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty} @@ -457,12 +437,6 @@ pub fn id_visitor(vfn: @fn(node_id)) -> visit::vt<()> { vfn(id); match *fk { - visit::fk_dtor(generics, _, self_id, parent_id) => { - visit_generics(generics); - vfn(id); - vfn(self_id); - vfn(parent_id.node); - } visit::fk_item_fn(_, generics, _, _) => { visit_generics(generics); } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 3311c61de8b64..3ad94905f7f78 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -431,7 +431,6 @@ impl gen_init for protocol { dummy_sp(), ast::struct_def { fields: fields, - dtor: None, ctor_id: None }, cx.strip_bounds(&generics)) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index d82608846ab98..adfc95f3e94d1 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -290,21 +290,8 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ { fn fold_struct_def(struct_def: @ast::struct_def, fld: @ast_fold) -> @ast::struct_def { - let dtor = do struct_def.dtor.map |dtor| { - let dtor_body = fld.fold_block(&dtor.node.body); - let dtor_id = fld.new_id(dtor.node.id); - spanned { - node: ast::struct_dtor_ { - body: dtor_body, - id: dtor_id, - .. copy dtor.node - }, - span: copy dtor.span - } - }; @ast::struct_def { fields: struct_def.fields.map(|f| fold_struct_field(*f, fld)), - dtor: dtor, ctor_id: struct_def.ctor_id.map(|cid| fld.new_id(*cid)), } } @@ -655,22 +642,9 @@ fn noop_fold_variant(v: &variant_, fld: @ast_fold) -> variant_ { }) } struct_variant_kind(struct_def) => { - let dtor = do struct_def.dtor.map |dtor| { - let dtor_body = fld.fold_block(&dtor.node.body); - let dtor_id = fld.new_id(dtor.node.id); - spanned { - node: ast::struct_dtor_ { - body: dtor_body, - id: dtor_id, - .. copy dtor.node - }, - .. copy *dtor - } - }; kind = struct_variant_kind(@ast::struct_def { fields: vec::map(struct_def.fields, |f| fld.fold_struct_field(*f)), - dtor: dtor, ctor_id: struct_def.ctor_id.map(|c| fld.new_id(*c)) }) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1a4a15b3bf522..27a1cde2f9638 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3346,7 +3346,6 @@ pub impl Parser { (class_name, item_struct(@ast::struct_def { fields: fields, - dtor: None, ctor_id: if is_tuple_like { Some(new_id) } else { None } }, generics), None) @@ -3803,7 +3802,6 @@ pub impl Parser { return @ast::struct_def { fields: fields, - dtor: None, ctor_id: None }; } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d5645ada9294a..f23badd046206 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -693,13 +693,6 @@ pub fn print_struct(s: @ps, nbsp(s); bopen(s); hardbreak_if_not_bol(s); - for struct_def.dtor.each |dtor| { - hardbreak_if_not_bol(s); - maybe_print_comment(s, dtor.span.lo); - print_outer_attributes(s, dtor.node.attrs); - head(s, ~"drop"); - print_block(s, &dtor.node.body); - } for struct_def.fields.each |field| { match field.node.kind { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 80df8fb91a515..71cfbab91089e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -11,7 +11,6 @@ use abi::AbiSet; use ast::*; use ast; -use ast_util; use codemap::span; use parse; use opt_vec; @@ -39,13 +38,6 @@ pub enum fn_kind<'self> { // |x, y| ... fk_fn_block, - - fk_dtor( // class destructor - &'self Generics, - &'self [attribute], - node_id /* self id */, - def_id /* parent class id */ - ) } pub fn name_of_fn(fk: &fn_kind) -> ident { @@ -54,15 +46,13 @@ pub fn name_of_fn(fk: &fn_kind) -> ident { name } fk_anon(*) | fk_fn_block(*) => parse::token::special_idents::anon, - fk_dtor(*) => parse::token::special_idents::dtor } } pub fn generics_of_fn(fk: &fn_kind) -> Generics { match *fk { fk_item_fn(_, generics, _, _) | - fk_method(_, generics, _) | - fk_dtor(generics, _, _, _) => { + fk_method(_, generics, _) => { copy *generics } fk_anon(*) | fk_fn_block(*) => { @@ -369,25 +359,6 @@ pub fn visit_method_helper(m: &method, e: E, v: vt) { ); } -pub fn visit_struct_dtor_helper(dtor: struct_dtor, generics: &Generics, - parent_id: def_id, e: E, v: vt) { - (v.visit_fn)( - &fk_dtor( - generics, - dtor.node.attrs, - dtor.node.self_id, - parent_id - ), - &ast_util::dtor_dec(), - &dtor.node.body, - dtor.span, - dtor.node.id, - e, - v - ) - -} - pub fn visit_fn(fk: &fn_kind, decl: &fn_decl, body: &blk, _sp: span, _id: node_id, e: E, v: vt) { visit_fn_decl(decl, e, v); @@ -412,23 +383,14 @@ pub fn visit_trait_method(m: &trait_method, e: E, v: vt) { pub fn visit_struct_def( sd: @struct_def, _nm: ast::ident, - generics: &Generics, - id: node_id, + _generics: &Generics, + _id: node_id, e: E, v: vt ) { for sd.fields.each |f| { (v.visit_struct_field)(*f, e, v); } - for sd.dtor.each |dtor| { - visit_struct_dtor_helper( - *dtor, - generics, - ast_util::local_def(id), - e, - v - ) - } } pub fn visit_struct_field(sf: @struct_field, e: E, v: vt) { From 3e3e2f00250d77719598ad052bb2016d46e6a148 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 30 Apr 2013 20:20:08 -0700 Subject: [PATCH 4/8] allow parsing attributes on struct fields --- src/libsyntax/ast.rs | 1 + src/libsyntax/ext/pipes/pipec.rs | 3 ++- src/libsyntax/fold.rs | 7 ++++++- src/libsyntax/parse/obsolete.rs | 6 +++--- src/libsyntax/parse/parser.rs | 30 ++++++++++++++++++------------ src/libsyntax/print/pprust.rs | 1 + 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 71fd506ebede3..a853dbed2f123 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1158,6 +1158,7 @@ pub struct struct_field_ { kind: struct_field_kind, id: node_id, ty: @Ty, + attrs: ~[attribute], } pub type struct_field = spanned; diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 3ad94905f7f78..e876972fe6878 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -415,7 +415,8 @@ impl gen_init for protocol { ast::struct_immutable, ast::inherited), id: cx.next_id(), - ty: fty + ty: fty, + attrs: ~[], }, span: dummy_sp() } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index adfc95f3e94d1..36565395e5988 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -222,9 +222,12 @@ pub fn noop_fold_item(i: @item, fld: @ast_fold) -> Option<@item> { fn noop_fold_struct_field(sf: @struct_field, fld: @ast_fold) -> @struct_field { + let fold_attribute = |x| fold_attribute_(x, fld); + @spanned { node: ast::struct_field_ { kind: copy sf.node.kind, id: sf.node.id, - ty: fld.fold_ty(sf.node.ty) }, + ty: fld.fold_ty(sf.node.ty), + attrs: sf.node.attrs.map(|e| fold_attribute(*e)) }, span: sf.span } } @@ -309,6 +312,7 @@ fn fold_struct_field(f: @struct_field, fld: @ast_fold) -> @struct_field { kind: copy f.node.kind, id: fld.new_id(f.node.id), ty: fld.fold_ty(f.node.ty), + attrs: /* FIXME (#2543) */ copy f.node.attrs, }, span: fld.new_span(f.span), } @@ -757,6 +761,7 @@ impl ast_fold for AstFoldFns { kind: copy sf.node.kind, id: sf.node.id, ty: (self as @ast_fold).fold_ty(sf.node.ty), + attrs: copy sf.node.attrs, }, span: (self.new_span)(sf.span), } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index ce21e0f672d45..c1afc53def0c2 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -18,7 +18,7 @@ removed. */ -use ast::{expr, expr_lit, lit_nil}; +use ast::{expr, expr_lit, lit_nil, attribute}; use ast; use codemap::{span, respan}; use parse::parser::Parser; @@ -282,13 +282,13 @@ pub impl Parser { } } - fn try_parse_obsolete_priv_section(&self) -> bool { + fn try_parse_obsolete_priv_section(&self, attrs: ~[attribute]) -> bool { if self.is_keyword(&~"priv") && self.look_ahead(1) == token::LBRACE { self.obsolete(copy *self.span, ObsoletePrivSection); self.eat_keyword(&~"priv"); self.bump(); while *self.token != token::RBRACE { - self.parse_single_struct_field(ast::private); + self.parse_single_struct_field(ast::private, attrs); } self.bump(); true diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 27a1cde2f9638..74af745840891 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2520,7 +2520,9 @@ pub impl Parser { } // parse a structure field - fn parse_name_and_ty(&self, pr: visibility) -> @struct_field { + fn parse_name_and_ty(&self, + pr: visibility, + attrs: ~[attribute]) -> @struct_field { let mut is_mutbl = struct_immutable; let lo = self.span.lo; if self.eat_keyword(&~"mut") { @@ -2535,7 +2537,8 @@ pub impl Parser { @spanned(lo, self.last_span.hi, ast::struct_field_ { kind: named_field(name, is_mutbl, pr), id: self.get_id(), - ty: ty + ty: ty, + attrs: attrs, }) } @@ -3318,11 +3321,13 @@ pub impl Parser { &token::RPAREN, seq_sep_trailing_allowed(token::COMMA) ) |p| { + let attrs = self.parse_outer_attributes(); let lo = p.span.lo; let struct_field_ = ast::struct_field_ { kind: unnamed_field, id: self.get_id(), - ty: p.parse_ty(false) + ty: p.parse_ty(false), + attrs: attrs, }; @spanned(lo, p.span.hi, struct_field_) }; @@ -3359,12 +3364,14 @@ pub impl Parser { } // parse a structure field declaration - fn parse_single_struct_field(&self, vis: visibility) -> @struct_field { + fn parse_single_struct_field(&self, + vis: visibility, + attrs: ~[attribute]) -> @struct_field { if self.eat_obsolete_ident("let") { self.obsolete(*self.last_span, ObsoleteLet); } - let a_var = self.parse_name_and_ty(vis); + let a_var = self.parse_name_and_ty(vis, attrs); match *self.token { token::SEMI => { self.obsolete(copy *self.span, ObsoleteFieldTerminator); @@ -3390,26 +3397,25 @@ pub impl Parser { // parse an element of a struct definition fn parse_struct_decl_field(&self) -> ~[@struct_field] { - if self.try_parse_obsolete_priv_section() { + let attrs = self.parse_outer_attributes(); + + if self.try_parse_obsolete_priv_section(attrs) { return ~[]; } - // Need this to parse comments on fields. - let _attrs = self.parse_outer_attributes(); - if self.eat_keyword(&~"priv") { - return ~[self.parse_single_struct_field(private)] + return ~[self.parse_single_struct_field(private, attrs)] } if self.eat_keyword(&~"pub") { - return ~[self.parse_single_struct_field(public)]; + return ~[self.parse_single_struct_field(public, attrs)]; } if self.try_parse_obsolete_struct_ctor() { return ~[]; } - return ~[self.parse_single_struct_field(inherited)]; + return ~[self.parse_single_struct_field(inherited, attrs)]; } // parse visiility: PUB, PRIV, or nothing diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f23badd046206..ab958d8b5cef5 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -700,6 +700,7 @@ pub fn print_struct(s: @ps, ast::named_field(ident, mutability, visibility) => { hardbreak_if_not_bol(s); maybe_print_comment(s, field.span.lo); + print_outer_attributes(s, field.node.attrs); print_visibility(s, visibility); if mutability == ast::struct_mutable { word_nbsp(s, ~"mut"); From 5fee32457fdb9ad495c9f19fa59e8b9b6c34f48b Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 30 Apr 2013 22:42:36 -0700 Subject: [PATCH 5/8] syntax: remove parse::token::{dtor,literally_dtor} --- src/libsyntax/parse/token.rs | 145 +++++++++++++++++------------------ 1 file changed, 70 insertions(+), 75 deletions(-) diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 0327a3b80da87..4c1a92f898e2d 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -305,50 +305,47 @@ pub fn is_bar(t: &Token) -> bool { pub mod special_idents { use ast::ident; - pub static underscore : ident = ident { repr: 0u, ctxt: 0}; - pub static anon : ident = ident { repr: 1u, ctxt: 0}; - pub static dtor : ident = ident { repr: 2u, ctxt: 0}; // 'drop', but that's - // reserved - pub static invalid : ident = ident { repr: 3u, ctxt: 0}; // '' - pub static unary : ident = ident { repr: 4u, ctxt: 0}; - pub static not_fn : ident = ident { repr: 5u, ctxt: 0}; - pub static idx_fn : ident = ident { repr: 6u, ctxt: 0}; - pub static unary_minus_fn : ident = ident { repr: 7u, ctxt: 0}; - pub static clownshoes_extensions : ident = ident { repr: 8u, ctxt: 0}; - - pub static self_ : ident = ident { repr: 9u, ctxt: 0}; // 'self' + pub static underscore : ident = ident { repr: 0, ctxt: 0}; + pub static anon : ident = ident { repr: 1, ctxt: 0}; + pub static invalid : ident = ident { repr: 2, ctxt: 0}; // '' + pub static unary : ident = ident { repr: 3, ctxt: 0}; + pub static not_fn : ident = ident { repr: 4, ctxt: 0}; + pub static idx_fn : ident = ident { repr: 5, ctxt: 0}; + pub static unary_minus_fn : ident = ident { repr: 6, ctxt: 0}; + pub static clownshoes_extensions : ident = ident { repr: 7, ctxt: 0}; + + pub static self_ : ident = ident { repr: 8, ctxt: 0}; // 'self' /* for matcher NTs */ - pub static item : ident = ident { repr: 10u, ctxt: 0}; - pub static block : ident = ident { repr: 11u, ctxt: 0}; - pub static stmt : ident = ident { repr: 12u, ctxt: 0}; - pub static pat : ident = ident { repr: 13u, ctxt: 0}; - pub static expr : ident = ident { repr: 14u, ctxt: 0}; - pub static ty : ident = ident { repr: 15u, ctxt: 0}; - pub static ident : ident = ident { repr: 16u, ctxt: 0}; - pub static path : ident = ident { repr: 17u, ctxt: 0}; - pub static tt : ident = ident { repr: 18u, ctxt: 0}; - pub static matchers : ident = ident { repr: 19u, ctxt: 0}; - - pub static str : ident = ident { repr: 20u, ctxt: 0}; // for the type + pub static item : ident = ident { repr: 9, ctxt: 0}; + pub static block : ident = ident { repr: 10, ctxt: 0}; + pub static stmt : ident = ident { repr: 11, ctxt: 0}; + pub static pat : ident = ident { repr: 12, ctxt: 0}; + pub static expr : ident = ident { repr: 13, ctxt: 0}; + pub static ty : ident = ident { repr: 14, ctxt: 0}; + pub static ident : ident = ident { repr: 15, ctxt: 0}; + pub static path : ident = ident { repr: 16, ctxt: 0}; + pub static tt : ident = ident { repr: 17, ctxt: 0}; + pub static matchers : ident = ident { repr: 18, ctxt: 0}; + + pub static str : ident = ident { repr: 19, ctxt: 0}; // for the type /* outside of libsyntax */ - pub static ty_visitor : ident = ident { repr: 21u, ctxt: 0}; - pub static arg : ident = ident { repr: 22u, ctxt: 0}; - pub static descrim : ident = ident { repr: 23u, ctxt: 0}; - pub static clownshoe_abi : ident = ident { repr: 24u, ctxt: 0}; - pub static clownshoe_stack_shim : ident = ident { repr: 25u, ctxt: 0}; - pub static tydesc : ident = ident { repr: 26u, ctxt: 0}; - pub static literally_dtor : ident = ident { repr: 27u, ctxt: 0}; - pub static main : ident = ident { repr: 28u, ctxt: 0}; - pub static opaque : ident = ident { repr: 29u, ctxt: 0}; - pub static blk : ident = ident { repr: 30u, ctxt: 0}; - pub static static : ident = ident { repr: 31u, ctxt: 0}; - pub static intrinsic : ident = ident { repr: 32u, ctxt: 0}; - pub static clownshoes_foreign_mod: ident = ident { repr: 33u, ctxt: 0}; - pub static unnamed_field: ident = ident { repr: 34u, ctxt: 0}; - pub static c_abi: ident = ident { repr: 35u, ctxt: 0}; - pub static type_self: ident = ident { repr: 36u, ctxt: 0}; // `Self` + pub static ty_visitor : ident = ident { repr: 20, ctxt: 0}; + pub static arg : ident = ident { repr: 21, ctxt: 0}; + pub static descrim : ident = ident { repr: 22, ctxt: 0}; + pub static clownshoe_abi : ident = ident { repr: 23, ctxt: 0}; + pub static clownshoe_stack_shim : ident = ident { repr: 24, ctxt: 0}; + pub static tydesc : ident = ident { repr: 25, ctxt: 0}; + pub static main : ident = ident { repr: 26, ctxt: 0}; + pub static opaque : ident = ident { repr: 27, ctxt: 0}; + pub static blk : ident = ident { repr: 28, ctxt: 0}; + pub static static : ident = ident { repr: 29, ctxt: 0}; + pub static intrinsic : ident = ident { repr: 30, ctxt: 0}; + pub static clownshoes_foreign_mod: ident = ident { repr: 31, ctxt: 0}; + pub static unnamed_field: ident = ident { repr: 32, ctxt: 0}; + pub static c_abi: ident = ident { repr: 33, ctxt: 0}; + pub static type_self: ident = ident { repr: 34, ctxt: 0}; // `Self` } pub struct StringRef<'self>(&'self str); @@ -426,41 +423,39 @@ pub fn mk_fresh_ident_interner() -> @ident_interner { let init_vec = ~[ @~"_", // 0 @~"anon", // 1 - @~"drop", // 2 - @~"", // 3 - @~"unary", // 4 - @~"!", // 5 - @~"[]", // 6 - @~"unary-", // 7 - @~"__extensions__", // 8 - @~"self", // 9 - @~"item", // 10 - @~"block", // 11 - @~"stmt", // 12 - @~"pat", // 13 - @~"expr", // 14 - @~"ty", // 15 - @~"ident", // 16 - @~"path", // 17 - @~"tt", // 18 - @~"matchers", // 19 - @~"str", // 20 - @~"TyVisitor", // 21 - @~"arg", // 22 - @~"descrim", // 23 - @~"__rust_abi", // 24 - @~"__rust_stack_shim", // 25 - @~"TyDesc", // 26 - @~"dtor", // 27 - @~"main", // 28 - @~"", // 29 - @~"blk", // 30 - @~"static", // 31 - @~"intrinsic", // 32 - @~"__foreign_mod__", // 33 - @~"__field__", // 34 - @~"C", // 35 - @~"Self", // 36 + @~"", // 2 + @~"unary", // 3 + @~"!", // 4 + @~"[]", // 5 + @~"unary-", // 6 + @~"__extensions__", // 7 + @~"self", // 8 + @~"item", // 9 + @~"block", // 10 + @~"stmt", // 11 + @~"pat", // 12 + @~"expr", // 13 + @~"ty", // 14 + @~"ident", // 15 + @~"path", // 16 + @~"tt", // 17 + @~"matchers", // 18 + @~"str", // 19 + @~"TyVisitor", // 20 + @~"arg", // 21 + @~"descrim", // 22 + @~"__rust_abi", // 23 + @~"__rust_stack_shim", // 24 + @~"TyDesc", // 25 + @~"main", // 26 + @~"", // 27 + @~"blk", // 28 + @~"static", // 29 + @~"intrinsic", // 30 + @~"__foreign_mod__", // 31 + @~"__field__", // 32 + @~"C", // 33 + @~"Self", // 34 ]; let rv = @ident_interner { From e9688fcfe3d345ae34e25c3bd51f878be4410d96 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 30 Apr 2013 22:47:09 -0700 Subject: [PATCH 6/8] remove some warnings --- src/compiletest/header.rs | 3 +-- src/compiletest/runtest.rs | 2 +- src/libsyntax/ast_util.rs | 2 +- src/libsyntax/parse/mod.rs | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index b0d04c6739b4a..b29e1c77be35e 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -82,14 +82,13 @@ pub fn load_props(testfile: &Path) -> TestProps { } pub fn is_test_ignored(config: config, testfile: &Path) -> bool { - let mut found = false; for iter_header(testfile) |ln| { if parse_name_directive(ln, ~"xfail-test") { return true; } if parse_name_directive(ln, xfail_target()) { return true; } if config.mode == common::mode_pretty && parse_name_directive(ln, ~"xfail-pretty") { return true; } }; - return found; + return true; fn xfail_target() -> ~str { ~"xfail-" + str::from_slice(os::SYSNAME) diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index fef4cabf7fd6d..5805c1730296c 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -106,7 +106,7 @@ fn run_rpass_test(config: config, props: TestProps, testfile: &Path) { fatal_ProcRes(~"test run failed!", ProcRes); } } else { - let mut ProcRes = jit_test(config, props, testfile); + let ProcRes = jit_test(config, props, testfile); if ProcRes.status != 0 { fatal_ProcRes(~"jit failed!", ProcRes); } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index bf5381831d054..283c232fb3f0e 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -11,7 +11,7 @@ use ast::*; use ast; use ast_util; -use codemap::{span, dummy_sp, spanned}; +use codemap::{span, spanned}; use parse::token; use visit; use opt_vec; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 7e7931bbb606b..5d51a54d770b1 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -24,7 +24,7 @@ use parse::token::{ident_interner, mk_ident_interner}; use core::io; use core::option::{None, Option, Some}; use core::path::Path; -use core::result::{Err, Ok, Result}; +use core::result::{Err, Ok}; pub mod lexer; pub mod parser; From e7a3bbd76c77fa7a878ecd86dcb5c772164cbb51 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 30 Apr 2013 23:30:04 -0700 Subject: [PATCH 7/8] rustdoc: Remove a now invalid test --- src/librustdoc/tystr_pass.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index a6fbee81bc8af..def32bdfd44d6 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -434,13 +434,6 @@ mod test { "struct S {")); } - #[test] - fn should_not_serialize_struct_drop_blocks() { - // All we care about are the fields - let doc = mk_doc(~"struct S { field: (), drop { } }"); - assert!(!(&doc.cratemod().structs()[0].sig).get().contains("drop")); - } - #[test] fn should_not_serialize_struct_attrs() { // All we care about are the fields From 7c9d089ee732c2930898574d9ecedbb01efe0eb9 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 1 May 2013 07:49:10 -0700 Subject: [PATCH 8/8] pipes: use finally to fix pipes::try_recv --- src/libcore/pipes.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 82dc598c750eb..145997fcb4bd5 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -88,6 +88,7 @@ use kinds::Owned; use libc; use ops::Drop; use option::{None, Option, Some}; +use unstable::finally::Finally; use unstable::intrinsics; use ptr; use task; @@ -396,28 +397,22 @@ pub fn try_recv(p: RecvPacketBuffered) let p_ = p.unwrap(); let p = unsafe { &*p_ }; - struct DropState<'self> { - p: &'self PacketHeader, - } - - #[unsafe_destructor] - impl<'self> Drop for DropState<'self> { - fn finalize(&self) { - unsafe { - if task::failing() { - self.p.state = Terminated; - let old_task = swap_task(&mut self.p.blocked_task, - ptr::null()); - if !old_task.is_null() { - rustrt::rust_task_deref(old_task); - } + do (|| { + try_recv_(p) + }).finally { + unsafe { + if task::failing() { + p.header.state = Terminated; + let old_task = swap_task(&mut p.header.blocked_task, ptr::null()); + if !old_task.is_null() { + rustrt::rust_task_deref(old_task); } } } } +} - let _drop_state = DropState { p: &p.header }; - +fn try_recv_(p: &Packet) -> Option { // optimistic path match p.header.state { Full => { @@ -454,7 +449,7 @@ pub fn try_recv(p: RecvPacketBuffered) Blocked); match old_state { Empty => { - debug!("no data available on %?, going to sleep.", p_); + debug!("no data available on %?, going to sleep.", p); if count == 0 { wait_event(this); }