Skip to content

Commit cc5e6b2

Browse files
committed
Rust: add test cases for basic unwrapping and pattern matching
1 parent 7c5cdd9 commit cc5e6b2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,3 +2285,26 @@ fn main() {
22852285
tuples::f(); // $ method=f
22862286
dereference::test(); // $ method=test
22872287
}
2288+
2289+
pub mod unwrap {
2290+
pub fn test_unwrapping() -> Option<()> {
2291+
let value = Some(42);
2292+
if let Some(mesg) = value {
2293+
let mesg = mesg; // $ MISSING: type=mesg:i32
2294+
println!("{mesg}");
2295+
}
2296+
match value {
2297+
Some(mesg) => {
2298+
let mesg = mesg; // $ MISSING: type=mesg:i32
2299+
println!("{mesg}");
2300+
}
2301+
None => (),
2302+
};
2303+
let mesg = value.unwrap(); // $ method=unwrap
2304+
let mesg = mesg; // $ type=mesg:i32
2305+
println!("{mesg}");
2306+
let mesg = value?; // $ type=mesg:i32
2307+
println!("{mesg}");
2308+
None
2309+
}
2310+
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,4 +3644,35 @@ inferType
36443644
| main.rs:2262:20:2262:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
36453645
| main.rs:2262:41:2262:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
36463646
| main.rs:2278:5:2278:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
3647+
| main.rs:2290:44:2309:5 | { ... } | | {EXTERNAL LOCATION} | Option |
3648+
| main.rs:2291:13:2291:17 | value | | {EXTERNAL LOCATION} | Option |
3649+
| main.rs:2291:13:2291:17 | value | T | {EXTERNAL LOCATION} | i32 |
3650+
| main.rs:2291:21:2291:28 | Some(...) | | {EXTERNAL LOCATION} | Option |
3651+
| main.rs:2291:21:2291:28 | Some(...) | T | {EXTERNAL LOCATION} | i32 |
3652+
| main.rs:2291:26:2291:27 | 42 | | {EXTERNAL LOCATION} | i32 |
3653+
| main.rs:2292:29:2292:33 | value | | {EXTERNAL LOCATION} | Option |
3654+
| main.rs:2292:29:2292:33 | value | T | {EXTERNAL LOCATION} | i32 |
3655+
| main.rs:2294:22:2294:29 | "{mesg}\\n" | | file://:0:0:0:0 | & |
3656+
| main.rs:2294:22:2294:29 | "{mesg}\\n" | &T | {EXTERNAL LOCATION} | str |
3657+
| main.rs:2296:15:2296:19 | value | | {EXTERNAL LOCATION} | Option |
3658+
| main.rs:2296:15:2296:19 | value | T | {EXTERNAL LOCATION} | i32 |
3659+
| main.rs:2299:26:2299:33 | "{mesg}\\n" | | file://:0:0:0:0 | & |
3660+
| main.rs:2299:26:2299:33 | "{mesg}\\n" | &T | {EXTERNAL LOCATION} | str |
3661+
| main.rs:2303:13:2303:16 | mesg | | {EXTERNAL LOCATION} | i32 |
3662+
| main.rs:2303:20:2303:24 | value | | {EXTERNAL LOCATION} | Option |
3663+
| main.rs:2303:20:2303:24 | value | T | {EXTERNAL LOCATION} | i32 |
3664+
| main.rs:2303:20:2303:33 | value.unwrap() | | {EXTERNAL LOCATION} | i32 |
3665+
| main.rs:2304:13:2304:16 | mesg | | {EXTERNAL LOCATION} | i32 |
3666+
| main.rs:2304:20:2304:23 | mesg | | {EXTERNAL LOCATION} | i32 |
3667+
| main.rs:2305:18:2305:25 | "{mesg}\\n" | | file://:0:0:0:0 | & |
3668+
| main.rs:2305:18:2305:25 | "{mesg}\\n" | &T | {EXTERNAL LOCATION} | str |
3669+
| main.rs:2305:20:2305:23 | mesg | | {EXTERNAL LOCATION} | i32 |
3670+
| main.rs:2306:13:2306:16 | mesg | | {EXTERNAL LOCATION} | i32 |
3671+
| main.rs:2306:20:2306:24 | value | | {EXTERNAL LOCATION} | Option |
3672+
| main.rs:2306:20:2306:24 | value | T | {EXTERNAL LOCATION} | i32 |
3673+
| main.rs:2306:20:2306:25 | TryExpr | | {EXTERNAL LOCATION} | i32 |
3674+
| main.rs:2307:18:2307:25 | "{mesg}\\n" | | file://:0:0:0:0 | & |
3675+
| main.rs:2307:18:2307:25 | "{mesg}\\n" | &T | {EXTERNAL LOCATION} | str |
3676+
| main.rs:2307:20:2307:23 | mesg | | {EXTERNAL LOCATION} | i32 |
3677+
| main.rs:2308:9:2308:12 | None | | {EXTERNAL LOCATION} | Option |
36473678
testFailures

0 commit comments

Comments
 (0)