Skip to content

Commit 51f7f79

Browse files
authored
Merge pull request #20537 from ChayimFriedman2/new-solver-normalize
fix: Normalize all types when finishing inference
2 parents 870cb33 + fd77af3 commit 51f7f79

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

crates/hir-ty/src/infer/unify.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,9 @@ impl<'a> InferenceTable<'a> {
621621
where
622622
T: HasInterner<Interner = Interner> + TypeFoldable<Interner>,
623623
{
624+
let t = self.resolve_with_fallback(t, &|_, _, d, _| d);
625+
let t = self.normalize_associated_types_in(t);
626+
// Resolve again, because maybe normalization inserted infer vars.
624627
self.resolve_with_fallback(t, &|_, _, d, _| d)
625628
}
626629

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,14 +808,24 @@ impl<'db> ChalkToNextSolver<'db, PredicateKind<'db>> for chalk_ir::DomainGoal<In
808808
_ => unimplemented!(),
809809
};
810810
let args: GenericArgs<'db> = proj_ty.substitution.to_nextsolver(interner);
811-
let alias = rustc_type_ir::AliasTerm::new(
811+
let alias = Ty::new(
812812
interner,
813-
from_assoc_type_id(proj_ty.associated_ty_id).into(),
814-
args,
815-
);
813+
rustc_type_ir::TyKind::Alias(
814+
rustc_type_ir::AliasTyKind::Projection,
815+
rustc_type_ir::AliasTy::new(
816+
interner,
817+
from_assoc_type_id(proj_ty.associated_ty_id).into(),
818+
args,
819+
),
820+
),
821+
)
822+
.into();
816823
let term = normalize.ty.to_nextsolver(interner).into();
817-
let normalizes_to = rustc_type_ir::NormalizesTo { alias, term };
818-
PredicateKind::NormalizesTo(normalizes_to)
824+
PredicateKind::AliasRelate(
825+
alias,
826+
term,
827+
rustc_type_ir::AliasRelationDirection::Equate,
828+
)
819829
}
820830
chalk_ir::DomainGoal::WellFormed(well_formed) => {
821831
let term = match well_formed {

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,29 @@ impl<'a> IntoIterator for &'a Grid {
2424
"#]],
2525
);
2626
}
27+
28+
#[test]
29+
fn normalization() {
30+
check_infer(
31+
r#"
32+
//- minicore: iterator, iterators
33+
fn main() {
34+
_ = [0i32].into_iter().filter_map(|_n| Some(1i32));
35+
}
36+
"#,
37+
expect![[r#"
38+
10..69 '{ ...2)); }': ()
39+
16..17 '_': FilterMap<IntoIter<i32, 1>, impl FnMut(i32) -> Option<i32>>
40+
16..66 '_ = [0...1i32))': ()
41+
20..26 '[0i32]': [i32; 1]
42+
20..38 '[0i32]...iter()': IntoIter<i32, 1>
43+
20..66 '[0i32]...1i32))': FilterMap<IntoIter<i32, 1>, impl FnMut(i32) -> Option<i32>>
44+
21..25 '0i32': i32
45+
50..65 '|_n| Some(1i32)': impl FnMut(i32) -> Option<i32>
46+
51..53 '_n': i32
47+
55..59 'Some': fn Some<i32>(i32) -> Option<i32>
48+
55..65 'Some(1i32)': Option<i32>
49+
60..64 '1i32': i32
50+
"#]],
51+
);
52+
}

0 commit comments

Comments
 (0)