Skip to content

Commit 4d1691f

Browse files
committed
Rust: type inference: add test for closure argument
1 parent fb73f2a commit 4d1691f

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,14 @@ pub mod pattern_matching {
32133213
}
32143214
}
32153215

3216+
mod closures {
3217+
pub fn f() {
3218+
Some(1).map(|x| {
3219+
let x = x; // $ MISSING: type=x:i32
3220+
println!("{x}");
3221+
}); // $ method=map
3222+
}
3223+
}
32163224
fn main() {
32173225
field_access::f(); // $ method=f
32183226
method_impl::f(); // $ method=f
@@ -3242,4 +3250,5 @@ fn main() {
32423250
tuples::f(); // $ method=f
32433251
dereference::test(); // $ method=test
32443252
pattern_matching::test_all_patterns(); // $ method=test_all_patterns
3253+
closures::f() // $ method=f
32453254
}

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5396,9 +5396,17 @@ inferType
53965396
| main.rs:3186:42:3186:48 | guard_x | | {EXTERNAL LOCATION} | i32 |
53975397
| main.rs:3188:13:3188:13 | _ | | {EXTERNAL LOCATION} | i32 |
53985398
| main.rs:3193:9:3193:11 | f(...) | | {EXTERNAL LOCATION} | Option |
5399-
| main.rs:3218:5:3218:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
5400-
| main.rs:3219:5:3219:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
5401-
| main.rs:3219:20:3219:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
5402-
| main.rs:3219:41:3219:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
5403-
| main.rs:3235:5:3235:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
5399+
| main.rs:3218:9:3218:15 | Some(...) | | {EXTERNAL LOCATION} | Option |
5400+
| main.rs:3218:9:3218:15 | Some(...) | T | {EXTERNAL LOCATION} | i32 |
5401+
| main.rs:3218:9:3221:10 | ... .map(...) | | {EXTERNAL LOCATION} | Option |
5402+
| main.rs:3218:14:3218:14 | 1 | | {EXTERNAL LOCATION} | i32 |
5403+
| main.rs:3220:22:3220:26 | "{x}\\n" | | file://:0:0:0:0 | & |
5404+
| main.rs:3220:22:3220:26 | "{x}\\n" | &T | {EXTERNAL LOCATION} | str |
5405+
| main.rs:3220:22:3220:26 | FormatArgsExpr | | {EXTERNAL LOCATION} | Arguments |
5406+
| main.rs:3220:22:3220:26 | MacroExpr | | {EXTERNAL LOCATION} | Arguments |
5407+
| main.rs:3226:5:3226:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
5408+
| main.rs:3227:5:3227:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
5409+
| main.rs:3227:20:3227:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
5410+
| main.rs:3227:41:3227:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
5411+
| main.rs:3243:5:3243:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
54045412
testFailures

0 commit comments

Comments
 (0)