From 251ef93ac3bbb138a2eedf6090f2f56f1a15d898 Mon Sep 17 00:00:00 2001 From: oxalica Date: Thu, 10 Sep 2020 20:01:23 +0800 Subject: Implement async blocks --- crates/hir_ty/src/tests/simple.rs | 45 +++++++++++++++++++++++---------------- crates/hir_ty/src/tests/traits.rs | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 18 deletions(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index 48db23a34..5b07948f3 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs @@ -1889,31 +1889,40 @@ fn fn_pointer_return() { fn effects_smoke_test() { check_infer( r#" - fn main() { + async fn main() { let x = unsafe { 92 }; let y = async { async { () }.await }; let z = try { () }; let t = 'a: { 92 }; } + + #[prelude_import] use future::*; + + mod future { + #[lang = "future_trait"] + pub trait Future { type Output; } + } "#, expect![[r#" - 10..130 '{ ...2 }; }': () - 20..21 'x': i32 - 24..37 'unsafe { 92 }': i32 - 31..37 '{ 92 }': i32 - 33..35 '92': i32 - 47..48 'y': {unknown} - 57..79 '{ asyn...wait }': {unknown} - 59..77 'async ....await': {unknown} - 65..71 '{ () }': () - 67..69 '()': () - 89..90 'z': {unknown} - 93..103 'try { () }': {unknown} - 97..103 '{ () }': () - 99..101 '()': () - 113..114 't': i32 - 121..127 '{ 92 }': i32 - 123..125 '92': i32 + 16..136 '{ ...2 }; }': () + 26..27 'x': i32 + 30..43 'unsafe { 92 }': i32 + 37..43 '{ 92 }': i32 + 39..41 '92': i32 + 53..54 'y': impl Future + 57..85 'async ...wait }': impl Future + 63..85 '{ asyn...wait }': () + 65..77 'async { () }': impl Future + 65..83 'async ....await': () + 71..77 '{ () }': () + 73..75 '()': () + 95..96 'z': {unknown} + 99..109 'try { () }': {unknown} + 103..109 '{ () }': () + 105..107 '()': () + 119..120 't': i32 + 127..133 '{ 92 }': i32 + 129..131 '92': i32 "#]], ) } diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 1f1056962..41d097519 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -85,6 +85,46 @@ mod future { ); } +#[test] +fn infer_async_block() { + check_types( + r#" +//- /main.rs crate:main deps:core +async fn test() { + let a = async { 42 }; + a; +// ^ impl Future + let x = a.await; + x; +// ^ i32 + let b = async {}.await; + b; +// ^ () + let c = async { + let y = Option::None; + y + // ^ Option + }; + let _: Option = c.await; + c; +// ^ impl Future> +} + +enum Option { None, Some(T) } + +//- /core.rs crate:core +#[prelude_import] use future::*; +mod future { + #[lang = "future_trait"] + trait Future { + type Output; + } +} + +"#, + ); +} + #[test] fn infer_try() { check_types( -- cgit v1.2.3