Rollup merge of #122222 - Nadrieril:deref-pat-feature-gate, r=compiler-errors
deref patterns: bare-bones feature gate and typechecking I am restarting the deref patterns experimentation. This introduces a feature gate under the lang-team [experimental feature](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md) process, with [````@cramertj```` as lang-team liaison](https://github.com/rust-lang/lang-team/issues/88) (it's been a while though, you still ok with this ````@cramertj?).```` Tracking issue: https://github.com/rust-lang/rust/issues/87121. This is the barest-bones implementation I could think of: - explicit syntax, reusing `box <pat>` because that saves me a ton of work; - use `Deref` as a marker trait (instead of a yet-to-design `DerefPure`); - no support for mutable patterns with `DerefMut` for now; - MIR lowering will come in the next PR. It's the trickiest part. My goal is to let us figure out the MIR lowering part, which might take some work. And hopefully get something working for std types soon. This is in large part salvaged from ````@fee1-dead's```` https://github.com/rust-lang/rust/pull/119467. r? ````@compiler-errors````
This commit is contained in:
commit
0867025cc8
16 changed files with 139 additions and 17 deletions
|
@ -647,6 +647,7 @@ impl<'tcx> Pat<'tcx> {
|
|||
AscribeUserType { subpattern, .. }
|
||||
| Binding { subpattern: Some(subpattern), .. }
|
||||
| Deref { subpattern }
|
||||
| DerefPattern { subpattern }
|
||||
| InlineConstant { subpattern, .. } => subpattern.walk_(it),
|
||||
Leaf { subpatterns } | Variant { subpatterns, .. } => {
|
||||
subpatterns.iter().for_each(|field| field.pattern.walk_(it))
|
||||
|
@ -762,6 +763,11 @@ pub enum PatKind<'tcx> {
|
|||
subpattern: Box<Pat<'tcx>>,
|
||||
},
|
||||
|
||||
/// Deref pattern, written `box P` for now.
|
||||
DerefPattern {
|
||||
subpattern: Box<Pat<'tcx>>,
|
||||
},
|
||||
|
||||
/// One of the following:
|
||||
/// * `&str` (represented as a valtree), which will be handled as a string pattern and thus
|
||||
/// exhaustiveness checking will detect if you use the same string twice in different
|
||||
|
@ -1172,6 +1178,9 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
|
|||
}
|
||||
write!(f, "{subpattern}")
|
||||
}
|
||||
PatKind::DerefPattern { ref subpattern } => {
|
||||
write!(f, "k#deref {subpattern}")
|
||||
}
|
||||
PatKind::Constant { value } => write!(f, "{value}"),
|
||||
PatKind::InlineConstant { def: _, ref subpattern } => {
|
||||
write!(f, "{} (from inline const)", subpattern)
|
||||
|
|
|
@ -229,6 +229,7 @@ pub fn walk_pat<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
|
|||
match &pat.kind {
|
||||
AscribeUserType { subpattern, ascription: _ }
|
||||
| Deref { subpattern }
|
||||
| DerefPattern { subpattern }
|
||||
| Binding {
|
||||
subpattern: Some(subpattern),
|
||||
mutability: _,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue