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 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
let subpatterns = pat let subpatterns = pat
.iter_fields() .iter_fields()
.enumerate() .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<_>>(); .collect::<Vec<_>>();
PatKind::StructLike { enum_info, subpatterns } PatKind::StructLike { enum_info, subpatterns }

View File

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