rust-lang / trait-system-refactor-initiative

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

we eagerly normalize Type-outlives bounds #63

Open compiler-errors opened 12 months ago

compiler-errors commented 12 months ago

With https://github.com/rust-lang/rust/pull/119101 and https://github.com/rust-lang/rust/pull/120513 TypeOutlives obligations and assumptions are now eagerly normalized at the start of regionck and borrowck.

previous issue

Type-outlives bounds can be proven several ways -- via item bounds, via param-env clauses, and by recursively applying to the type's components. When applying param-env clauses that may satisfy a type-outlives bounds, we use the Match relation, which only considers types structurally.

That causes this code to go from passing to failing in the new trait solver:

trait Mirror {
    type Assoc;
}
impl<T> Mirror for T {
    type Assoc = T;
}

fn is_static<T: 'static>() {}

fn test<T>() where <T as Mirror>::Assoc: 'static {
    is_static::<T>();
}
compiler-errors commented 12 months ago

The current trait solver avoids this by normalizing the param-env, so the bound in test above becomes where T: 'static.

compiler-errors commented 7 months ago

This is not fixed by rust-lang/rust#119101, MIR borrowck doesn't normalize type-outlives yet. That will happen soon.