Skip to content

Commit c32e05c

Browse files
committed
Rust: Add async type inference tests
1 parent 79a8942 commit c32e05c

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,46 @@ mod overloadable_operators {
16301630
}
16311631
}
16321632

1633+
mod async_ {
1634+
use std::future::Future;
1635+
1636+
struct S1;
1637+
1638+
impl S1 {
1639+
pub fn f(self) {} // S1f
1640+
}
1641+
1642+
async fn f1() -> S1 {
1643+
S1
1644+
}
1645+
1646+
fn f2() -> impl Future<Output = S1> {
1647+
async {
1648+
S1
1649+
}
1650+
}
1651+
1652+
struct S2;
1653+
1654+
impl Future for S2 {
1655+
type Output = S1;
1656+
1657+
fn poll(self: std::pin::Pin<&mut Self>, _cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
1658+
std::task::Poll::Ready(S1)
1659+
}
1660+
}
1661+
1662+
fn f3() -> impl Future<Output = S1> {
1663+
S2
1664+
}
1665+
1666+
pub async fn f() {
1667+
f1().await.f(); // $ MISSING: method=S1f
1668+
f2().await.f(); // $ MISSING: method=S1f
1669+
f3().await.f(); // $ MISSING: method=S1f
1670+
}
1671+
}
1672+
16331673
fn main() {
16341674
field_access::f();
16351675
method_impl::f();
@@ -1649,4 +1689,5 @@ fn main() {
16491689
try_expressions::f();
16501690
builtins::f();
16511691
operators::f();
1692+
async_::f();
16521693
}

rust/ql/test/library-tests/type-inference/type-inference.expected

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,8 +2374,27 @@ inferType
23742374
| main.rs:1629:13:1629:20 | vec2_not | | main.rs:1278:5:1283:5 | Vec2 |
23752375
| main.rs:1629:24:1629:26 | ! ... | | main.rs:1278:5:1283:5 | Vec2 |
23762376
| main.rs:1629:25:1629:26 | v1 | | main.rs:1278:5:1283:5 | Vec2 |
2377-
| main.rs:1635:5:1635:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
2378-
| main.rs:1636:5:1636:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
2379-
| main.rs:1636:20:1636:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
2380-
| main.rs:1636:41:1636:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
2377+
| main.rs:1639:18:1639:21 | SelfParam | | main.rs:1636:5:1636:14 | S1 |
2378+
| main.rs:1642:25:1644:5 | { ... } | | main.rs:1636:5:1636:14 | S1 |
2379+
| main.rs:1643:9:1643:10 | S1 | | main.rs:1636:5:1636:14 | S1 |
2380+
| main.rs:1646:41:1650:5 | { ... } | | main.rs:1636:5:1636:14 | S1 |
2381+
| main.rs:1647:9:1649:9 | { ... } | | main.rs:1636:5:1636:14 | S1 |
2382+
| main.rs:1648:13:1648:14 | S1 | | main.rs:1636:5:1636:14 | S1 |
2383+
| main.rs:1657:17:1657:46 | SelfParam | | {EXTERNAL LOCATION} | Pin |
2384+
| main.rs:1657:17:1657:46 | SelfParam | Ptr | file://:0:0:0:0 | & |
2385+
| main.rs:1657:17:1657:46 | SelfParam | Ptr.&T | main.rs:1652:5:1652:14 | S2 |
2386+
| main.rs:1657:49:1657:51 | _cx | | file://:0:0:0:0 | & |
2387+
| main.rs:1657:49:1657:51 | _cx | &T | {EXTERNAL LOCATION} | Context |
2388+
| main.rs:1657:116:1659:9 | { ... } | | {EXTERNAL LOCATION} | Poll |
2389+
| main.rs:1657:116:1659:9 | { ... } | T | main.rs:1636:5:1636:14 | S1 |
2390+
| main.rs:1658:13:1658:38 | ...::Ready(...) | | {EXTERNAL LOCATION} | Poll |
2391+
| main.rs:1658:13:1658:38 | ...::Ready(...) | T | main.rs:1636:5:1636:14 | S1 |
2392+
| main.rs:1658:36:1658:37 | S1 | | main.rs:1636:5:1636:14 | S1 |
2393+
| main.rs:1662:41:1664:5 | { ... } | | main.rs:1652:5:1652:14 | S2 |
2394+
| main.rs:1663:9:1663:10 | S2 | | main.rs:1652:5:1652:14 | S2 |
2395+
| main.rs:1667:9:1667:12 | f1(...) | | main.rs:1636:5:1636:14 | S1 |
2396+
| main.rs:1675:5:1675:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
2397+
| main.rs:1676:5:1676:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
2398+
| main.rs:1676:20:1676:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
2399+
| main.rs:1676:41:1676:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
23812400
testFailures

0 commit comments

Comments
 (0)