Rust: Add type inference tests for borrowing

This commit is contained in:
Simon Friis Vindum
2025-06-11 08:38:30 +02:00
parent d659d40d58
commit 8f5d9d7702
2 changed files with 1074 additions and 1036 deletions

View File

@@ -1154,6 +1154,17 @@ mod implicit_self_borrow {
}
mod borrowed_typed {
#[derive(Debug, Copy, Clone, Default)]
struct MyFlag {
bool: bool,
}
impl MyFlag {
fn flip(&mut self) {
self.bool = !self.bool; // $ fieldof=MyFlag method=not
}
}
struct S;
impl S {
@@ -1179,6 +1190,14 @@ mod borrowed_typed {
x.f1(); // $ method=f1
x.f2(); // $ method=f2
S::f3(&x);
let n = **&&true; // $ MISSING: type=n:bool
// In this example the type of `flag` must be inferred at the call to
// `flip` and flow through the borrow in the argument.
let mut flag = Default::default();
MyFlag::flip(&mut flag);
println!("{:?}", flag); // $ MISSING: type=flag:MyFlag
}
}