Skip to content

Commit a96d3d7

Browse files
committed
Rust: Add more type inference tests
1 parent ac13f40 commit a96d3d7

File tree

2 files changed

+372
-321
lines changed

2 files changed

+372
-321
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
@@ -2295,6 +2295,10 @@ mod explicit_type_args {
22952295
field: T5,
22962296
}
22972297

2298+
fn foo<T>(x: T) -> T {
2299+
x
2300+
}
2301+
22982302
pub fn f() {
22992303
let x1: Option<S1<S2>> = S1::assoc_fun(); // $ type=x1:T.T.S2 method=assoc_fun
23002304
let x2 = S1::<S2>::assoc_fun(); // $ type=x2:T.T.S2 method=assoc_fun
@@ -2315,6 +2319,7 @@ mod explicit_type_args {
23152319
{
23162320
field: S2::default(), // $ method=default
23172321
};
2322+
let x14 = foo::<i32>(Default::default()); // $ type=x14:i32 method=default method=foo
23182323
}
23192324
}
23202325

@@ -2457,6 +2462,27 @@ pub mod pattern_matching {
24572462
_ => (),
24582463
}
24592464

2465+
let opt1 = Some(Default::default()); // $ MISSING: type=opt1:T.i32 method=default
2466+
#[rustfmt::skip]
2467+
let _ = if let Some::<i32>(x) = opt1
2468+
{
2469+
x; // $ MISSING: type=x:i32
2470+
};
2471+
2472+
let opt2 = Some(Default::default()); // $ MISSING: type=opt2:T.i32 method=default
2473+
#[rustfmt::skip]
2474+
let _ = if let Option::Some::<i32>(x) = opt2
2475+
{
2476+
x; // $ MISSING: type=x:i32
2477+
};
2478+
2479+
let opt3 = Some(Default::default()); // $ type=opt3:T.i32 method=default
2480+
#[rustfmt::skip]
2481+
let _ = if let Option::<i32>::Some(x) = opt3
2482+
{
2483+
x; // $ type=x:i32
2484+
};
2485+
24602486
None
24612487
}
24622488
}

0 commit comments

Comments
 (0)