Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared, type inference: Add inference for type parameters with constraints (base type mentions) #19102

Merged
merged 8 commits into from
Mar 28, 2025
24 changes: 20 additions & 4 deletions rust/ql/test/library-tests/type-inference/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,16 @@ mod function_trait_bounds {
}
}

// Type parameter with bound occurs in the root of a parameter type.
fn call_trait_m1<T1, T2: MyTrait<T1>>(x: T2) -> T1 {
x.m1()
}

// Type parameter with bound occurs nested within another type.
fn call_trait_thing_m1<T1, T2: MyTrait<T1>>(x: MyThing<T2>) -> T1 {
x.a.m1()
}

impl<T> MyTrait<T> for MyThing<T> {
fn m1(self) -> T {
self.a
Expand All @@ -298,11 +304,21 @@ mod function_trait_bounds {
println!("{:?}", x.m2());
println!("{:?}", y.m2());

let x = MyThing { a: S1 };
let y = MyThing { a: S2 };
let x2 = MyThing { a: S1 };
let y2 = MyThing { a: S2 };

println!("{:?}", call_trait_m1(x)); // missing
println!("{:?}", call_trait_m1(y)); // missing
println!("{:?}", call_trait_m1(x2));
println!("{:?}", call_trait_m1(y2));

let x3 = MyThing {
a: MyThing { a: S1 },
};
let y3 = MyThing {
a: MyThing { a: S2 },
};

println!("{:?}", call_trait_thing_m1(x3));
println!("{:?}", call_trait_thing_m1(y3));
}
}

Expand Down
Loading
Loading