@@ -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
1212This 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 {
5454assert_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+
5768Additionally, when ` deref_patterns ` is enabled, string literal patterns may be written where ` str `
5869is expected. Likewise, byte string literal patterns may be written where ` [u8] ` or ` [u8; _] ` is
5970expected. This lets them be used in ` deref!(_) ` patterns:
@@ -75,4 +86,6 @@ match *"test" {
7586
7687Implicit 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