Skip to content

Commit 600283f

Browse files
committed
Auto merge of rust-lang#14550 - HKalbasi:mir, r=HKalbasi
Fix inference in nested closures fix rust-lang/rust-analyzer#14470 (comment)
2 parents 5d41aff + 85f9235 commit 600283f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

crates/hir-ty/src/infer/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl InferenceContext<'_> {
462462
}
463463

464464
fn expr_ty(&mut self, expr: ExprId) -> Ty {
465-
self.infer_expr_no_expect(expr)
465+
self.result[expr].clone()
466466
}
467467

468468
fn is_upvar(&self, place: &HirPlace) -> bool {

crates/hir-ty/src/tests/regression.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,23 @@ fn parse_arule() {
10671067
)
10681068
}
10691069

1070+
#[test]
1071+
fn nested_closure() {
1072+
check_types(
1073+
r#"
1074+
//- minicore: fn, option
1075+
1076+
fn map<T, U>(o: Option<T>, f: impl FnOnce(T) -> U) -> Option<U> { loop {} }
1077+
1078+
fn test() {
1079+
let o = Some(Some(2));
1080+
map(o, |s| map(s, |x| x));
1081+
// ^ i32
1082+
}
1083+
"#,
1084+
);
1085+
}
1086+
10701087
#[test]
10711088
fn call_expected_type_closure() {
10721089
check_types(

0 commit comments

Comments
 (0)