Skip to content

Commit f9a04bc

Browse files
committed
Rust: More type inference tests
1 parent 3c32880 commit f9a04bc

File tree

2 files changed

+591
-534
lines changed

2 files changed

+591
-534
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// This file contains tests for dereferencing with through the `Deref` trait.
22
use std::ops::Deref;
3+
use std::ops::DerefMut;
34

45
struct MyIntPointer {
56
value: i64,
@@ -27,6 +28,13 @@ impl<T> Deref for MySmartPointer<T> {
2728
}
2829
}
2930

31+
impl<T> DerefMut for MySmartPointer<T> {
32+
// MySmartPointer::deref_mut
33+
fn deref_mut(&mut self) -> &mut T {
34+
&mut self.value // $ fieldof=MySmartPointer
35+
}
36+
}
37+
3038
struct S<T>(T);
3139

3240
impl<T> S<T> {
@@ -102,6 +110,10 @@ fn implicit_dereference() {
102110

103111
let z = MySmartPointer { value: S(0i64) };
104112
let z_ = z.foo(); // $ MISSING: target=foo type=z_:TRef.i64
113+
114+
let v = Vec::new(); // $ target=new $ MISSING: type=x:T.i32
115+
let mut x = MySmartPointer { value: v };
116+
x.push(0); // $ MISSING: target=push
105117
}
106118

107119
mod implicit_deref_coercion_cycle {

0 commit comments

Comments
 (0)