Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #14550 - HKalbasi:mir, r=HKalbasi
Fix inference in nested closures
fix https://github.com/rust-lang/rust-analyzer/pull/14470#issuecomment-1503084796
| -rw-r--r-- | crates/hir-ty/src/infer/closure.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/tests/regression.rs | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs index e994546356..28cb301f3e 100644 --- a/crates/hir-ty/src/infer/closure.rs +++ b/crates/hir-ty/src/infer/closure.rs @@ -462,7 +462,7 @@ impl InferenceContext<'_> { } fn expr_ty(&mut self, expr: ExprId) -> Ty { - self.infer_expr_no_expect(expr) + self.result[expr].clone() } fn is_upvar(&self, place: &HirPlace) -> bool { diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs index d78d6eba7f..28b87689ec 100644 --- a/crates/hir-ty/src/tests/regression.rs +++ b/crates/hir-ty/src/tests/regression.rs @@ -1068,6 +1068,23 @@ fn parse_arule() { } #[test] +fn nested_closure() { + check_types( + r#" +//- minicore: fn, option + +fn map<T, U>(o: Option<T>, f: impl FnOnce(T) -> U) -> Option<U> { loop {} } + +fn test() { + let o = Some(Some(2)); + map(o, |s| map(s, |x| x)); + // ^ i32 +} + "#, + ); +} + +#[test] fn call_expected_type_closure() { check_types( r#" |