about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLindsey Kuper <lindsey@rockstargirl.org>2012-08-07 09:45:32 -0700
committerLindsey Kuper <lindsey@rockstargirl.org>2012-08-07 10:29:19 -0700
commite656261ee7ff7cfd301c0d7c31cdc969e3bdbfeb (patch)
tree2ff5c5eda8c14d7311528d2f5f4a3ab33e23c408 /src
parent2e0c1dbd4f281a8451c1e9f276ff088d9be15977 (diff)
downloadrust-e656261ee7ff7cfd301c0d7c31cdc969e3bdbfeb.tar.gz
rust-e656261ee7ff7cfd301c0d7c31cdc969e3bdbfeb.zip
Comments, minor refactoring, clean up wording of error messages
Diffstat (limited to 'src')
-rw-r--r--src/rustc/middle/ty.rs21
-rw-r--r--src/rustc/middle/typeck/check/method.rs27
-rw-r--r--src/test/compile-fail/private-method.rs2
-rw-r--r--src/test/compile-fail/selftype-traittype.rs2
-rw-r--r--src/test/compile-fail/trait-test-2.rs2
5 files changed, 33 insertions, 21 deletions
diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs
index 60461db08c4..5c22e155828 100644
--- a/src/rustc/middle/ty.rs
+++ b/src/rustc/middle/ty.rs
@@ -2654,14 +2654,21 @@ fn store_trait_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) {
 
 fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
     match cx.trait_method_cache.find(id) {
-      some(ms) => return ms,
-      _ => ()
+      // Local traits are supposed to have been added explicitly.
+      some(ms) => ms,
+      _ => {
+        // If the lookup in trait_method_cache fails, assume that the trait
+        // method we're trying to look up is in a different crate, and look
+        // for it there.
+        assert id.crate != ast::local_crate;
+        let result = csearch::get_trait_methods(cx, id);
+
+        // Store the trait method in the local trait_method_cache so that
+        // future lookups succeed.
+        cx.trait_method_cache.insert(id, result);
+        result
+      }
     }
-    // Local traits are supposed to have been added explicitly.
-    assert id.crate != ast::local_crate;
-    let result = csearch::get_trait_methods(cx, id);
-    cx.trait_method_cache.insert(id, result);
-    result
 }
 
 fn impl_traits(cx: ctxt, id: ast::def_id) -> ~[t] {
diff --git a/src/rustc/middle/typeck/check/method.rs b/src/rustc/middle/typeck/check/method.rs
index 442920a0681..7347a9dc601 100644
--- a/src/rustc/middle/typeck/check/method.rs
+++ b/src/rustc/middle/typeck/check/method.rs
@@ -57,13 +57,16 @@ class lookup {
     let include_private: bool;
 
     new(fcx: @fn_ctxt,
-        expr: @ast::expr,           //expr for a.b in a.b()
-        self_expr: @ast::expr,      //a in a.b(...)
-        borrow_lb: ast::node_id, //scope to borrow the expr for
-        node_id: ast::node_id,      //node id where to store type of fn
-        m_name: ast::ident,         //b in a.b(...)
-        self_ty: ty::t,             //type of a in a.b(...)
-        supplied_tps: ~[ty::t],      //Xs in a.b::<Xs>(...)
+
+        // In a call `a.b::<X, Y, ...>(...)`:
+        expr: @ast::expr,        // The expression `a.b`.
+        self_expr: @ast::expr,   // The expression `a`.
+        borrow_lb: ast::node_id, // Scope to borrow the expression `a` for.
+        node_id: ast::node_id,   // The node_id in which to store the type of
+                                 // `a.b`.
+        m_name: ast::ident,      // The ident `b`.
+        self_ty: ty::t,          // The type of `a`.
+        supplied_tps: ~[ty::t],  // The list of types X, Y, ... .
         include_private: bool) {
 
         self.fcx = fcx;
@@ -87,6 +90,8 @@ class lookup {
                ty::get(self.self_ty).struct};
 
         // Determine if there are any inherent methods we can call.
+        // (An inherent method is one that belongs to no trait, but is
+        // inherent to a class or impl.)
         let optional_inherent_methods;
         match get_base_type_def_id(self.fcx.infcx,
                                  self.self_expr.span,
@@ -281,14 +286,14 @@ class lookup {
             if ty::type_has_self(m_fty) {
                 self.tcx().sess.span_err(
                     self.expr.span,
-                    ~"can not call a method that contains a \
-                     self type through a boxed trait");
+                    ~"cannot call a method whose type contains a \
+                     self-type through a boxed trait");
             }
 
             if (*m.tps).len() > 0u {
                 self.tcx().sess.span_err(
                     self.expr.span,
-                    ~"can not call a generic method through a \
+                    ~"cannot call a generic method through a \
                      boxed trait");
             }
 
@@ -315,7 +320,7 @@ class lookup {
             if m.vis == ast::private && !self.include_private {
                 self.tcx().sess.span_fatal(
                     self.expr.span,
-                    ~"Call to private method not allowed outside \
+                    ~"call to private method not allowed outside \
                      its defining class");
             }
 
diff --git a/src/test/compile-fail/private-method.rs b/src/test/compile-fail/private-method.rs
index 1a2fd1a6eb1..f59e583f9b9 100644
--- a/src/test/compile-fail/private-method.rs
+++ b/src/test/compile-fail/private-method.rs
@@ -1,4 +1,4 @@
-// error-pattern:Call to private method not allowed
+// error-pattern:call to private method not allowed
 class cat {
   priv {
     let mut meows : uint;
diff --git a/src/test/compile-fail/selftype-traittype.rs b/src/test/compile-fail/selftype-traittype.rs
index 09fc12fda1e..cccc78b04b9 100644
--- a/src/test/compile-fail/selftype-traittype.rs
+++ b/src/test/compile-fail/selftype-traittype.rs
@@ -3,7 +3,7 @@ trait add {
 }
 
 fn do_add(x: add, y: add) -> add {
-    x.plus(y) //~ ERROR can not call a method that contains a self type through a boxed trait
+    x.plus(y) //~ ERROR cannot call a method whose type contains a self-type through a boxed trait
 }
 
 fn main() {}
diff --git a/src/test/compile-fail/trait-test-2.rs b/src/test/compile-fail/trait-test-2.rs
index b53f1972b72..f822aa15380 100644
--- a/src/test/compile-fail/trait-test-2.rs
+++ b/src/test/compile-fail/trait-test-2.rs
@@ -5,5 +5,5 @@ impl of bar for uint { fn dup() -> uint { self } fn blah<X>() {} }
 fn main() {
     10.dup::<int>(); //~ ERROR does not take type parameters
     10.blah::<int, int>(); //~ ERROR incorrect number of type parameters
-    (10 as bar).dup(); //~ ERROR contains a self type
+    (10 as bar).dup(); //~ ERROR contains a self-type
 }