1
Fork 0

Comments, minor refactoring, clean up wording of error messages

This commit is contained in:
Lindsey Kuper 2012-08-07 09:45:32 -07:00
parent 2e0c1dbd4f
commit e656261ee7
5 changed files with 33 additions and 21 deletions

View file

@ -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] {

View file

@ -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");
}

View file

@ -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;

View file

@ -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() {}

View file

@ -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
}