diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 119f4465d9e..58650e147cc 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -329,6 +329,18 @@ fn trait_method_to_ty_method(method: trait_method) -> ty_method { } } +fn split_trait_methods(trait_methods: ~[trait_method]) + -> (~[ty_method], ~[@method]) { + let mut reqd = ~[], provd = ~[]; + for trait_methods.each |trt_method| { + alt trt_method { + required(tm) { vec::push(reqd, tm); } + provided(m) { vec::push(provd, m); } + } + }; + (reqd, provd) +} + pure fn class_member_visibility(ci: @class_member) -> visibility { alt ci.node { instance_var(_, _, _, _, vis) { vis } diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index adc47d5fad4..910d57e875e 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -43,7 +43,8 @@ import syntax::{ast, ast_util, ast_map}; import ast::spanned; import ast::{required, provided}; import syntax::ast_map::node_id_to_str; -import syntax::ast_util::{local_def, respan, split_class_items}; +import syntax::ast_util::{local_def, respan, split_class_items, + split_trait_methods}; import syntax::visit; import metadata::csearch; import driver::session::session; diff --git a/src/rustc/middle/typeck/collect.rs b/src/rustc/middle/typeck/collect.rs index aab71d1b72b..da9575b898e 100644 --- a/src/rustc/middle/typeck/collect.rs +++ b/src/rustc/middle/typeck/collect.rs @@ -339,12 +339,22 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) { check_methods_against_trait(ccx, tps, rp, selfty, t, cms); } } - ast::item_trait(*) { + 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)}; write_ty_to_tcx(tcx, it.id, tpt.ty); ensure_trait_methods(ccx, it.id); + + let (_, provided_methods) = split_trait_methods(trait_methods); + let selfty = ty::mk_self(tcx); + let {bounds, _} = mk_substs(ccx, tps, rp); + let _cms = convert_methods(ccx, provided_methods, rp, bounds, selfty); + // FIXME (#2616): something like this, when we start having + // trait inheritance? + // for trt.each |t| { + // check_methods_against_trait(ccx, tps, rp, selfty, t, cms); + // } } ast::item_class(tps, traits, members, m_ctor, m_dtor) { // Write the class type