{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/14844","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/14844/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/14844/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/14844/events","html_url":"https://github.com/rust-lang/rust/issues/14844","id":35577076,"number":14844,"title":"suggest binding site when issuing \"try using a local type parameter instead\" err msg","user":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-diagnostics","name":"A-diagnostics","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-06-12T11:53:41Z","updated_at":"2016-05-25T06:52:24Z","closed_at":null,"body":"Here is some code:\r\n```rust\r\npub trait Bar { fn m(&self); }\r\n\r\npub fn foo<T>() {\r\n    struct S<T>;\r\n    impl Bar for S<T> {\r\n        fn m(&self) { println!(\"Hello World\"); }\r\n    }\r\n    let s = S::<T>;\r\n    s.m();\r\n}\r\n\r\npub fn main() {\r\n    foo::<int>();\r\n}\r\n```\r\n\r\nHere is a transcript of a compilation attempt:\r\n```\r\n% rustc /tmp/bar.rs\r\nerror: can't use type parameters from outer function in the substitution of `foo::S<T>`; try using a local type parameter instead\r\n/tmp/bar.rs:9:7: 9:10 error: type `foo::S<T>` does not implement any method in scope named `m`\r\n/tmp/bar.rs:9     s.m();\r\n                    ^~~\r\nerror: can't use type parameters from outer function in the substitution of `foo::S<T>`; try using a local type parameter instead\r\nerror: can't use type parameters from outer function in the substitution of `fn(&foo::S<T>)`; try using a local type parameter instead\r\nerror: can't use type parameters from outer function in the substitution of `fn(&foo::S<T>)`; try using a local type parameter instead\r\nerror: can't use type parameters from outer function in the substitution of `foo::S<T>`; try using a local type parameter instead\r\nerror: can't use type parameters from outer function in the substitution of `foo::S<T>`; try using a local type parameter instead\r\nerror: can't use type parameters from outer function in the substitution of `foo::S<T>`; try using a local type parameter instead\r\nerror: can't use type parameters from outer function in the substitution of `foo::S<T>`; try using a local type parameter instead\r\nerror: can't use type parameters from outer function in the substitution of `foo::S<T>`; try using a local type parameter instead\r\nerror: can't use type parameters from outer function in the substitution of `foo::S<T>`; try using a local type parameter instead\r\nerror: aborting due to 11 previous errors\r\n% \r\n```\r\n\r\nFirst off, maybe we should be aborting the compilation a little sooner rather than emitting so many seemingly redundant error messages.\r\n\r\nSecond, I was scratching my head for a little while because I was saying to myself \"`T` *is* a local type parameter\".  Of course, it is not local *enough*; one needs to change the `impl Bar for S<T>` to `impl<T> Bar for S<T>`.\r\n\r\nSo, I think it would be good if the error message suggested this; e.g.:\r\n\r\n> error: can't use type parameters from outer function in the substitution of `foo::S<T>`; try adding a local type parameter to the `impl`\r\n\r\nor\r\n\r\n> error: can't use type parameters from outer function in the substitution of `foo::S<T>`; try using a local type parameter like `impl<T> Bar for ...`"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/221488317","html_url":"https://github.com/rust-lang/rust/issues/14844#issuecomment-221488317","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/14844","id":221488317,"user":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"created_at":"2016-05-25T06:52:24Z","updated_at":"2016-05-25T06:52:24Z","body":"Yes the number of errors reported is now reasonable,  but it still leads to head scratching because it doesn't make it clear that one needs a binding on the `impl` block "}}
{"actor":{"display_login":"pnkfelix"}}