Skip to content

Commit 019ec37

Browse files
committed
Fix projection substitution order considering GATs
1 parent 808257c commit 019ec37

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

chalk-solve/src/clauses.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,14 @@ fn push_alias_alias_eq_clause<I: Interner>(
820820
// <<X as Y>::A as Z>::B == U :- <T as Z>::B == U, <X as Y>::A == T
821821
// }
822822
builder.push_binders(binders, |builder, bound_var| {
823+
let (_, trait_args, assoc_args) = builder.db.split_projection(&projection_ty);
823824
let fresh_self_subst = Substitution::from_iter(
824825
interner,
825-
std::iter::once(bound_var.clone().cast(interner)).chain(
826-
projection_ty.substitution.as_slice(interner)[1..]
827-
.iter()
828-
.cloned(),
829-
),
826+
assoc_args
827+
.iter()
828+
.cloned()
829+
.chain(std::iter::once(bound_var.clone().cast(interner)))
830+
.chain(trait_args[1..].iter().cloned()),
830831
);
831832
let fresh_alias = AliasTy::Projection(ProjectionTy {
832833
associated_ty_id: projection_ty.associated_ty_id,

tests/test/projection.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,30 @@ fn normalize_gat_with_higher_ranked_trait_bound() {
609609
}
610610
}
611611

612+
#[test]
613+
fn gat_in_alias_in_alias_eq() {
614+
test! {
615+
program {
616+
trait Foo {
617+
type Rebind<U>: Foo;
618+
}
619+
620+
struct S<T> { }
621+
impl<T> Foo for S<T> {
622+
type Rebind<U> = S<U>;
623+
}
624+
}
625+
626+
goal {
627+
exists<T> {
628+
<<S<u32> as Foo>::Rebind<i32> as Foo>::Rebind<usize>: Foo
629+
}
630+
} yields {
631+
expect![[r#"Unique"#]]
632+
}
633+
}
634+
}
635+
612636
#[test]
613637
fn forall_projection() {
614638
test! {

0 commit comments

Comments
 (0)