Skip to content

Commit f4ff815

Browse files
committed
Rust: Add additional type inference tests
1 parent 7bd1612 commit f4ff815

File tree

2 files changed

+679
-603
lines changed

2 files changed

+679
-603
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,16 @@ mod method_supertraits {
784784

785785
impl<T> MyTrait3<T> for MyThing2<T> {}
786786

787+
fn call_trait_m1<T1, T2: MyTrait1<T1>>(x: T2) -> T1 {
788+
x.m1() // $ method=MyTrait1::m1
789+
}
790+
791+
fn type_param_trait_to_supertrait<T: MyTrait3<S1>>(x: T) {
792+
// Test that `MyTrait3` is a subtrait of `MyTrait1<MyThing<S1>>`
793+
let a = x.m1(); // $ method=MyTrait1::m1 type=a:MyThing type=a:A.S1
794+
println!("{:?}", a);
795+
}
796+
787797
pub fn f() {
788798
let x = MyThing { a: S1 };
789799
let y = MyThing { a: S2 };
@@ -802,6 +812,12 @@ mod method_supertraits {
802812

803813
println!("{:?}", x.m3()); // $ method=m3 type=x.m3():S1
804814
println!("{:?}", y.m3()); // $ method=m3 type=y.m3():S2
815+
816+
let x = MyThing { a: S1 };
817+
let s = call_trait_m1(x); // $ type=s:S1
818+
819+
let x = MyThing2 { a: S2 };
820+
let s = call_trait_m1(x); // $ type=s:MyThing type=s:A.S2
805821
}
806822
}
807823

@@ -1054,6 +1070,12 @@ mod method_call_type_conversion {
10541070
let x6 = &S(S2);
10551071
// explicit dereference
10561072
println!("{:?}", (*x6).m1()); // $ method=m1
1073+
1074+
let x7 = S(&S2);
1075+
// Non-implicit dereference with nested borrow in order to test that the
1076+
// implicit dereference handling doesn't affect nested borrows.
1077+
let t = x7.m1(); // $ method=m1 type=t:& type=t:&T.S2
1078+
println!("{:?}", x7);
10571079
}
10581080
}
10591081

0 commit comments

Comments
 (0)