rust-lang / trait-system-refactor-initiative

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

higher-ranked goals in trait goal candidate selection #120

Open lcnr opened 2 months ago

lcnr commented 2 months ago

This compiles with the old solver but currently fails with next:

trait Leak<'a> {}
impl Leak<'_> for Box<u32> {}
impl Leak<'static> for Box<u16> {}

fn impls_leak<T: for<'a> Leak<'a>>() {}
fn direct() {
    // The `Box<u16>` impls fails the leak check,
    // meaning that we apply the `Box<u32>` impl.
    impls_leak::<Box<_>>();
    //[next]~^ ERROR type annotations needed
}

cc https://github.com/rust-lang/rust/issues/119820 which got reverted in https://github.com/rust-lang/rust/pull/127568

We originally intended to never consider the placeholders from higher ranked goals while computing their candidates. However, this resulted in some undesirable breakage and we'll instead have to support this with the next solver before stabilization.

I currently hope to support this by adding OR region bounds and removing ParamEnv preference by returning guidance instead, discussed in https://hackmd.io/-IMJ8e0iTBqvL6X1XuiRdw#Leak-check