Skip to content

Commit 24a4208

Browse files
committed
Rust: Add async type inference tests
1 parent a519eab commit 24a4208

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
@@ -1239,6 +1239,46 @@ mod operators {
12391239
}
12401240
}
12411241

1242+
mod async_ {
1243+
use std::future::Future;
1244+
1245+
struct S1;
1246+
1247+
impl S1 {
1248+
pub fn f(self) {} // S1f
1249+
}
1250+
1251+
async fn f1() -> S1 {
1252+
S1
1253+
}
1254+
1255+
fn f2() -> impl Future<Output = S1> {
1256+
async {
1257+
S1
1258+
}
1259+
}
1260+
1261+
struct S2;
1262+
1263+
impl Future for S2 {
1264+
type Output = S1;
1265+
1266+
fn poll(self: std::pin::Pin<&mut Self>, _cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
1267+
std::task::Poll::Ready(S1)
1268+
}
1269+
}
1270+
1271+
fn f3() -> impl Future<Output = S1> {
1272+
S2
1273+
}
1274+
1275+
pub async fn f() {
1276+
f1().await.f(); // $ MISSING: method=S1f
1277+
f2().await.f(); // $ MISSING: method=S1f
1278+
f3().await.f(); // $ MISSING: method=S1f
1279+
}
1280+
}
1281+
12421282
fn main() {
12431283
field_access::f();
12441284
method_impl::f();
@@ -1258,4 +1298,5 @@ fn main() {
12581298
try_expressions::f();
12591299
builtins::f();
12601300
operators::f();
1301+
async_::f();
12611302
}

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,26 @@ inferType
16011601
| main.rs:1236:13:1236:17 | ... = ... | | file://:0:0:0:0 | () |
16021602
| main.rs:1236:17:1236:17 | 2 | | file:///BUILTINS/types.rs:12:1:12:15 | i32 |
16031603
| main.rs:1238:9:1238:9 | a | | file:///BUILTINS/types.rs:12:1:12:15 | i32 |
1604-
| main.rs:1244:5:1244:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
1605-
| main.rs:1245:5:1245:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
1606-
| main.rs:1245:20:1245:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
1607-
| main.rs:1245:41:1245:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
1604+
| main.rs:1248:18:1248:21 | SelfParam | | main.rs:1245:5:1245:14 | S1 |
1605+
| main.rs:1251:25:1253:5 | { ... } | | main.rs:1245:5:1245:14 | S1 |
1606+
| main.rs:1252:9:1252:10 | S1 | | main.rs:1245:5:1245:14 | S1 |
1607+
| main.rs:1255:41:1259:5 | { ... } | | main.rs:1245:5:1245:14 | S1 |
1608+
| main.rs:1256:9:1258:9 | { ... } | | main.rs:1245:5:1245:14 | S1 |
1609+
| main.rs:1257:13:1257:14 | S1 | | main.rs:1245:5:1245:14 | S1 |
1610+
| main.rs:1266:17:1266:46 | SelfParam | | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/pin.rs:934:1:1104:1 | Pin |
1611+
| main.rs:1266:17:1266:46 | SelfParam | Ptr | file://:0:0:0:0 | & |
1612+
| main.rs:1266:17:1266:46 | SelfParam | Ptr.&T | main.rs:1261:5:1261:14 | S2 |
1613+
| main.rs:1266:49:1266:51 | _cx | | file://:0:0:0:0 | & |
1614+
| main.rs:1266:49:1266:51 | _cx | &T | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/task/wake.rs:214:1:232:1 | Context |
1615+
| main.rs:1266:116:1268:9 | { ... } | | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/task/poll.rs:6:1:28:1 | Poll |
1616+
| main.rs:1266:116:1268:9 | { ... } | T | main.rs:1245:5:1245:14 | S1 |
1617+
| main.rs:1267:13:1267:38 | ...::Ready(...) | | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/task/poll.rs:6:1:28:1 | Poll |
1618+
| main.rs:1267:13:1267:38 | ...::Ready(...) | T | main.rs:1245:5:1245:14 | S1 |
1619+
| main.rs:1267:36:1267:37 | S1 | | main.rs:1245:5:1245:14 | S1 |
1620+
| main.rs:1271:41:1273:5 | { ... } | | main.rs:1261:5:1261:14 | S2 |
1621+
| main.rs:1272:9:1272:10 | S2 | | main.rs:1261:5:1261:14 | S2 |
1622+
| main.rs:1276:9:1276:12 | f1(...) | | main.rs:1245:5:1245:14 | S1 |
1623+
| main.rs:1284:5:1284:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
1624+
| main.rs:1285:5:1285:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
1625+
| main.rs:1285:20:1285:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
1626+
| main.rs:1285:41:1285:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |

0 commit comments

Comments
 (0)