chalk icon indicating copy to clipboard operation
chalk copied to clipboard

Change order of implicit type parameters

Open tmandry opened this issue 7 years ago • 0 comments

Implicit type parameters (like Self and others from the env) are put into a lowered item after the explicit type parameters, which is surprising.

For example, the following test fails:

program {
    trait Combine { type Item<T>; }
    struct u32 { }
    struct i32 { }
    struct Either<T, U> { }
    impl Combine for u32 { type Item<U> = Either<u32, U>; }
    impl Combine for i32 { type Item<U> = Either<i32, U>; }
}

goal {
    exists<T, U> {
        T: Combine<Item<U> = Either<u32, i32>>
    }
} yields {
    "Unique; substitution [?0 := u32, ?1 := i32]"
}

Instead of the expected result, we get [?0 := i32, ?1 := u32], which is technically correct because our GAT parameter U is mapped to ?0 and T is mapped to ?1. But there's no way to see this from the output of chalk.

See for example: https://github.com/rust-lang-nursery/chalk/blob/94a1941a021842a5fcb35cd043145c8faae59f08/src/ir/lowering.rs#L183-L185

This will probably have to be changed in a bunch of places.

tmandry avatar May 14 '18 16:05 tmandry