Skip to content

Commit b6d5225

Browse files
committed
Rust: Add more type inference tests
1 parent d10002c commit b6d5225

File tree

2 files changed

+2142
-2006
lines changed

2 files changed

+2142
-2006
lines changed

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,14 @@ mod type_aliases {
10301030
println!("{:?}", x);
10311031
}
10321032

1033+
struct S4<T41, T42>(T41, T42);
1034+
1035+
struct S5<T5>(T5);
1036+
1037+
type S6<T6> = S4<T6, S5<T6>>;
1038+
1039+
type S7<T7> = Result<S6<T7>, S1>;
1040+
10331041
pub fn f() {
10341042
// Type can be inferred from the constructor
10351043
let p1: MyPair = PairOption::PairBoth(S1, S2);
@@ -1048,6 +1056,8 @@ mod type_aliases {
10481056
println!("{:?}", p3);
10491057

10501058
g(PairOption::PairSnd(PairOption::PairSnd(S3)));
1059+
1060+
let x: S7<S2>; // $ type=x:Result $ type=x:E.S1 $ type=x:T.S4 $ type=x:T.T41.S2 $ MISSING: type=x:T.T42.S5 $ MISSING: type=x:T.T42.T5.S2
10511061
}
10521062
}
10531063

@@ -2157,6 +2167,57 @@ mod loops {
21572167

21582168
mod dereference;
21592169

2170+
mod explicit_type_args {
2171+
struct S1<T>(T);
2172+
2173+
#[derive(Default)]
2174+
struct S2;
2175+
2176+
impl<T: Default> S1<T> {
2177+
fn assoc_fun() -> Option<Self> {
2178+
None
2179+
}
2180+
2181+
fn default() -> Self {
2182+
S1(T::default())
2183+
}
2184+
2185+
fn method(self) -> Self {
2186+
self
2187+
}
2188+
}
2189+
2190+
type S3 = S1<S2>;
2191+
2192+
struct S4<T4 = S2>(T4);
2193+
2194+
struct S5<T5 = S2> {
2195+
field: T5,
2196+
}
2197+
2198+
pub fn f() {
2199+
let x1: Option<S1<S2>> = S1::assoc_fun(); // $ type=x1:T.T.S2
2200+
let x2 = S1::<S2>::assoc_fun(); // $ MISSING: type=x2:T.T.S2
2201+
let x3 = S3::assoc_fun(); // $ MISSING: type=x3:T.T.S2
2202+
let x4 = S1::<S2>::method(S1::default()); // $ MISSING: method=method type=x4:T.S2
2203+
let x5 = S3::method(S1::default()); // $ MISSING: method=method type=x5:T.S2
2204+
let x6 = S4::<S2>(Default::default()); // $ type=x6:T4.S2
2205+
let x7 = S4(S2); // $ type=x7:T4.S2
2206+
let x8 = S4(0); // $ type=x8:T4.i32
2207+
let x9 = S4(S2::default()); // $ type=x9:T4.S2
2208+
let x10 = S5::<S2> // $ type=x10:T5.S2
2209+
{
2210+
field: Default::default(),
2211+
};
2212+
let x11 = S5 { field: S2 }; // $ type=x11:T5.S2
2213+
let x12 = S5 { field: 0 }; // $ type=x12:T5.i32
2214+
let x13 = S5 // $ type=x13:T5.S2
2215+
{
2216+
field: S2::default(),
2217+
};
2218+
}
2219+
}
2220+
21602221
fn main() {
21612222
field_access::f();
21622223
method_impl::f();

0 commit comments

Comments
 (0)