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

Conflicting implementation should not exist after generic trait paramters have been constrained to associated types #123450

Open
ZhennanWu opened this issue Apr 4, 2024 · 0 comments
Labels
A-associated-items Area: Associated items such as associated types and consts. A-coherence Area: Coherence A-traits Area: Trait system C-discussion Category: Discussion or questions that doesn't represent real issues. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@ZhennanWu
Copy link

ZhennanWu commented Apr 4, 2024

Consider this code. Currently it cannot compile.

pub trait Foo {}

pub trait ImplBy {
    type Impl;
}

pub trait FooBy<I> {}

impl<T> Foo for T
where
    T: ImplBy,
    T: FooBy<T::Impl>,
{
}

struct Bar;
impl ImplBy for Bar {
    type Impl = ();
}
impl Foo for Bar {}
// conflicting implementations of trait `Foo` for type `Bar`
// downstream crates may implement trait `FooBy<_>` for type `Bar`

The type solver assumed downstream can impl FooBy<Bar::Impl> for type Bar. But this is easy to reject with orphan rules. Bar::Impl must be in the same scope as Bar itself. Therefore FooBy<Bar::Impl> cannot be implemented on Bar outside its origin crate.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 4, 2024
@jieyouxu jieyouxu added A-traits Area: Trait system T-types Relevant to the types team, which will review and decide on the PR/issue. A-associated-items Area: Associated items such as associated types and consts. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-discussion Category: Discussion or questions that doesn't represent real issues. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 4, 2024
@fmease fmease added the A-coherence Area: Coherence label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items such as associated types and consts. A-coherence Area: Coherence A-traits Area: Trait system C-discussion Category: Discussion or questions that doesn't represent real issues. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants