Skip to content

Commit 0f1adf4

Browse files
An associated type is not a projection!
More correctly, a `TyKind::AssociatedType` is not the same as `TyKind::Projection`. We used to map next-solver `TyKind::Alias` to Chalk's `TyKind::AssociatedType`. This is very incorrect, as `AssociatedType` is assumed to be fully normalized, and caused a lot of type mismatches. Unfortunately fixing this causes a lot of stack overflows, because the next solver doesn't have something akin to `AssociatedType` so we normalize again and again. The reason is that is the lazy-normalization nature of the next solver, which means we need to stop normalizing everything. This will be fixed in the next commit.
1 parent 412932e commit 0f1adf4

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

crates/hir-ty/src/next_solver/mapping.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,10 @@ pub(crate) fn convert_ty_for_result<'db>(interner: DbInterner<'db>, ty: Ty<'db>)
13581358
};
13591359
let associated_ty_id = to_assoc_type_id(assoc_ty_id);
13601360
let substitution = convert_args_for_result(interner, alias_ty.args.as_slice());
1361-
TyKind::AssociatedType(associated_ty_id, substitution)
1361+
TyKind::Alias(crate::AliasTy::Projection(crate::ProjectionTy {
1362+
associated_ty_id,
1363+
substitution,
1364+
}))
13621365
}
13631366
rustc_type_ir::AliasTyKind::Opaque => {
13641367
let opaque_ty_id = match alias_ty.def_id {

crates/hir-ty/src/tests/regression/new_solver.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,30 @@ fn main() {
7171
}"#,
7272
);
7373
}
74+
75+
#[test]
76+
fn projection_is_not_associated_type() {
77+
check_no_mismatches(
78+
r#"
79+
//- minicore: fn
80+
trait Iterator {
81+
type Item;
82+
83+
fn partition<F>(self, f: F)
84+
where
85+
F: FnMut(&Self::Item) -> bool,
86+
{
87+
}
88+
}
89+
90+
struct Iter;
91+
impl Iterator for Iter {
92+
type Item = i32;
93+
}
94+
95+
fn main() {
96+
Iter.partition(|n| true);
97+
}
98+
"#,
99+
);
100+
}

0 commit comments

Comments
 (0)