Skip to content

Commit 8f5d9d7

Browse files
committed
Rust: Add type inference tests for borrowing
1 parent d659d40 commit 8f5d9d7

File tree

2 files changed

+1074
-1036
lines changed

2 files changed

+1074
-1036
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,17 @@ mod implicit_self_borrow {
11541154
}
11551155

11561156
mod borrowed_typed {
1157+
#[derive(Debug, Copy, Clone, Default)]
1158+
struct MyFlag {
1159+
bool: bool,
1160+
}
1161+
1162+
impl MyFlag {
1163+
fn flip(&mut self) {
1164+
self.bool = !self.bool; // $ fieldof=MyFlag method=not
1165+
}
1166+
}
1167+
11571168
struct S;
11581169

11591170
impl S {
@@ -1179,6 +1190,14 @@ mod borrowed_typed {
11791190
x.f1(); // $ method=f1
11801191
x.f2(); // $ method=f2
11811192
S::f3(&x);
1193+
1194+
let n = **&&true; // $ MISSING: type=n:bool
1195+
1196+
// In this example the type of `flag` must be inferred at the call to
1197+
// `flip` and flow through the borrow in the argument.
1198+
let mut flag = Default::default();
1199+
MyFlag::flip(&mut flag);
1200+
println!("{:?}", flag); // $ MISSING: type=flag:MyFlag
11821201
}
11831202
}
11841203

0 commit comments

Comments
 (0)