about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLindsey Kuper <lindsey@rockstargirl.org>2012-08-02 15:52:30 -0700
committerLindsey Kuper <lindsey@rockstargirl.org>2012-08-02 17:15:36 -0700
commit65e0e30e59351aed899adbb20cbd07ae98f213d3 (patch)
tree5bb12d679c68a9f9ab2ac2df52aab2a38c6a3dfd /src
parent2fe299d1a53355c9bb78b9067bd2d18bd4eb94e7 (diff)
downloadrust-65e0e30e59351aed899adbb20cbd07ae98f213d3.tar.gz
rust-65e0e30e59351aed899adbb20cbd07ae98f213d3.zip
Make typeck::collect aware of provided methods in traits.
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/ast_util.rs12
-rw-r--r--src/rustc/middle/typeck.rs3
-rw-r--r--src/rustc/middle/typeck/collect.rs12
3 files changed, 25 insertions, 2 deletions
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