Skip to content

Commit 519905e

Browse files
committed
Rust: type inference: add test for closure argument
1 parent 32e7a9d commit 519905e

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,15 @@ pub mod pattern_matching_experimental {
23782378
}
23792379
}
23802380

2381+
mod closures {
2382+
pub fn f() {
2383+
Some(1).map(|x| {
2384+
let x = x; // $ MISSING: type=x:i32
2385+
println!("{x}");
2386+
}); // $ method=map
2387+
}
2388+
}
2389+
23812390
fn main() {
23822391
field_access::f(); // $ method=f
23832392
method_impl::f(); // $ method=f
@@ -2408,4 +2417,5 @@ fn main() {
24082417
dereference::test(); // $ method=test
24092418
pattern_matching::test_all_patterns(); // $ method=test_all_patterns
24102419
pattern_matching_experimental::box_patterns(); // $ method=box_patterns
2420+
closures::f() // $ method=f
24112421
}

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,11 +4112,19 @@ inferType
41124112
| main.rs:2375:26:2375:43 | "Nested boxed: {}\\n" | &T | {EXTERNAL LOCATION} | str |
41134113
| main.rs:2375:26:2375:59 | FormatArgsExpr | | {EXTERNAL LOCATION} | Arguments |
41144114
| main.rs:2375:26:2375:59 | MacroExpr | | {EXTERNAL LOCATION} | Arguments |
4115-
| main.rs:2383:5:2383:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
4116-
| main.rs:2384:5:2384:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
4117-
| main.rs:2384:20:2384:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
4118-
| main.rs:2384:41:2384:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
4119-
| main.rs:2400:5:2400:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
4115+
| main.rs:2383:9:2383:15 | Some(...) | | {EXTERNAL LOCATION} | Option |
4116+
| main.rs:2383:9:2383:15 | Some(...) | T | {EXTERNAL LOCATION} | i32 |
4117+
| main.rs:2383:9:2386:10 | ... .map(...) | | {EXTERNAL LOCATION} | Option |
4118+
| main.rs:2383:14:2383:14 | 1 | | {EXTERNAL LOCATION} | i32 |
4119+
| main.rs:2385:22:2385:26 | "{x}\\n" | | file://:0:0:0:0 | & |
4120+
| main.rs:2385:22:2385:26 | "{x}\\n" | &T | {EXTERNAL LOCATION} | str |
4121+
| main.rs:2385:22:2385:26 | FormatArgsExpr | | {EXTERNAL LOCATION} | Arguments |
4122+
| main.rs:2385:22:2385:26 | MacroExpr | | {EXTERNAL LOCATION} | Arguments |
4123+
| main.rs:2392:5:2392:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
4124+
| main.rs:2393:5:2393:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
4125+
| main.rs:2393:20:2393:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
4126+
| main.rs:2393:41:2393:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
4127+
| main.rs:2409:5:2409:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
41204128
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
41214129
| pattern_matching.rs:14:9:14:13 | value | | {EXTERNAL LOCATION} | Option |
41224130
| pattern_matching.rs:14:9:14:13 | value | T | {EXTERNAL LOCATION} | i32 |

0 commit comments

Comments
 (0)