Skip to content

Commit

Permalink
Auto merge of rust-lang#14550 - HKalbasi:mir, r=HKalbasi
Browse files Browse the repository at this point in the history
Fix inference in nested closures

fix rust-lang/rust-analyzer#14470 (comment)
  • Loading branch information
bors committed Apr 11, 2023
2 parents 5d41aff + 85f9235 commit 600283f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions crates/hir-ty/src/tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,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(
Expand Down

0 comments on commit 600283f

Please sign in to comment.