Change error for out of scope type params to be more helpful.

This commit is contained in:
Kevin Butler 2014-04-16 23:32:00 +01:00
parent 14e1fd4629
commit 52a53e8ae7
9 changed files with 17 additions and 14 deletions

View File

@ -3507,8 +3507,9 @@ impl<'a> Resolver<'a> {
// its scope.
self.resolve_error(span,
"attempt to use a type \
argument out of scope");
"can't use type parameters from \
outer function; try using a local \
type parameter instead");
}
return None;
@ -3530,8 +3531,9 @@ impl<'a> Resolver<'a> {
// its scope.
self.resolve_error(span,
"attempt to use a type \
argument out of scope");
"can't use type parameters from \
outer function; try using a local \
type parameter instead");
}
return None;

View File

@ -95,8 +95,9 @@ impl<'a> TypeFolder for SubstFolder<'a> {
root.repr(self.tcx)),
None => ~""
};
let m = format!("missing type param `{}`{}",
t.repr(self.tcx), root_msg);
let m = format!("can't use type parameters from outer \
function{}; try using a local type \
parameter instead", root_msg);
match self.span {
Some(span) => self.tcx.sess.span_err(span, m),
None => self.tcx.sess.err(m)

View File

@ -9,7 +9,7 @@
// except according to those terms.
fn foo<T>() {
fn bar(b: T) { } //~ ERROR attempt to use a type argument out of scope
fn bar(b: T) { } //~ ERROR can't use type parameters from outer
//~^ ERROR use of undeclared type name
}
fn main() { }

View File

@ -11,8 +11,8 @@
fn siphash<T>() {
trait t {
fn g(&self, x: T) -> T; //~ ERROR attempt to use a type argument out of scope
//~^ ERROR attempt to use a type argument out of scope
fn g(&self, x: T) -> T; //~ ERROR can't use type parameters from outer function; try using
//~^ ERROR can't use type parameters from outer function; try using
//~^^ ERROR use of undeclared type name `T`
//~^^^ ERROR use of undeclared type name `T`
}

View File

@ -10,7 +10,7 @@
fn foo<T>() {
struct foo {
x: T, //~ ERROR attempt to use a type argument out of scope
x: T, //~ ERROR can't use type parameters from outer function;
//~^ ERROR use of undeclared type name
}

View File

@ -10,7 +10,7 @@
fn f<Z>() -> bool {
enum E { V(Z) }
//~^ ERROR missing type param `Z` in the substitution of `Z`
//~^ ERROR can't use type parameters from outer function in the
true
}

View File

@ -10,7 +10,7 @@
fn f<T>() -> bool {
struct S(T); //~ ERROR use of undeclared type name `T`
//~^ ERROR attempt to use a type argument out of scope
//~^ ERROR can't use type parameters from outer function; try using
true
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:attempt to use a type argument out of scope
// error-pattern:can't use type parameters from outer function; try using
fn hd<U>(v: Vec<U> ) -> U {
fn hd1(w: [U]) -> U { return w[0]; }

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:attempt to use a type argument out of scope
// error-pattern:can't use type parameters from outer function; try using
fn foo<T>(x: T) {
fn bar(f: |T| -> T) { }
}