Skip to content

Commit 65e0e30

Browse files
committed
Make typeck::collect aware of provided methods in traits.
1 parent 2fe299d commit 65e0e30

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/libsyntax/ast_util.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ fn trait_method_to_ty_method(method: trait_method) -> ty_method {
329329
}
330330
}
331331

332+
fn split_trait_methods(trait_methods: ~[trait_method])
333+
-> (~[ty_method], ~[@method]) {
334+
let mut reqd = ~[], provd = ~[];
335+
for trait_methods.each |trt_method| {
336+
alt trt_method {
337+
required(tm) { vec::push(reqd, tm); }
338+
provided(m) { vec::push(provd, m); }
339+
}
340+
};
341+
(reqd, provd)
342+
}
343+
332344
pure fn class_member_visibility(ci: @class_member) -> visibility {
333345
alt ci.node {
334346
instance_var(_, _, _, _, vis) { vis }

src/rustc/middle/typeck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import syntax::{ast, ast_util, ast_map};
4343
import ast::spanned;
4444
import ast::{required, provided};
4545
import syntax::ast_map::node_id_to_str;
46-
import syntax::ast_util::{local_def, respan, split_class_items};
46+
import syntax::ast_util::{local_def, respan, split_class_items,
47+
split_trait_methods};
4748
import syntax::visit;
4849
import metadata::csearch;
4950
import driver::session::session;

src/rustc/middle/typeck/collect.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,22 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
339339
check_methods_against_trait(ccx, tps, rp, selfty, t, cms);
340340
}
341341
}
342-
ast::item_trait(*) {
342+
ast::item_trait(tps, trait_methods) {
343343
let tpt = ty_of_item(ccx, it);
344344
debug!{"item_trait(it.id=%d, tpt.ty=%s)",
345345
it.id, ty_to_str(tcx, tpt.ty)};
346346
write_ty_to_tcx(tcx, it.id, tpt.ty);
347347
ensure_trait_methods(ccx, it.id);
348+
349+
let (_, provided_methods) = split_trait_methods(trait_methods);
350+
let selfty = ty::mk_self(tcx);
351+
let {bounds, _} = mk_substs(ccx, tps, rp);
352+
let _cms = convert_methods(ccx, provided_methods, rp, bounds, selfty);
353+
// FIXME (#2616): something like this, when we start having
354+
// trait inheritance?
355+
// for trt.each |t| {
356+
// check_methods_against_trait(ccx, tps, rp, selfty, t, cms);
357+
// }
348358
}
349359
ast::item_class(tps, traits, members, m_ctor, m_dtor) {
350360
// Write the class type

0 commit comments

Comments
 (0)