diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs index e994546356b..28cb301f3e4 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 d78d6eba7fb..28b87689ecd 100644 --- a/crates/hir-ty/src/tests/regression.rs +++ b/crates/hir-ty/src/tests/regression.rs @@ -1067,6 +1067,23 @@ fn parse_arule() { ) } +#[test] +fn nested_closure() { + check_types( + r#" +//- minicore: fn, option + +fn map(o: Option, f: impl FnOnce(T) -> U) -> Option { loop {} } + +fn test() { + let o = Some(Some(2)); + map(o, |s| map(s, |x| x)); + // ^ i32 +} + "#, + ); +} + #[test] fn call_expected_type_closure() { check_types(