Skip to content

Commit 3b474cb

Browse files
committed
Rust: Add type inference regression test
1 parent ff41917 commit 3b474cb

File tree

2 files changed

+254
-0
lines changed

2 files changed

+254
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,35 @@ mod regression2 {
7474
let x = s1 - &s2; // $ target=S1SubRefS2 type=x:S2
7575
}
7676
}
77+
78+
mod regression3 {
79+
trait SomeTrait {}
80+
81+
trait MyFrom<T> {
82+
fn my_from(value: T) -> Self;
83+
}
84+
85+
impl<T> MyFrom<T> for T {
86+
fn my_from(s: T) -> Self {
87+
s
88+
}
89+
}
90+
91+
impl<T> MyFrom<T> for Option<T> {
92+
fn my_from(val: T) -> Option<T> {
93+
Some(val)
94+
}
95+
}
96+
97+
pub struct S<Ts>(Ts);
98+
99+
pub fn f<T1, T2>(x: T2) -> T2
100+
where
101+
T2: SomeTrait + MyFrom<Option<T1>>,
102+
Option<T1>: MyFrom<T2>,
103+
{
104+
let y = MyFrom::my_from(x); // $ target=my_from
105+
let z = MyFrom::my_from(y); // $ target=my_from
106+
z
107+
}
108+
}

0 commit comments

Comments
 (0)