From 0edb5b4a501a66baa7db8ececf46135e6246f4de Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 24 Dec 2019 19:45:28 +0800 Subject: Implement infer await from async func --- crates/ra_hir_ty/src/tests/traits.rs | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 76e2198b6..08d1bf044 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -37,6 +37,63 @@ mod future { assert_eq!("u64", type_at_pos(&db, pos)); } +#[test] +fn infer_async() { + let (db, pos) = TestDB::with_position( + r#" +//- /main.rs crate:main deps:std + +async fn foo() -> u64 { + 128 +} + +fn test() { + let r = foo(); + let v = r.await; + v<|>; +} + +//- /std.rs crate:std +#[prelude_import] use future::*; +mod future { + trait Future { + type Output; + } +} + +"#, + ); + assert_eq!("u64", type_at_pos(&db, pos)); +} + +#[test] +fn infer_desugar_async() { + let (db, pos) = TestDB::with_position( + r#" +//- /main.rs crate:main deps:std + +async fn foo() -> u64 { + 128 +} + +fn test() { + let r = foo(); + r<|>; +} + +//- /std.rs crate:std +#[prelude_import] use future::*; +mod future { + trait Future { + type Output; + } +} + +"#, + ); + assert_eq!("impl Future", type_at_pos(&db, pos)); +} + #[test] fn infer_try() { let (db, pos) = TestDB::with_position( -- cgit v1.2.3