Skip to content

Commit b04fb36

Browse files
committed
Rust: Add more type inference tests
1 parent 12cda86 commit b04fb36

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
@@ -3967,11 +3967,44 @@ inferType
39673967
| main.rs:1919:9:1919:9 | x | | {EXTERNAL LOCATION} | i64 |
39683968
| main.rs:1919:9:1919:22 | x.my_add(...) | | {EXTERNAL LOCATION} | i64 |
39693969
| main.rs:1919:18:1919:21 | true | | {EXTERNAL LOCATION} | bool |
3970-
| main.rs:1927:5:1927:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
3971-
| main.rs:1928:5:1928:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
3972-
| main.rs:1928:20:1928:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
3973-
| main.rs:1928:41:1928:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
3974-
| main.rs:1944:5:1944:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
3970+
| main.rs:1929:12:1929:13 | S2 | | main.rs:1928:5:1929:14 | S2 |
3971+
| main.rs:1929:12:1929:13 | { ... } | | main.rs:1928:5:1929:14 | S2 |
3972+
| main.rs:1932:40:1934:9 | { ... } | | {EXTERNAL LOCATION} | Option |
3973+
| main.rs:1932:40:1934:9 | { ... } | T | main.rs:1926:5:1926:20 | S1 |
3974+
| main.rs:1932:40:1934:9 | { ... } | T.T | main.rs:1931:10:1931:20 | T |
3975+
| main.rs:1933:13:1933:16 | None | | {EXTERNAL LOCATION} | Option |
3976+
| main.rs:1933:13:1933:16 | None | T | main.rs:1926:5:1926:20 | S1 |
3977+
| main.rs:1933:13:1933:16 | None | T.T | main.rs:1931:10:1931:20 | T |
3978+
| main.rs:1936:30:1938:9 | { ... } | | main.rs:1926:5:1926:20 | S1 |
3979+
| main.rs:1936:30:1938:9 | { ... } | T | main.rs:1931:10:1931:20 | T |
3980+
| main.rs:1937:13:1937:28 | S1(...) | | main.rs:1926:5:1926:20 | S1 |
3981+
| main.rs:1937:13:1937:28 | S1(...) | T | main.rs:1931:10:1931:20 | T |
3982+
| main.rs:1937:16:1937:27 | ...::default(...) | | main.rs:1931:10:1931:20 | T |
3983+
| main.rs:1940:19:1940:22 | SelfParam | | main.rs:1926:5:1926:20 | S1 |
3984+
| main.rs:1940:19:1940:22 | SelfParam | T | main.rs:1931:10:1931:20 | T |
3985+
| main.rs:1940:33:1942:9 | { ... } | | main.rs:1926:5:1926:20 | S1 |
3986+
| main.rs:1940:33:1942:9 | { ... } | T | main.rs:1931:10:1931:20 | T |
3987+
| main.rs:1941:13:1941:16 | self | | main.rs:1926:5:1926:20 | S1 |
3988+
| main.rs:1941:13:1941:16 | self | T | main.rs:1931:10:1931:20 | T |
3989+
| main.rs:1948:13:1948:14 | x1 | | {EXTERNAL LOCATION} | Option |
3990+
| main.rs:1948:13:1948:14 | x1 | T | main.rs:1926:5:1926:20 | S1 |
3991+
| main.rs:1948:13:1948:14 | x1 | T.T | main.rs:1928:5:1929:14 | S2 |
3992+
| main.rs:1948:35:1948:49 | ...::assoc_fun(...) | | {EXTERNAL LOCATION} | Option |
3993+
| main.rs:1948:35:1948:49 | ...::assoc_fun(...) | T | main.rs:1926:5:1926:20 | S1 |
3994+
| main.rs:1948:35:1948:49 | ...::assoc_fun(...) | T.T | main.rs:1928:5:1929:14 | S2 |
3995+
| main.rs:1949:13:1949:14 | x2 | | {EXTERNAL LOCATION} | Option |
3996+
| main.rs:1949:13:1949:14 | x2 | T | main.rs:1926:5:1926:20 | S1 |
3997+
| main.rs:1949:18:1949:38 | ...::assoc_fun(...) | | {EXTERNAL LOCATION} | Option |
3998+
| main.rs:1949:18:1949:38 | ...::assoc_fun(...) | T | main.rs:1926:5:1926:20 | S1 |
3999+
| main.rs:1951:13:1951:14 | x4 | | main.rs:1926:5:1926:20 | S1 |
4000+
| main.rs:1951:18:1951:48 | ...::method(...) | | main.rs:1926:5:1926:20 | S1 |
4001+
| main.rs:1951:35:1951:47 | ...::default(...) | | main.rs:1926:5:1926:20 | S1 |
4002+
| main.rs:1952:29:1952:41 | ...::default(...) | | main.rs:1926:5:1926:20 | S1 |
4003+
| main.rs:1958:5:1958:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
4004+
| main.rs:1959:5:1959:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
4005+
| main.rs:1959:20:1959:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
4006+
| main.rs:1959:41:1959:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
4007+
| main.rs:1975:5:1975:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
39754008
testFailures
39764009
| main.rs:2:5:2:20 | f.write_str(...) | Unexpected result: method=write_str |
39774010
| main.rs:5:5:5:20 | f.debug_struct(...) | Unexpected result: method=debug_struct |

0 commit comments

Comments
 (0)