clean up witness printing for tuple-like constructors

By construction, `subpatterns` contains all fields in order. Witness
patterns are constructed with all fields in order by
`WitnessPat::wild_from_ctor` and `WitnessStack::apply_constructor`, and
the order is preserved at `write_struct_like`'s call-site in
`print_witness_pat`. It's thus no longer necessary to go looking for
fields or handle missing fields.
This commit is contained in:
dianne
2025-08-10 15:52:41 -07:00
parent 9449b78621
commit 8f649a7e58
@@ -101,23 +101,8 @@ pub(crate) fn write_struct_like<'tcx>(
let num_fields = variant_and_name.as_ref().map_or(subpatterns.len(), |(v, _)| v.fields.len());
if num_fields != 0 || variant_and_name.is_none() {
write!(f, "(")?;
for i in 0..num_fields {
write!(f, "{}", start_or_comma())?;
// Common case: the field is where we expect it.
if let Some(p) = subpatterns.get(i) {
if p.field.index() == i {
write!(f, "{}", p.pattern)?;
continue;
}
}
// Otherwise, we have to go looking for it.
if let Some(p) = subpatterns.iter().find(|p| p.field.index() == i) {
write!(f, "{}", p.pattern)?;
} else {
write!(f, "_")?;
}
for FieldPat { pattern, .. } in subpatterns {
write!(f, "{}{pattern}", start_or_comma())?;
}
if matches!(ty.kind(), ty::Tuple(..)) && num_fields == 1 {
write!(f, ",")?;