diff options
| author | bors <bors@rust-lang.org> | 2023-04-11 13:34:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-04-11 13:34:49 +0000 |
| commit | 600283f2de12b40fbe60a6cade3650785ef0bbbc (patch) | |
| tree | 734207a245382ff8e1b47320a258e8b02a055cbc | |
| parent | 5d41affc775aea0ed264fdd9f438a23f6bcbe0af (diff) | |
| parent | 85f9235de82e99127c766c619ad392cc6f0cb694 (diff) | |
| download | rust-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.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 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#" |
