diff options
| author | Zachary S <zasample18+github@gmail.com> | 2022-08-07 00:02:25 -0500 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2023-03-15 13:10:35 +0100 |
| commit | af175ddcdcfeddf6814b67bce8abb68a954981eb (patch) | |
| tree | 390db5f046ce6f87fda64042fa371d6a4e0917e0 | |
| parent | 6746a08b442d25dc63a90ace1682ebd9ec9b50b8 (diff) | |
| download | rust-af175ddcdcfeddf6814b67bce8abb68a954981eb.tar.gz rust-af175ddcdcfeddf6814b67bce8abb68a954981eb.zip | |
Add test for async closure types.
(rebased onto 6dfd8ae)
| -rw-r--r-- | crates/hir-def/src/body/pretty.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/tests/traits.rs | 40 |
2 files changed, 41 insertions, 1 deletions
diff --git a/crates/hir-def/src/body/pretty.rs b/crates/hir-def/src/body/pretty.rs index 610b7d8008d..de3d995c9a0 100644 --- a/crates/hir-def/src/body/pretty.rs +++ b/crates/hir-def/src/body/pretty.rs @@ -386,7 +386,7 @@ impl<'a> Printer<'a> { self.print_type_ref(ret_ty); } (None, ClosureKind::Async) => { - w!(self, " -> impl Future<Output = {{unknown}}>"); // FIXME(zachs18): {unknown} or ()? + w!(self, " -> impl Future<Output = {{unknown}}>"); } (None, _) => {} } diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs index 015085bde45..4e9b1611fb2 100644 --- a/crates/hir-ty/src/tests/traits.rs +++ b/crates/hir-ty/src/tests/traits.rs @@ -83,6 +83,46 @@ async fn test() { } #[test] +fn infer_async_closure() { + check_types( + r#" +//- minicore: future, option +async fn test() { + let f = async move |x: i32| x + 42; + f; +// ^ |i32| -> impl Future<Output = i32> + let a = f(4); + a; +// ^ impl Future<Output = i32> + let x = a.await; + x; +// ^ i32 + let f = async move || 42; + f; +// ^ || -> impl Future<Output = i32> + let a = f(); + a; +// ^ impl Future<Output = i32> + let x = a.await; + x; +// ^ i32 + let b = ((async move || {})()).await; + b; +// ^ () + let c = async move || { + let y = None; + y + // ^ Option<u64> + }; + let _: Option<u64> = c().await; + c; +// ^ || -> impl Future<Output = Option<u64>> +} +"#, + ); +} + +#[test] fn auto_sized_async_block() { check_no_mismatches( r#" |
