We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4313318 commit 4e555faCopy full SHA for 4e555fa
tests/ui/pattern/deref-patterns/deref-box.rs
@@ -15,11 +15,19 @@ fn unbox_2<T>(b: Box<(T,)>) -> T {
15
x
16
}
17
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
+
24
fn main() {
25
// test that deref patterns can move out of boxes
26
let b1 = Box::new(0);
27
let b2 = Box::new((0,));
28
assert_eq!(unbox_1(b1), unbox_2(b2));
29
+ let b3 = Box::new((1, 2));
30
+ assert_eq!(unbox_separately(b3), (1, 2));
31
32
// test that borrowing from a box also works
33
let mut b = "hi".to_owned().into_boxed_str();
0 commit comments