Skip to content

Commit 52a53e8

Browse files
committed
Change error for out of scope type params to be more helpful.
1 parent 14e1fd4 commit 52a53e8

9 files changed

+17
-14
lines changed

src/librustc/middle/resolve.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3507,8 +3507,9 @@ impl<'a> Resolver<'a> {
35073507
// its scope.
35083508

35093509
self.resolve_error(span,
3510-
"attempt to use a type \
3511-
argument out of scope");
3510+
"can't use type parameters from \
3511+
outer function; try using a local \
3512+
type parameter instead");
35123513
}
35133514

35143515
return None;
@@ -3530,8 +3531,9 @@ impl<'a> Resolver<'a> {
35303531
// its scope.
35313532

35323533
self.resolve_error(span,
3533-
"attempt to use a type \
3534-
argument out of scope");
3534+
"can't use type parameters from \
3535+
outer function; try using a local \
3536+
type parameter instead");
35353537
}
35363538

35373539
return None;

src/librustc/middle/subst.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ impl<'a> TypeFolder for SubstFolder<'a> {
9595
root.repr(self.tcx)),
9696
None => ~""
9797
};
98-
let m = format!("missing type param `{}`{}",
99-
t.repr(self.tcx), root_msg);
98+
let m = format!("can't use type parameters from outer \
99+
function{}; try using a local type \
100+
parameter instead", root_msg);
100101
match self.span {
101102
Some(span) => self.tcx.sess.span_err(span, m),
102103
None => self.tcx.sess.err(m)

src/test/compile-fail/bad-type-env-capture.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
fn foo<T>() {
12-
fn bar(b: T) { } //~ ERROR attempt to use a type argument out of scope
12+
fn bar(b: T) { } //~ ERROR can't use type parameters from outer
1313
//~^ ERROR use of undeclared type name
1414
}
1515
fn main() { }

src/test/compile-fail/issue-3021-c.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
fn siphash<T>() {
1212

1313
trait t {
14-
fn g(&self, x: T) -> T; //~ ERROR attempt to use a type argument out of scope
15-
//~^ ERROR attempt to use a type argument out of scope
14+
fn g(&self, x: T) -> T; //~ ERROR can't use type parameters from outer function; try using
15+
//~^ ERROR can't use type parameters from outer function; try using
1616
//~^^ ERROR use of undeclared type name `T`
1717
//~^^^ ERROR use of undeclared type name `T`
1818
}

src/test/compile-fail/issue-3214.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

src/test/compile-fail/issue-5997-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
fn f<Z>() -> bool {
1212
enum E { V(Z) }
13-
//~^ ERROR missing type param `Z` in the substitution of `Z`
13+
//~^ ERROR can't use type parameters from outer function in the
1414

1515
true
1616
}

src/test/compile-fail/issue-5997-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
fn f<T>() -> bool {
1212
struct S(T); //~ ERROR use of undeclared type name `T`
13-
//~^ ERROR attempt to use a type argument out of scope
13+
//~^ ERROR can't use type parameters from outer function; try using
1414

1515
true
1616
}

src/test/compile-fail/nested-ty-params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:attempt to use a type argument out of scope
11+
// error-pattern:can't use type parameters from outer function; try using
1212
fn hd<U>(v: Vec<U> ) -> U {
1313
fn hd1(w: [U]) -> U { return w[0]; }
1414

src/test/compile-fail/type-arg-out-of-scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:attempt to use a type argument out of scope
11+
// error-pattern:can't use type parameters from outer function; try using
1212
fn foo<T>(x: T) {
1313
fn bar(f: |T| -> T) { }
1414
}

0 commit comments

Comments
 (0)