1
Fork 0

Add barest-bones deref patterns

Co-authored-by: Deadbeef <ent3rm4n@gmail.com>
This commit is contained in:
Nadrieril 2024-03-08 19:17:23 +01:00
parent a128516cf9
commit 120d3570aa
16 changed files with 139 additions and 17 deletions

View file

@ -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)

View file

@ -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: _,