Skip to content

Commit a0c6df3

Browse files
committed
Rust: Add another type inference test
1 parent bcc65e1 commit a0c6df3

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
multipleMethodCallTargets
2+
| main.rs:945:26:945:31 | x.m1() | main.rs:931:9:933:9 | fn m1 |
3+
| main.rs:945:26:945:31 | x.m1() | main.rs:938:9:940:9 | fn m1 |

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,33 @@ mod borrowed_typed {
919919
}
920920
}
921921

922+
mod impl_overlap {
923+
#[derive(Debug)]
924+
struct S1;
925+
926+
trait MyTrait {
927+
fn m1(self) -> S1;
928+
}
929+
930+
impl MyTrait for S1 {
931+
fn m1(self) -> S1 {
932+
panic!("not called");
933+
}
934+
}
935+
936+
#[rustfmt::skip]
937+
impl S1 {
938+
fn m1(self) -> S1 { // target
939+
self
940+
}
941+
}
942+
943+
pub fn f() {
944+
let x = S1;
945+
println!("{:?}", x.m1()); // $ method=target
946+
}
947+
}
948+
922949
fn main() {
923950
field_access::f();
924951
method_impl::f();
@@ -935,4 +962,5 @@ fn main() {
935962
trait_implicit_self_borrow::f();
936963
implicit_self_borrow::f();
937964
borrowed_typed::f();
965+
impl_overlap::f();
938966
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
testFailures
2+
| main.rs:945:26:945:31 | x.m1() | Unexpected result: method=m1 |
23
inferType
34
| loop/main.rs:7:12:7:15 | SelfParam | | loop/main.rs:6:1:8:1 | Self [trait T1] |
45
| loop/main.rs:11:12:11:15 | SelfParam | | loop/main.rs:10:1:14:1 | Self [trait T2] |
@@ -1005,7 +1006,17 @@ inferType
10051006
| main.rs:918:15:918:16 | &x | | file://:0:0:0:0 | & |
10061007
| main.rs:918:15:918:16 | &x | &T | main.rs:894:5:894:13 | S |
10071008
| main.rs:918:16:918:16 | x | | main.rs:894:5:894:13 | S |
1008-
| main.rs:924:5:924:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
1009-
| main.rs:925:5:925:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
1010-
| main.rs:925:20:925:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
1011-
| main.rs:925:41:925:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
1009+
| main.rs:927:15:927:18 | SelfParam | | main.rs:926:5:928:5 | Self [trait MyTrait] |
1010+
| main.rs:931:15:931:18 | SelfParam | | main.rs:923:5:924:14 | S1 |
1011+
| main.rs:931:27:933:9 | { ... } | | main.rs:923:5:924:14 | S1 |
1012+
| main.rs:938:15:938:18 | SelfParam | | main.rs:923:5:924:14 | S1 |
1013+
| main.rs:938:27:940:9 | { ... } | | main.rs:923:5:924:14 | S1 |
1014+
| main.rs:939:13:939:16 | self | | main.rs:923:5:924:14 | S1 |
1015+
| main.rs:944:13:944:13 | x | | main.rs:923:5:924:14 | S1 |
1016+
| main.rs:944:17:944:18 | S1 | | main.rs:923:5:924:14 | S1 |
1017+
| main.rs:945:26:945:26 | x | | main.rs:923:5:924:14 | S1 |
1018+
| main.rs:945:26:945:31 | x.m1() | | main.rs:923:5:924:14 | S1 |
1019+
| main.rs:951:5:951:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
1020+
| main.rs:952:5:952:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
1021+
| main.rs:952:20:952:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
1022+
| main.rs:952:41:952:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |

0 commit comments

Comments
 (0)