Conflicting implementation should not exist after generic trait paramters have been constrained to associated types
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the minimized Rust example in the issue and inspect how the type solver applies orphan rules to the associated type constraint. Trace the relevant compiler handling for overlapping implementations; done means the explicit Foo implementation for Bar is no longer rejected as conflicting when the downstream implementation is impossible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100