mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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:
@@ -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, ",")?;
|
||||
|
||||
Reference in New Issue
Block a user