Skip to content

Commit de290ff

Browse files
committed
Rust: Add async type inference tests
1 parent 8595bd8 commit de290ff

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
@@ -1265,6 +1265,46 @@ mod operators {
12651265
}
12661266
}
12671267

1268+
mod async_ {
1269+
use std::future::Future;
1270+
1271+
struct S1;
1272+
1273+
impl S1 {
1274+
pub fn f(self) {} // S1f
1275+
}
1276+
1277+
async fn f1() -> S1 {
1278+
S1
1279+
}
1280+
1281+
fn f2() -> impl Future<Output = S1> {
1282+
async {
1283+
S1
1284+
}
1285+
}
1286+
1287+
struct S2;
1288+
1289+
impl Future for S2 {
1290+
type Output = S1;
1291+
1292+
fn poll(self: std::pin::Pin<&mut Self>, _cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
1293+
std::task::Poll::Ready(S1)
1294+
}
1295+
}
1296+
1297+
fn f3() -> impl Future<Output = S1> {
1298+
S2
1299+
}
1300+
1301+
pub async fn f() {
1302+
f1().await.f(); // $ MISSING: method=S1f
1303+
f2().await.f(); // $ MISSING: method=S1f
1304+
f3().await.f(); // $ MISSING: method=S1f
1305+
}
1306+
}
1307+
12681308
fn main() {
12691309
field_access::f();
12701310
method_impl::f();
@@ -1284,4 +1324,5 @@ fn main() {
12841324
try_expressions::f();
12851325
builtins::f();
12861326
operators::f();
1327+
async_::f();
12871328
}

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,26 @@ inferType
16181618
| main.rs:1262:13:1262:17 | ... = ... | | file://:0:0:0:0 | () |
16191619
| main.rs:1262:17:1262:17 | 2 | | file:///BUILTINS/types.rs:12:1:12:15 | i32 |
16201620
| main.rs:1264:9:1264:9 | a | | file:///BUILTINS/types.rs:12:1:12:15 | i32 |
1621-
| main.rs:1270:5:1270:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
1622-
| main.rs:1271:5:1271:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
1623-
| main.rs:1271:20:1271:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
1624-
| main.rs:1271:41:1271:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
1621+
| main.rs:1274:18:1274:21 | SelfParam | | main.rs:1271:5:1271:14 | S1 |
1622+
| main.rs:1277:25:1279:5 | { ... } | | main.rs:1271:5:1271:14 | S1 |
1623+
| main.rs:1278:9:1278:10 | S1 | | main.rs:1271:5:1271:14 | S1 |
1624+
| main.rs:1281:41:1285:5 | { ... } | | main.rs:1271:5:1271:14 | S1 |
1625+
| main.rs:1282:9:1284:9 | { ... } | | main.rs:1271:5:1271:14 | S1 |
1626+
| main.rs:1283:13:1283:14 | S1 | | main.rs:1271:5:1271:14 | S1 |
1627+
| main.rs:1292:17:1292:46 | SelfParam | | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/pin.rs:934:1:1104:1 | Pin |
1628+
| main.rs:1292:17:1292:46 | SelfParam | Ptr | file://:0:0:0:0 | & |
1629+
| main.rs:1292:17:1292:46 | SelfParam | Ptr.&T | main.rs:1287:5:1287:14 | S2 |
1630+
| main.rs:1292:49:1292:51 | _cx | | file://:0:0:0:0 | & |
1631+
| main.rs:1292:49:1292:51 | _cx | &T | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/task/wake.rs:214:1:232:1 | Context |
1632+
| main.rs:1292:116:1294:9 | { ... } | | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/task/poll.rs:6:1:28:1 | Poll |
1633+
| main.rs:1292:116:1294:9 | { ... } | T | main.rs:1271:5:1271:14 | S1 |
1634+
| main.rs:1293:13:1293:38 | ...::Ready(...) | | file:///RUSTUP_HOME/toolchain/lib/rustlib/src/rust/library/core/src/task/poll.rs:6:1:28:1 | Poll |
1635+
| main.rs:1293:13:1293:38 | ...::Ready(...) | T | main.rs:1271:5:1271:14 | S1 |
1636+
| main.rs:1293:36:1293:37 | S1 | | main.rs:1271:5:1271:14 | S1 |
1637+
| main.rs:1297:41:1299:5 | { ... } | | main.rs:1287:5:1287:14 | S2 |
1638+
| main.rs:1298:9:1298:10 | S2 | | main.rs:1287:5:1287:14 | S2 |
1639+
| main.rs:1302:9:1302:12 | f1(...) | | main.rs:1271:5:1271:14 | S1 |
1640+
| main.rs:1310:5:1310:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
1641+
| main.rs:1311:5:1311:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
1642+
| main.rs:1311:20:1311:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
1643+
| main.rs:1311:41:1311:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |

0 commit comments

Comments
 (0)