Avoid matching on PatKind::Wild in write_struct_like

This commit is contained in:
Zalathar 2024-08-03 20:26:17 +10:00
parent c9bd03cb72
commit 0a777090d8
2 changed files with 10 additions and 5 deletions

View File

@ -847,7 +847,11 @@ fn hoist_witness_pat(&self, pat: &WitnessPat<'p, 'tcx>) -> print::Pat<'tcx> {
let subpatterns = pat
.iter_fields()
.enumerate()
.map(|(i, pat)| FieldPat { field: FieldIdx::new(i), pattern: hoist(pat) })
.map(|(i, pat)| FieldPat {
field: FieldIdx::new(i),
pattern: hoist(pat),
is_wildcard: would_print_as_wildcard(cx.tcx, pat),
})
.collect::<Vec<_>>();
PatKind::StructLike { enum_info, subpatterns }

View File

@ -21,6 +21,7 @@
pub(crate) struct FieldPat<'tcx> {
pub(crate) field: FieldIdx,
pub(crate) pattern: Box<Pat<'tcx>>,
pub(crate) is_wildcard: bool,
}
#[derive(Clone, Debug)]
@ -139,12 +140,12 @@ fn write_struct_like<'tcx>(
write!(f, " {{ ")?;
let mut printed = 0;
for p in subpatterns {
if let PatKind::Wild = p.pattern.kind {
for &FieldPat { field, ref pattern, is_wildcard } in subpatterns {
if is_wildcard {
continue;
}
let name = variant.fields[p.field].name;
write!(f, "{}{}: {}", start_or_comma(), name, p.pattern)?;
let field_name = variant.fields[field].name;
write!(f, "{}{field_name}: {pattern}", start_or_comma())?;
printed += 1;
}