Description
Tracking issue for implementing deref patterns (#[feature(deref_patterns)]
).
deref patterns project group repo
lang team initiative issue
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
- Implement the feature
- String -> &str: string_deref_patterns implementation: Minimal implementation of implicit deref patterns for Strings Minimal implementation of implicit deref patterns for Strings #98914 (stabilization not started)
- Deref patterns for other std types
- Adjust documentation (see instructions on rustc-dev-guide)
- Write an RFC
- Stabilization PR (see instructions on rustc-dev-guide)
Status
The current implementation uses a placeholder deref!(<pat>)
syntax and is limited to types in the standard library. See the design proposal document for more details.
We limit to types in the standard library using the unstable trait DerefPure
(#[feature(deref_pure_trait)]
). It is not intended to be stabilized at this stage.
- Supported std types:
Box
,Rc
,Arc
,Vec
,String
,Cow
,Pin
,ManuallyDrop
,Ref
,RefMut
. - Unstable types that would be eligible :
ThinBox
,UniqueRc
,LazyCell
,LazyLock
,
There is also a feature gate just for matching string literals on String
s, under #[feature(string_deref_patterns)]
.
Unresolved Questions
None at this stage
Implementation history
- Minimal implementation of implicit deref patterns for Strings #98914
- [WIP] implement explicit deref patterns through
k#deref
#119467 - deref patterns: bare-bones feature gate and typechecking #122222
- Implement macro-based deref!() syntax for deref patterns #122793
- Require
DerefMut
andDerefPure
onderef!()
patterns when appropriate #122835 - match lowering: make false edges more precise #123324
- deref patterns: lower deref patterns to MIR #122598
- deref patterns: impl
DerefPure
for more std types #123480 - Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str. #137105
- deref patterns: implement implicit deref patterns #138528
- allow deref patterns to move out of boxes #140022
deref_patterns
: support string and byte string literals in explicitderef!("...")
patterns #140028deref_patterns
: let string and byte string literal patterns peel references and smart pointers before matching #140658- allow deref patterns to participate in exhaustiveness analysis #140106