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

Can't implement From or Into for custom wrapper type #49817

Closed
clarfonthey opened this issue Apr 9, 2018 · 4 comments
Closed

Can't implement From or Into for custom wrapper type #49817

clarfonthey opened this issue Apr 9, 2018 · 4 comments
Labels
C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Apr 9, 2018

This won't work:

pub struct Wrapper<T>(T);
impl<T> From<Wrapper<T>> for T {
    fn from(val: Wrapper<T>) -> T { val.0 }
}

and neither will:

pub struct Wrapper<T>(T);
impl<T> Into<T> for Wrapper<T> {
    fn into(self) -> T { self.0 }
}

In previous (post-1.0) versions of the compiler, the latter was able to be implemented, however, now it's seen as conflicting with impl<T, U> Into<U> for T where U: From<T>, which is definitely the correct behaviour.

But right now, not being able to implement From for this case seems very much to me like a bug.

@clarfonthey clarfonthey changed the title Can't implement From or Into for custom type Can't implement From or Into for custom wrapper type Apr 9, 2018
@durka
Copy link
Contributor

durka commented Apr 9, 2018

Do you happen to know which version(s)? They both fail in 1.0: https://godbolt.org/g/Cay61k

The coherence issue with implementing From is that a downstream crate might want to implement From<Wrapper<TheirType>> for TheirType and they get priority.

@Mark-Simulacrum Mark-Simulacrum added T-lang Relevant to the language team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 29, 2018
@clarfonthey
Copy link
Contributor Author

This should be fixed by #55437.

@leesongun
Copy link

It is still subject to the rule

  1. No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)

and both doesn't work. (playground link)

@clarfonthey
Copy link
Contributor Author

Right, I closed it but for the wrong reason. It's still not okay with the inference rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants