Conflicting implementation should not exist after generic trait paramters have been constrained to associated types #123450
Open
Description
opened on 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.
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: CoherenceArea: Trait systemCategory: Discussion or questions that doesn't represent real issues.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Activity