Skip to content

Commit 8685c44

Browse files
committed
Rust: Add more type inference tests
1 parent 3324d07 commit 8685c44

2 files changed

Lines changed: 7480 additions & 7437 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ mod method_non_parametric_trait_impl {
264264
}
265265
}
266266

267+
trait MyTrait2<B> {
268+
fn m3(self) -> B;
269+
}
270+
267271
trait MyProduct<A, B> {
268272
// MyProduct::fst
269273
fn fst(self) -> A;
@@ -275,6 +279,10 @@ mod method_non_parametric_trait_impl {
275279
x.m1() // $ target=m1
276280
}
277281

282+
fn call_trait_m1_trait2_m3<T1, T2: MyTrait<T1>, T3: MyTrait2<T2>>(x: T3) -> T1 {
283+
x.m3().m1() // $ target=m1 target=m3
284+
}
285+
278286
impl MyTrait<S1> for MyThing<S1> {
279287
// MyThing<S1>::m1
280288
fn m1(self) -> S1 {
@@ -289,6 +297,13 @@ mod method_non_parametric_trait_impl {
289297
}
290298
}
291299

300+
impl MyTrait2<MyThing<S1>> for MyThing<S2> {
301+
// MyThing<S2>::m3
302+
fn m3(self) -> MyThing<S1> {
303+
MyThing { a: S1 }
304+
}
305+
}
306+
292307
// Implementation where the type parameter `TD` only occurs in the
293308
// implemented trait and not the implementing type.
294309
impl<TD> MyTrait<TD> for MyThing<S3>
@@ -453,6 +468,8 @@ mod method_non_parametric_trait_impl {
453468
let thing = MyThing { a: S1 };
454469
let i = thing.convert_to(); // $ type=i:S1 target=T::convert_to
455470
let j = convert_to(thing); // $ target=convert_to $ MISSING: type=j:S1 -- the blanket implementation `impl<T: MyTrait<S1>> ConvertTo<S1> for T` is currently not included in the constraint analysis
471+
472+
let x = call_trait_m1_trait2_m3(MyThing { a: S2 }); // $ target=call_trait_m1_trait2_m3 $ MISSING: type=x:S1
456473
}
457474
}
458475

0 commit comments

Comments
 (0)