From dfbdd2bd029f46a30c734e75ee3f7e43a233dd14 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 9 Jul 2025 16:53:52 +0100 Subject: [PATCH 1/3] Rust: Add type inference test cases for tuples. --- .../test/library-tests/type-inference/main.rs | 29 +++++++++++++++++++ .../type-inference/type-inference.expected | 13 +++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/rust/ql/test/library-tests/type-inference/main.rs b/rust/ql/test/library-tests/type-inference/main.rs index 7535df34ee81..6e5374deebb5 100644 --- a/rust/ql/test/library-tests/type-inference/main.rs +++ b/rust/ql/test/library-tests/type-inference/main.rs @@ -2228,6 +2228,33 @@ mod explicit_type_args { } } +mod tuples { + struct S1 { + } + + impl S1 { + fn get_pair() -> (S1, S1) { (S1 {}, S1 {}) } + fn foo(self) { } + } + + pub fn f() { + let a = S1::get_pair(); // $ method=get_pair MISSING: type=a:? + let mut b = S1::get_pair(); // $ method=get_pair MISSING: type=b:? + let (c, d) = S1::get_pair(); // $ method=get_pair MISSING: type=c:? type=d:? + let (mut e, f) = S1::get_pair(); // $ method=get_pair MISSING: type=e: type=f: + let (mut g, mut h) = S1::get_pair(); // $ method=get_pair MISSING: type=g:? type=h:? + + a.0.foo(); // $ MISSING: method=foo + b.1.foo(); // $ MISSING: method=foo + c.foo(); // $ MISSING: method=foo + d.foo(); // $ MISSING: method=foo + e.foo(); // $ MISSING: method=foo + f.foo(); // $ MISSING: method=foo + g.foo(); // $ MISSING: method=foo + h.foo(); // $ MISSING: method=foo + } +} + fn main() { field_access::f(); // $ method=f method_impl::f(); // $ method=f @@ -2251,7 +2278,9 @@ fn main() { impl_trait::f(); // $ method=f indexers::f(); // $ method=f loops::f(); // $ method=f + explicit_type_args::f(); // $ method=f macros::f(); // $ method=f method_determined_by_argument_type::f(); // $ method=f + tuples::f(); // $ method=f dereference::test(); // $ method=test } diff --git a/rust/ql/test/library-tests/type-inference/type-inference.expected b/rust/ql/test/library-tests/type-inference/type-inference.expected index cf14df7e9af7..041c19c27efb 100644 --- a/rust/ql/test/library-tests/type-inference/type-inference.expected +++ b/rust/ql/test/library-tests/type-inference/type-inference.expected @@ -3636,9 +3636,12 @@ inferType | main.rs:2224:19:2227:9 | S5 {...} | | main.rs:2204:5:2206:5 | S5 | | main.rs:2224:19:2227:9 | S5 {...} | T5 | main.rs:2183:5:2184:14 | S2 | | main.rs:2226:20:2226:32 | ...::default(...) | | main.rs:2183:5:2184:14 | S2 | -| main.rs:2233:5:2233:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo | -| main.rs:2234:5:2234:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo | -| main.rs:2234:20:2234:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo | -| main.rs:2234:41:2234:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo | -| main.rs:2250:5:2250:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future | +| main.rs:2236:38:2236:42 | S1 {...} | | main.rs:2232:5:2233:5 | S1 | +| main.rs:2236:45:2236:49 | S1 {...} | | main.rs:2232:5:2233:5 | S1 | +| main.rs:2237:16:2237:19 | SelfParam | | main.rs:2232:5:2233:5 | S1 | +| main.rs:2260:5:2260:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo | +| main.rs:2261:5:2261:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo | +| main.rs:2261:20:2261:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo | +| main.rs:2261:41:2261:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo | +| main.rs:2277:5:2277:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future | testFailures From 6c9c8904d786e7ff8f7d7fcfb4e7978eb4f08d56 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 9 Jul 2025 18:43:33 +0100 Subject: [PATCH 2/3] Rust: Autoformat. --- rust/ql/test/library-tests/type-inference/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rust/ql/test/library-tests/type-inference/main.rs b/rust/ql/test/library-tests/type-inference/main.rs index 6e5374deebb5..8dcff4ede6fc 100644 --- a/rust/ql/test/library-tests/type-inference/main.rs +++ b/rust/ql/test/library-tests/type-inference/main.rs @@ -2229,12 +2229,13 @@ mod explicit_type_args { } mod tuples { - struct S1 { - } + struct S1 {} impl S1 { - fn get_pair() -> (S1, S1) { (S1 {}, S1 {}) } - fn foo(self) { } + fn get_pair() -> (S1, S1) { + (S1 {}, S1 {}) + } + fn foo(self) {} } pub fn f() { From 36720ca4dd516fb7bcefd74ba66e9995353e6574 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 9 Jul 2025 21:52:23 +0100 Subject: [PATCH 3/3] Rust: Update .expected file after autoformat. --- .../type-inference/type-inference.expected | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rust/ql/test/library-tests/type-inference/type-inference.expected b/rust/ql/test/library-tests/type-inference/type-inference.expected index 041c19c27efb..6d603dccf2ce 100644 --- a/rust/ql/test/library-tests/type-inference/type-inference.expected +++ b/rust/ql/test/library-tests/type-inference/type-inference.expected @@ -3636,12 +3636,12 @@ inferType | main.rs:2224:19:2227:9 | S5 {...} | | main.rs:2204:5:2206:5 | S5 | | main.rs:2224:19:2227:9 | S5 {...} | T5 | main.rs:2183:5:2184:14 | S2 | | main.rs:2226:20:2226:32 | ...::default(...) | | main.rs:2183:5:2184:14 | S2 | -| main.rs:2236:38:2236:42 | S1 {...} | | main.rs:2232:5:2233:5 | S1 | -| main.rs:2236:45:2236:49 | S1 {...} | | main.rs:2232:5:2233:5 | S1 | -| main.rs:2237:16:2237:19 | SelfParam | | main.rs:2232:5:2233:5 | S1 | -| main.rs:2260:5:2260:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo | -| main.rs:2261:5:2261:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo | -| main.rs:2261:20:2261:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo | -| main.rs:2261:41:2261:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo | -| main.rs:2277:5:2277:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future | +| main.rs:2236:14:2236:18 | S1 {...} | | main.rs:2232:5:2232:16 | S1 | +| main.rs:2236:21:2236:25 | S1 {...} | | main.rs:2232:5:2232:16 | S1 | +| main.rs:2238:16:2238:19 | SelfParam | | main.rs:2232:5:2232:16 | S1 | +| main.rs:2261:5:2261:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo | +| main.rs:2262:5:2262:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo | +| main.rs:2262:20:2262:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo | +| main.rs:2262:41:2262:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo | +| main.rs:2278:5:2278:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future | testFailures