Stream: wg-traits

Topic: Associated type normalization

Florian Diebold (Jul 07 2019 at 17:59, on Zulip):

So, we added for loop support in rust-analyzer but it's not having the desired effect, and I'm investigating why. There's something weird going on with the rules for normalization, and I'm not sure whether I'm doing something wrong or there's a bug there.

Basically, written as a Chalk test:

program {
    trait IntoIterator { type Item; }
    trait Iterator { type Item; }
    struct Vec<T> { }
    struct u32 { }
    impl<T> IntoIterator for Vec<T> {
        type Item = T;
    impl<T> IntoIterator for T where T: Iterator {
        type Item = <T as Iterator>::Item;

goal {
    forall<T> {
        exists<U> {
            Normalize(<Vec<T> as IntoIterator>::Item -> U)

I'd expect this to have a unique solution (because the Iterator impl shouldn't matter), but it doesn't currently. The problem as far as I understand it is that the impl<T> IntoIterator for T where T: Iterator results in a rule Normalize(<Vec<T> as IntoIterator>::Item -> <Vec<T> as Iterator>::Item) :- Implemented(Vec<T>: IntoIterator), and then Implemented(Vec<T>: IntoIterator) is of course the case, but because of the other impl. So I don't understand how this is actually supposed to work.

Geoffry Song (Jul 08 2019 at 03:35, on Zulip):

indeed, it seems that the Normalize-From-Impl rule is wrong as written... it only requires that the trait be implemented _at all_, not that the particular impl in question applies

Geoffry Song (Jul 08 2019 at 03:37, on Zulip):

i guess the way to fix it would be to add the bounds of the impl in question to the hypotheses, at which point the Implemented hypothesis wouldn't be needed

Geoffry Song (Jul 08 2019 at 03:39, on Zulip):

it'd be nice to avoid that duplication, but that probably needs impls to be named?

Florian Diebold (Jul 08 2019 at 10:04, on Zulip):

named impls might be useful if they allowed us to find out which impl actually applied? :thinking:

Florian Diebold (Aug 23 2019 at 18:15, on Zulip):

I opened an issue for this and another associated type problem I have:

Last update: Jul 03 2020 at 17:40UTC