Skip to content

Commit aa49c0b

Browse files
Normalize all types when finishing inference
The new solver does not eagerly normalize, but things after inference expect types to be normalized. rustc does the same. Also, I'm afraid other things in r-a don't expect results of the solver to be unnormalized. We'll need to handle that.
1 parent 781e026 commit aa49c0b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/tools/rust-analyzer/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

src/tools/rust-analyzer/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)