@@ -7,7 +7,7 @@ The tracking issue for this feature is: [#87121]
7
7
------------------------
8
8
9
9
> ** 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 ` ] .
11
11
12
12
This feature permits pattern matching on [ smart pointers in the standard library] through their
13
13
` Deref ` target types, either implicitly or with explicit ` deref!(_) ` patterns (the syntax of which
@@ -54,6 +54,17 @@ if let [b] = &mut *v {
54
54
assert_eq! (v , [Box :: new (Some (2 ))]);
55
55
```
56
56
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
+
57
68
Additionally, when ` deref_patterns ` is enabled, string literal patterns may be written where ` str `
58
69
is expected. Likewise, byte string literal patterns may be written where ` [u8] ` or ` [u8; _] ` is
59
70
expected. This lets them be used in ` deref!(_) ` patterns:
@@ -75,4 +86,6 @@ match *"test" {
75
86
76
87
Implicit deref pattern syntax is not yet supported for string or byte string literals.
77
88
89
+ [ `box_patterns` ] : ./box-patterns.md
90
+ [ `string_deref_patterns` ] : ./string-deref-patterns.md
78
91
[ smart pointers in the standard library ] : https://doc.rust-lang.org/std/ops/trait.DerefPure.html#implementors
0 commit comments