Skip to content

Commit 56a4d1c

Browse files
committed
Rust: Add more type inference tests
1 parent 1ccea7f commit 56a4d1c

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,37 @@ mod method_determined_by_argument_type {
19221922

19231923
mod dereference;
19241924

1925+
mod explicit_type_args {
1926+
struct S1<T>(T);
1927+
1928+
#[derive(Default)]
1929+
struct S2;
1930+
1931+
impl<T : Default> S1<T> {
1932+
fn assoc_fun() -> Option<Self> {
1933+
None
1934+
}
1935+
1936+
fn default() -> Self {
1937+
S1(T::default())
1938+
}
1939+
1940+
fn method(self) -> Self {
1941+
self
1942+
}
1943+
}
1944+
1945+
type S3 = S1<S2>;
1946+
1947+
pub fn f() {
1948+
let x1 : Option<S1<S2>> = S1::assoc_fun(); // $ type=x1:T.T.S2
1949+
let x2 = S1::<S2>::assoc_fun(); // $ MISSING: type=x2:T.T.S2
1950+
let x3 = S3::assoc_fun(); // $ MISSING: type=x3:T.T.S2
1951+
let x4 = S1::<S2>::method(S1::default()); // $ MISSING: method=method type=x4:T.S2
1952+
let x5 = S3::method(S1::default()); // $ MISSING: method=method type=x5:T.S2
1953+
}
1954+
}
1955+
19251956
fn main() {
19261957
field_access::f();
19271958
method_impl::f();

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

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,9 +2964,42 @@ inferType
29642964
| main.rs:1919:9:1919:9 | x | | {EXTERNAL LOCATION} | i64 |
29652965
| main.rs:1919:9:1919:22 | x.my_add(...) | | {EXTERNAL LOCATION} | i64 |
29662966
| main.rs:1919:18:1919:21 | true | | {EXTERNAL LOCATION} | bool |
2967-
| main.rs:1927:5:1927:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
2968-
| main.rs:1928:5:1928:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
2969-
| main.rs:1928:20:1928:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
2970-
| main.rs:1928:41:1928:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
2971-
| main.rs:1944:5:1944:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
2967+
| main.rs:1929:12:1929:13 | S2 | | main.rs:1928:5:1929:14 | S2 |
2968+
| main.rs:1929:12:1929:13 | { ... } | | main.rs:1928:5:1929:14 | S2 |
2969+
| main.rs:1932:40:1934:9 | { ... } | | {EXTERNAL LOCATION} | Option |
2970+
| main.rs:1932:40:1934:9 | { ... } | T | main.rs:1926:5:1926:20 | S1 |
2971+
| main.rs:1932:40:1934:9 | { ... } | T.T | main.rs:1931:10:1931:20 | T |
2972+
| main.rs:1933:13:1933:16 | None | | {EXTERNAL LOCATION} | Option |
2973+
| main.rs:1933:13:1933:16 | None | T | main.rs:1926:5:1926:20 | S1 |
2974+
| main.rs:1933:13:1933:16 | None | T.T | main.rs:1931:10:1931:20 | T |
2975+
| main.rs:1936:30:1938:9 | { ... } | | main.rs:1926:5:1926:20 | S1 |
2976+
| main.rs:1936:30:1938:9 | { ... } | T | main.rs:1931:10:1931:20 | T |
2977+
| main.rs:1937:13:1937:28 | S1(...) | | main.rs:1926:5:1926:20 | S1 |
2978+
| main.rs:1937:13:1937:28 | S1(...) | T | main.rs:1931:10:1931:20 | T |
2979+
| main.rs:1937:16:1937:27 | ...::default(...) | | main.rs:1931:10:1931:20 | T |
2980+
| main.rs:1940:19:1940:22 | SelfParam | | main.rs:1926:5:1926:20 | S1 |
2981+
| main.rs:1940:19:1940:22 | SelfParam | T | main.rs:1931:10:1931:20 | T |
2982+
| main.rs:1940:33:1942:9 | { ... } | | main.rs:1926:5:1926:20 | S1 |
2983+
| main.rs:1940:33:1942:9 | { ... } | T | main.rs:1931:10:1931:20 | T |
2984+
| main.rs:1941:13:1941:16 | self | | main.rs:1926:5:1926:20 | S1 |
2985+
| main.rs:1941:13:1941:16 | self | T | main.rs:1931:10:1931:20 | T |
2986+
| main.rs:1948:13:1948:14 | x1 | | {EXTERNAL LOCATION} | Option |
2987+
| main.rs:1948:13:1948:14 | x1 | T | main.rs:1926:5:1926:20 | S1 |
2988+
| main.rs:1948:13:1948:14 | x1 | T.T | main.rs:1928:5:1929:14 | S2 |
2989+
| main.rs:1948:35:1948:49 | ...::assoc_fun(...) | | {EXTERNAL LOCATION} | Option |
2990+
| main.rs:1948:35:1948:49 | ...::assoc_fun(...) | T | main.rs:1926:5:1926:20 | S1 |
2991+
| main.rs:1948:35:1948:49 | ...::assoc_fun(...) | T.T | main.rs:1928:5:1929:14 | S2 |
2992+
| main.rs:1949:13:1949:14 | x2 | | {EXTERNAL LOCATION} | Option |
2993+
| main.rs:1949:13:1949:14 | x2 | T | main.rs:1926:5:1926:20 | S1 |
2994+
| main.rs:1949:18:1949:38 | ...::assoc_fun(...) | | {EXTERNAL LOCATION} | Option |
2995+
| main.rs:1949:18:1949:38 | ...::assoc_fun(...) | T | main.rs:1926:5:1926:20 | S1 |
2996+
| main.rs:1951:13:1951:14 | x4 | | main.rs:1926:5:1926:20 | S1 |
2997+
| main.rs:1951:18:1951:48 | ...::method(...) | | main.rs:1926:5:1926:20 | S1 |
2998+
| main.rs:1951:35:1951:47 | ...::default(...) | | main.rs:1926:5:1926:20 | S1 |
2999+
| main.rs:1952:29:1952:41 | ...::default(...) | | main.rs:1926:5:1926:20 | S1 |
3000+
| main.rs:1958:5:1958:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
3001+
| main.rs:1959:5:1959:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
3002+
| main.rs:1959:20:1959:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
3003+
| main.rs:1959:41:1959:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
3004+
| main.rs:1975:5:1975:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
29723005
testFailures

0 commit comments

Comments
 (0)