Skip to content

Commit 4e555fa

Browse files
committed
Test partial moves via deref pats
1 parent 4313318 commit 4e555fa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tests/ui/pattern/deref-patterns/deref-box.rs

+8
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ fn unbox_2<T>(b: Box<(T,)>) -> T {
1515
x
1616
}
1717

18+
fn unbox_separately<T>(b: Box<(T, T)>) -> (T, T) {
19+
let (x, _) = b else { unreachable!() };
20+
let (_, y) = b else { unreachable!() };
21+
(x, y)
22+
}
23+
1824
fn main() {
1925
// test that deref patterns can move out of boxes
2026
let b1 = Box::new(0);
2127
let b2 = Box::new((0,));
2228
assert_eq!(unbox_1(b1), unbox_2(b2));
29+
let b3 = Box::new((1, 2));
30+
assert_eq!(unbox_separately(b3), (1, 2));
2331

2432
// test that borrowing from a box also works
2533
let mut b = "hi".to_owned().into_boxed_str();

0 commit comments

Comments
 (0)