rust/tests/ui/pattern/deref-patterns/closure_capture.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

22 lines
472 B
Rust
Raw Normal View History

2024-04-05 16:42:29 -05:00
//@ 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);
}