chalk icon indicating copy to clipboard operation
chalk copied to clipboard

Unable to deduce projection types of dyn types from supertrait bounds

Open lowr opened this issue 3 years ago • 0 comments

Context: https://github.com/rust-lang/rust-analyzer/issues/13169

It seems chalk is unable to deduce projection type of trait object types when it's not specified in dyn notation but the trait has supertrait with its projection type specified.

I expect the following tests to succeed but all three fail. This is because according to the rules described in #203, chalk yields AliasEq(<dyn Trait as Base>::Output = usize) as a subgoal but there's no "fact" clause for that to prove it. Shouldn't the AliasEq clause be also produced as a fact under these circumstances, or should we explicitly pass the AliasEq clause?

test! {
    program {
        trait Base { type Output; }
        trait Trait where Self: Base<Output = usize> {}
    }

    goal {
        forall<'s> {
            dyn Trait + 's: Trait
        }
    } yields[SolverChoice::recursive_default()] {
        expect![[r#"Unique"#]] // fails: "No possible solution"
    }

    goal {
        forall<'s> {
            dyn Trait + 's: Base<Output = usize>
        }
    } yields[SolverChoice::recursive_default()] {
        expect![[r#"Unique"#]] // fails: "No possible solution"
    }

    goal {
        forall<'s> {
            exists<T> {
                dyn Trait + 's: Base<Output = T>
            }
        }
    } yields[SolverChoice::recursive_default()] {
        // fails: "Unique; substitution [?0 := (Base::Output)<dyn for<type> [for<> Implemented(^1.0: Trait)] + '!1_0>]"
        expect![[r#"Unique; substitution [?0 := Uint(Usize)]"#]]
    }
}

lowr avatar Sep 09 '22 09:09 lowr