Skip to content

Commit af175dd

Browse files
zachs18Veykril
authored andcommitted
Add test for async closure types.
(rebased onto 6dfd8ae)
1 parent 6746a08 commit af175dd

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

crates/hir-def/src/body/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl<'a> Printer<'a> {
386386
self.print_type_ref(ret_ty);
387387
}
388388
(None, ClosureKind::Async) => {
389-
w!(self, " -> impl Future<Output = {{unknown}}>"); // FIXME(zachs18): {unknown} or ()?
389+
w!(self, " -> impl Future<Output = {{unknown}}>");
390390
}
391391
(None, _) => {}
392392
}

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,46 @@ async fn test() {
8282
);
8383
}
8484

85+
#[test]
86+
fn infer_async_closure() {
87+
check_types(
88+
r#"
89+
//- minicore: future, option
90+
async fn test() {
91+
let f = async move |x: i32| x + 42;
92+
f;
93+
// ^ |i32| -> impl Future<Output = i32>
94+
let a = f(4);
95+
a;
96+
// ^ impl Future<Output = i32>
97+
let x = a.await;
98+
x;
99+
// ^ i32
100+
let f = async move || 42;
101+
f;
102+
// ^ || -> impl Future<Output = i32>
103+
let a = f();
104+
a;
105+
// ^ impl Future<Output = i32>
106+
let x = a.await;
107+
x;
108+
// ^ i32
109+
let b = ((async move || {})()).await;
110+
b;
111+
// ^ ()
112+
let c = async move || {
113+
let y = None;
114+
y
115+
// ^ Option<u64>
116+
};
117+
let _: Option<u64> = c().await;
118+
c;
119+
// ^ || -> impl Future<Output = Option<u64>>
120+
}
121+
"#,
122+
);
123+
}
124+
85125
#[test]
86126
fn auto_sized_async_block() {
87127
check_no_mismatches(

0 commit comments

Comments
 (0)