rust-lang / rust-lang/rust

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

Open
#123,450 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-associated-items A-coherence A-trait-system C-discussion S-has-mcve T-compiler T-types
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.