diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-08-03 15:02:01 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-08-03 15:02:53 -0700 |
| commit | b65dd9d0908ba75ee4cf128058858aea87e4508a (patch) | |
| tree | 794ee6f47d188314a2b0256fd954cbcf8219331c /src/rustc | |
| parent | a805a1fb37443601819604954510cb312a724fe9 (diff) | |
rustc: Parse, serialize, and deserialize trait inheritance
Diffstat (limited to 'src/rustc')
| -rw-r--r-- | src/rustc/metadata/encoder.rs | 5 | ||||
| -rw-r--r-- | src/rustc/middle/resolve3.rs | 25 | ||||
| -rw-r--r-- | src/rustc/middle/typeck/check.rs | 4 | ||||
| -rw-r--r-- | src/rustc/middle/typeck/collect.rs | 13 |
4 files changed, 35 insertions, 12 deletions
diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs index 256d8e310c4..a5d398c7ad0 100644 --- a/src/rustc/metadata/encoder.rs +++ b/src/rustc/metadata/encoder.rs @@ -813,7 +813,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, vec::append(tps, m.tps)); } } - item_trait(tps, ms) { + item_trait(tps, traits, ms) { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); @@ -844,6 +844,9 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, i += 1u; } encode_path(ebml_w, path, ast_map::path_name(item.ident)); + for traits.each |associated_trait| { + encode_trait_ref(ebml_w, ecx, associated_trait) + } ebml_w.end_tag(); } item_mac(*) { fail ~"item macros unimplemented" } diff --git a/src/rustc/middle/resolve3.rs b/src/rustc/middle/resolve3.rs index 243c2af19b2..93173b4008f 100644 --- a/src/rustc/middle/resolve3.rs +++ b/src/rustc/middle/resolve3.rs @@ -988,7 +988,7 @@ class Resolver { visit_item(item, new_parent, visitor); } - item_trait(_, methods) { + item_trait(_, _, methods) { // Add the names of all the methods to the trait info. let method_names = @atom_hashmap(); for methods.each |method| { @@ -3063,7 +3063,7 @@ class Resolver { self_type, methods, visitor); } - item_trait(type_parameters, methods) { + item_trait(type_parameters, traits, methods) { // Create a new rib for the self type. let self_type_rib = @Rib(NormalRibKind); (*self.type_ribs).push(self_type_rib); @@ -3077,6 +3077,27 @@ class Resolver { self.resolve_type_parameters(type_parameters, visitor); + // Resolve derived traits. + for traits.each |trt| { + match self.resolve_path(trt.path, TypeNS, true, + visitor) { + none => + self.session.span_err(trt.path.span, + ~"attempt to derive a \ + nonexistent trait"), + some(def) => { + // Write a mapping from the trait ID to the + // definition of the trait into the definition + // map. + + debug!{"(resolving trait) found trait def: \ + %?", def}; + + self.record_def(trt.ref_id, def); + } + } + } + for methods.each |method| { // Create a new rib for the method-specific type // parameters. diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index 91caf75f602..65ad1b26a8d 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -419,7 +419,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) { node_id: it.id }; for ms.each |m| { check_method(ccx, m, self_info);} } - ast::item_trait(_, trait_methods) { + ast::item_trait(_, _, trait_methods) { for trait_methods.each |trait_method| { alt trait_method { required(ty_m) { @@ -434,7 +434,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) { } } } - ast::item_class(tps, traits, members, m_ctor, m_dtor) { + ast::item_class(tps, _, members, m_ctor, m_dtor) { let tcx = ccx.tcx; let class_t = {self_ty: ty::node_id_to_type(tcx, it.id), node_id: it.id}; diff --git a/src/rustc/middle/typeck/collect.rs b/src/rustc/middle/typeck/collect.rs index da9575b898e..ae748b541ff 100644 --- a/src/rustc/middle/typeck/collect.rs +++ b/src/rustc/middle/typeck/collect.rs @@ -38,20 +38,19 @@ fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) { let substs = {self_r: none, self_ty: none, tps: ~[]}; alt intrinsic_item.node { - - ast::item_trait(_, _) { + ast::item_trait(*) => { let ty = ty::mk_trait(ccx.tcx, def_id, substs); ccx.tcx.intrinsic_defs.insert (intrinsic_item.ident, (def_id, ty)); } - ast::item_enum(_, _) { + ast::item_enum(*) => { let ty = ty::mk_enum(ccx.tcx, def_id, substs); ccx.tcx.intrinsic_defs.insert (intrinsic_item.ident, (def_id, ty)); } - _ { } + _ => {} } } } @@ -147,7 +146,7 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id) { let tcx = ccx.tcx; let rp = tcx.region_paramd_items.contains_key(id); alt check tcx.items.get(id) { - ast_map::node_item(@{node: ast::item_trait(_, ms), _}, _) { + ast_map::node_item(@{node: ast::item_trait(_, _, ms), _}, _) { store_methods::<ast::trait_method>(ccx, id, ms, |m| { alt m { required(ty_m) { @@ -339,7 +338,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) { check_methods_against_trait(ccx, tps, rp, selfty, t, cms); } } - ast::item_trait(tps, trait_methods) { + ast::item_trait(tps, _, trait_methods) { let tpt = ty_of_item(ccx, it); debug!{"item_trait(it.id=%d, tpt.ty=%s)", it.id, ty_to_str(tcx, tpt.ty)}; @@ -550,7 +549,7 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_trait(tps, ms) { + ast::item_trait(tps, _, ms) { let {bounds, substs} = mk_substs(ccx, tps, rp); let t = ty::mk_trait(tcx, local_def(it.id), substs); let tpt = {bounds: bounds, rp: rp, ty: t}; |
