Auto merge of #47574 - zilbuz:issue-14844, r=nikomatsakis

Show the used type variable when issuing a "can't use type parameters from outer function" error message

Fix #14844

r? @estebank
This commit is contained in:
bors 2018-03-10 10:52:07 +00:00
commit 87344aa59a
13 changed files with 309 additions and 43 deletions

View file

@ -8,11 +8,33 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Baz<T> {}
fn foo<T>(x: T) {
fn bar(y: T) { //~ ERROR E0401
fn bar<U, V: Baz<U>, W: Fn()>(y: T) { //~ ERROR E0401
}
fn baz<U,
V: Baz<U>,
W: Fn()>
(y: T) { //~ ERROR E0401
}
bar(x);
}
struct A<T> {
inner: T,
}
impl<T> Iterator for A<T> {
type Item = u8;
fn next(&mut self) -> Option<u8> {
fn helper(sel: &Self) -> u8 { //~ ERROR E0401
unimplemented!();
}
Some(helper(self))
}
}
fn main() {
}

View file

@ -1,9 +1,35 @@
error[E0401]: can't use type parameters from outer function; try using a local type parameter instead
--> $DIR/E0401.rs:12:15
error[E0401]: can't use type parameters from outer function
--> $DIR/E0401.rs:14:38
|
LL | fn bar(y: T) { //~ ERROR E0401
| ^ use of type variable from outer function
LL | fn foo<T>(x: T) {
| - type variable from outer function
LL | fn bar<U, V: Baz<U>, W: Fn()>(y: T) { //~ ERROR E0401
| -------------------------- ^ use of type variable from outer function
| |
| help: try using a local type parameter instead: `bar<U, V: Baz<U>, W: Fn(), T>`
error: aborting due to previous error
error[E0401]: can't use type parameters from outer function
--> $DIR/E0401.rs:19:16
|
LL | fn foo<T>(x: T) {
| - type variable from outer function
...
LL | (y: T) { //~ ERROR E0401
| ^ use of type variable from outer function
|
= help: try using a local type parameter instead
error[E0401]: can't use type parameters from outer function
--> $DIR/E0401.rs:32:25
|
LL | impl<T> Iterator for A<T> {
| ---- `Self` type implicitely declared here, on the `impl`
...
LL | fn helper(sel: &Self) -> u8 { //~ ERROR E0401
| ------ ^^^^ use of type variable from outer function
| |
| help: try using a local type parameter instead: `helper<Self>`
error: aborting due to 3 previous errors
If you want more information on this error, try using "rustc --explain E0401"