about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-04-11 13:34:49 +0000
committerbors <bors@rust-lang.org>2023-04-11 13:34:49 +0000
commit600283f2de12b40fbe60a6cade3650785ef0bbbc (patch)
tree734207a245382ff8e1b47320a258e8b02a055cbc
parent5d41affc775aea0ed264fdd9f438a23f6bcbe0af (diff)
parent85f9235de82e99127c766c619ad392cc6f0cb694 (diff)
downloadrust-600283f2de12b40fbe60a6cade3650785ef0bbbc.tar.gz
rust-600283f2de12b40fbe60a6cade3650785ef0bbbc.zip
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.rs2
-rw-r--r--crates/hir-ty/src/tests/regression.rs17
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 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
@@ -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#"