rust-lang / trait-system-refactor-initiative

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

should looking up the defined opaque types be structural or semantic #17

Open lcnr opened 1 year ago

lcnr commented 1 year ago

a purely structural lookup is difficult to support in MIR typeck because we replace all regions with new variables.

a semantic lookup requires some special care to correctly handle universes. It also breaks the following example

trait Trait<'a, 'b> {}
impl<'a, 'b, T> Trait<'a, 'b> for T {}

#[derive(Copy, Clone)]
struct Inv<'a>(*mut &'a ());

fn foo<'a, 'b>(x: Inv<'a>, y: Inv<'b>, b: bool) -> impl Trait<'a, 'b> {
    if b {
        let _: Inv<'b> = foo(y, x, false);
    }

    x
}
lcnr commented 1 year ago

if we uniquify regions the lookup will have to be semantic