Skip to content

Commit ad136ca

Browse files
committed
Rust: add test cases for basic unwrapping and pattern matching
1 parent 5722084 commit ad136ca

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,3 +2255,29 @@ fn main() {
22552255
method_determined_by_argument_type::f(); // $ method=f
22562256
dereference::test(); // $ method=test
22572257
}
2258+
2259+
pub mod unwrap {
2260+
pub fn test_unwrapping() -> Option<()> {
2261+
let value = Some(42);
2262+
if let Some(mesg) = value {
2263+
let mesg = mesg; // $ MISSING: type=mesg:i32
2264+
println!("{mesg}");
2265+
}
2266+
match value {
2267+
Some(mesg) => {
2268+
let mesg = mesg; // $ MISSING: type=mesg:i32
2269+
println!("{mesg}");
2270+
}
2271+
None => (),
2272+
};
2273+
let mesg = value.unwrap(); // $ method=unwrap
2274+
let mesg = mesg; // $ type=mesg:i32
2275+
println!("{mesg}");
2276+
let mesg = value?; // $ type=mesg:i32
2277+
println!("{mesg}");
2278+
let (a, b) = (10, true);
2279+
let a = a; // $ MISSING: type=a:i32
2280+
let b = b; // $ MISSING: type=b:bool
2281+
None
2282+
}
2283+
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3641,4 +3641,37 @@ inferType
36413641
| main.rs:2234:20:2234:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
36423642
| main.rs:2234:41:2234:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
36433643
| main.rs:2250:5:2250:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
3644+
| main.rs:2260:44:2282:5 | { ... } | | {EXTERNAL LOCATION} | Option |
3645+
| main.rs:2261:13:2261:17 | value | | {EXTERNAL LOCATION} | Option |
3646+
| main.rs:2261:13:2261:17 | value | T | {EXTERNAL LOCATION} | i32 |
3647+
| main.rs:2261:21:2261:28 | Some(...) | | {EXTERNAL LOCATION} | Option |
3648+
| main.rs:2261:21:2261:28 | Some(...) | T | {EXTERNAL LOCATION} | i32 |
3649+
| main.rs:2261:26:2261:27 | 42 | | {EXTERNAL LOCATION} | i32 |
3650+
| main.rs:2262:29:2262:33 | value | | {EXTERNAL LOCATION} | Option |
3651+
| main.rs:2262:29:2262:33 | value | T | {EXTERNAL LOCATION} | i32 |
3652+
| main.rs:2264:22:2264:29 | "{mesg}\\n" | | file://:0:0:0:0 | & |
3653+
| main.rs:2264:22:2264:29 | "{mesg}\\n" | &T | {EXTERNAL LOCATION} | str |
3654+
| main.rs:2266:15:2266:19 | value | | {EXTERNAL LOCATION} | Option |
3655+
| main.rs:2266:15:2266:19 | value | T | {EXTERNAL LOCATION} | i32 |
3656+
| main.rs:2269:26:2269:33 | "{mesg}\\n" | | file://:0:0:0:0 | & |
3657+
| main.rs:2269:26:2269:33 | "{mesg}\\n" | &T | {EXTERNAL LOCATION} | str |
3658+
| main.rs:2273:13:2273:16 | mesg | | {EXTERNAL LOCATION} | i32 |
3659+
| main.rs:2273:20:2273:24 | value | | {EXTERNAL LOCATION} | Option |
3660+
| main.rs:2273:20:2273:24 | value | T | {EXTERNAL LOCATION} | i32 |
3661+
| main.rs:2273:20:2273:33 | value.unwrap() | | {EXTERNAL LOCATION} | i32 |
3662+
| main.rs:2274:13:2274:16 | mesg | | {EXTERNAL LOCATION} | i32 |
3663+
| main.rs:2274:20:2274:23 | mesg | | {EXTERNAL LOCATION} | i32 |
3664+
| main.rs:2275:18:2275:25 | "{mesg}\\n" | | file://:0:0:0:0 | & |
3665+
| main.rs:2275:18:2275:25 | "{mesg}\\n" | &T | {EXTERNAL LOCATION} | str |
3666+
| main.rs:2275:20:2275:23 | mesg | | {EXTERNAL LOCATION} | i32 |
3667+
| main.rs:2276:13:2276:16 | mesg | | {EXTERNAL LOCATION} | i32 |
3668+
| main.rs:2276:20:2276:24 | value | | {EXTERNAL LOCATION} | Option |
3669+
| main.rs:2276:20:2276:24 | value | T | {EXTERNAL LOCATION} | i32 |
3670+
| main.rs:2276:20:2276:25 | TryExpr | | {EXTERNAL LOCATION} | i32 |
3671+
| main.rs:2277:18:2277:25 | "{mesg}\\n" | | file://:0:0:0:0 | & |
3672+
| main.rs:2277:18:2277:25 | "{mesg}\\n" | &T | {EXTERNAL LOCATION} | str |
3673+
| main.rs:2277:20:2277:23 | mesg | | {EXTERNAL LOCATION} | i32 |
3674+
| main.rs:2278:23:2278:24 | 10 | | {EXTERNAL LOCATION} | i32 |
3675+
| main.rs:2278:27:2278:30 | true | | {EXTERNAL LOCATION} | bool |
3676+
| main.rs:2281:9:2281:12 | None | | {EXTERNAL LOCATION} | Option |
36443677
testFailures

0 commit comments

Comments
 (0)