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
This commit is contained in:
bors 2023-04-11 13:34:49 +00:00
commit 600283f2de
2 changed files with 18 additions and 1 deletions

View File

@ -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 {

View File

@ -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(