Skip to content

Commit 4313318

Browse files
committed
update unstable book to mention moving out of boxes
1 parent 0eb3b11 commit 4313318

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/doc/unstable-book/src/language-features/deref-patterns.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The tracking issue for this feature is: [#87121]
77
------------------------
88

99
> **Note**: This feature is incomplete. In the future, it is meant to supersede
10-
> [`box_patterns`](./box-patterns.md) and [`string_deref_patterns`](./string-deref-patterns.md).
10+
> [`box_patterns`] and [`string_deref_patterns`].
1111
1212
This feature permits pattern matching on [smart pointers in the standard library] through their
1313
`Deref` target types, either implicitly or with explicit `deref!(_)` patterns (the syntax of which
@@ -54,6 +54,17 @@ if let [b] = &mut *v {
5454
assert_eq!(v, [Box::new(Some(2))]);
5555
```
5656

57+
Like [`box_patterns`], deref patterns may move out of boxes:
58+
59+
```rust
60+
# #![feature(deref_patterns)]
61+
# #![allow(incomplete_features)]
62+
struct NoCopy;
63+
// Match exhaustiveness analysis is not yet implemented.
64+
let deref!(x) = Box::new(NoCopy) else { unreachable!() };
65+
drop::<NoCopy>(x);
66+
```
67+
5768
Additionally, when `deref_patterns` is enabled, string literal patterns may be written where `str`
5869
is expected. Likewise, byte string literal patterns may be written where `[u8]` or `[u8; _]` is
5970
expected. This lets them be used in `deref!(_)` patterns:
@@ -75,4 +86,6 @@ match *"test" {
7586

7687
Implicit deref pattern syntax is not yet supported for string or byte string literals.
7788

89+
[`box_patterns`]: ./box-patterns.md
90+
[`string_deref_patterns`]: ./string-deref-patterns.md
7891
[smart pointers in the standard library]: https://doc.rust-lang.org/std/ops/trait.DerefPure.html#implementors

0 commit comments

Comments
 (0)