Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error message when trying to implement From<GenericLocalType<T>> for Option<T> #65247

Closed
repnop opened this issue Oct 9, 2019 · 3 comments · Fixed by #66253
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@repnop
Copy link
Contributor

repnop commented Oct 9, 2019

I have a local type:

#[derive(Debug, Deserialize)]
#[serde(untagged)]
enum BadOption<T> {
    Some(T),
    None(Value),
}

and I want to impl<T> From<BadOption<T>> for Option<T> but the error message suggests that T isn't being used as the type parameter for a local type

type parameter T must be used as the type parameter for some local type

Reproduction: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9abd2ab4860140be2859d4767fc027f8

Full error:

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
  --> src/main.rs:11:1
   |
11 | impl<T> From<BadOption<T>> for Option<T> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
   |
   = note: only traits defined in the current crate can be implemented for a type parameter
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 9, 2019
@estebank
Copy link
Contributor

estebank commented Nov 8, 2019

Current output:

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
  --> src/main.rs:11:6
   |
11 | impl<T> From<BadOption<T>> for Option<T> {
   |      ^ type parameter `T` must be used as the type parameter for some local type
   |
   = note: only traits defined in the current crate can be implemented for a type parameter

@Aaron1011
Copy link
Member

This is fixed by #![feature(re_rebalance_coherence)], which is getting stabilized

@spunit262
Copy link
Contributor

Minimal example that still error with #![feature(re_rebalance_coherence)]

The error message needs to tell the user that the order the types are listed in is important. Maybe some thing like "A local type must appear before type parameters". And change it to "uncovered type parameters" if re_rebalance_coherence is on (Option covers T in OP's example which is why it works under re_rebalance_coherence)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants