Skip to content

Commit e4d1b01

Browse files
committed
Rust: Add type inference test with function call to trait method
1 parent 16690cc commit e4d1b01

File tree

2 files changed

+1554
-1511
lines changed

2 files changed

+1554
-1511
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,32 @@ mod method_impl {
9090
}
9191
}
9292

93+
mod trait_impl {
94+
#[derive(Debug)]
95+
struct MyThing {
96+
field: bool,
97+
}
98+
99+
trait MyTrait<B> {
100+
fn trait_method(self) -> B;
101+
}
102+
103+
impl MyTrait<bool> for MyThing {
104+
// MyThing::trait_method
105+
fn trait_method(self) -> bool {
106+
self.field // $ fieldof=MyThing
107+
}
108+
}
109+
110+
pub fn f() {
111+
let x = MyThing { field: true };
112+
let a = x.trait_method(); // $ type=a:bool method=MyThing::trait_method
113+
114+
let y = MyThing { field: false };
115+
let b = MyTrait::trait_method(y); // $ type=b:bool MISSING: method=MyThing::trait_method
116+
}
117+
}
118+
93119
mod method_non_parametric_impl {
94120
#[derive(Debug)]
95121
struct MyThing<A> {

0 commit comments

Comments
 (0)