The move to universes in rustc

Tracking issue

The universes PR 

Leak check

The pre-universes leak check was “conservative” in potentially a few ways:
  • It ignores direction of subtyping when performing the check
  • The check is forced to occur “eagerly” in some sense, due to limitations of the infrastructure. So it could fail in cases where, due to later inference, it could’ve succeeded
  • There are certain cases where 'static will not be inferred

We pretty clearly don’t want to keep the leak check long-term, but do want to find a way to “ease into” a better approach.

57639


trait Foo<'a> {}

trait Bar {
    type Item: for<'a> Foo<'a>;
}

fn foo<'a, T>(_: T)
where
    T: Bar,
    T::Item: Foo<'a>
{}

Compiles on stable, not on nightly

The where clause ends up effectively “shadowing” the associated type bound because we greedily commit to the first way of solving an obligation (up to region constraints, which are handled later)

aturon: I don’t recall exactly how this relates to the universe change

46989 and coherence


trait Foo {}
impl<Ret, A> Foo for fn(A) -> Ret {}
impl<Ret, A> Foo for for<'a> fn(&'a A) -> Ret {}

Compiles on  stable, not on nightly

With the universes change, it becomes impossible to set up a trait that is implemented for both an HRTB type and all ground instances of it. They are considered overlapping as impls, yet neither implies the other (currently), so you’re forced to choose.

If for<'a> fn(&'a u8) is equivalent to fn(&'empty u8) then there should be an implication.

General questions

Are we comfortable with the following equations?