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

Impls discriminating on associated types do not cause rustc consider them separate #36432

Closed
nagisa opened this issue Sep 12, 2016 · 1 comment

Comments

@nagisa
Copy link
Member

nagisa commented Sep 12, 2016

Consider code like this:

impl<C> fmt::Display for Stuff<C>
where C: SomeTrait<Type=()>
{
    fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        panic!()
    }
}

impl<C> fmt::Display for Stuff<C>
where C: SomeTrait<Type=Vec<C>>
{
    fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        panic!()
    }
}

Play here

It is obvious, that C cannot in any way implement the same trait so the associated Type is both () and Vec<C> at the same time. The compiler should be able to infer that these trait implementations are completely independent. Alas, in the current nightly you get something like

error[E0119]: conflicting implementations of trait `std::fmt::Display` for type `Stuff<_>`:
  --> <anon>:24:1
   |
15 | impl<C> ::std::fmt::Display for Stuff<C>
   | - first implementation here
...
24 | impl<C> ::std::fmt::Display for Stuff<C>
   | ^ conflicting implementation for `Stuff<_>`

instead.

cc @nikomatsakis @eddyb

@nagisa
Copy link
Member Author

nagisa commented Sep 12, 2016

Seems to be rust-lang/rfcs#1672

@nagisa nagisa closed this as completed Sep 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant