rust/tests/ui/pattern/deref-patterns/closure_capture.rs
2024-04-20 15:59:54 +02:00

22 lines
472 B
Rust

//@ run-pass
#![feature(deref_patterns)]
#![allow(incomplete_features)]
fn main() {
let b = Box::new("aaa".to_string());
let f = || {
let deref!(ref s) = b else { unreachable!() };
assert_eq!(s.len(), 3);
};
assert_eq!(b.len(), 3);
f();
let mut b = Box::new("aaa".to_string());
let mut f = || {
let deref!(ref mut s) = b else { unreachable!() };
s.push_str("aa");
};
f();
assert_eq!(b.len(), 5);
}