rust-lang / trait-system-refactor-initiative

The Rustc Trait System Refactor Initiative
21 stars 0 forks source link

inductive cycles as ambig causes unintended breakage #114

Open lcnr opened 5 months ago

lcnr commented 5 months ago
trait Trait {
    type Item;
}

fn foo<A: Trait, B: Trait>()
where
    A::Item: Trait<Item = u32>,
    B::Item: Trait<Item = i32>,
{}

this should compile but fails with

error[E0283]: type annotations needed: cannot satisfy `<A as Trait>::Item: Trait`
 --> <source>:7:14
  |
7 |     A::Item: Trait<Item = u32>,
  |              ^^^^^^^^^^^^^^^^^
  |

The underlying issue is trying to prove <A as Trait>::Item: Trait normalizes the self type:

lcnr commented 5 months ago

original test by @aliemjay :heart:

pub trait ParallelIterator {
    type Item;
}

impl<T> ParallelIterator for T {
    type Item = u32;
}

trait Trait {}

impl<A, B> Trait for (A, B) where
    //~^ type annotations needed: cannot satisfy `<<A as ParallelIterator>::Item as ParallelIterator>::Item == u32`
    A: ParallelIterator,
    A::Item: ParallelIterator<Item = u32>,
    B: ParallelIterator,
    B::Item: ParallelIterator<Item = u32>,
{}

fn main() {}
lcnr commented 5 months ago

this is the underlying reason for https://github.com/rust-lang/trait-system-refactor-initiative/issues/111, closing that issue

trait Trait<'a> {
    type Assoc;
}

fn foo<'a, T: Trait<'a>>()
where
    T::Assoc: Trait<'a>,
{}

this may also be the root cause of https://github.com/rust-lang/trait-system-refactor-initiative/issues/89