Skip to content

Commit 8f649a7

Browse files
committed
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.
1 parent 9449b78 commit 8f649a7

File tree

1 file changed

+2
-17
lines changed
  • compiler/rustc_pattern_analysis/src/rustc

1 file changed

+2
-17
lines changed

compiler/rustc_pattern_analysis/src/rustc/print.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,8 @@ pub(crate) fn write_struct_like<'tcx>(
101101
let num_fields = variant_and_name.as_ref().map_or(subpatterns.len(), |(v, _)| v.fields.len());
102102
if num_fields != 0 || variant_and_name.is_none() {
103103
write!(f, "(")?;
104-
for i in 0..num_fields {
105-
write!(f, "{}", start_or_comma())?;
106-
107-
// Common case: the field is where we expect it.
108-
if let Some(p) = subpatterns.get(i) {
109-
if p.field.index() == i {
110-
write!(f, "{}", p.pattern)?;
111-
continue;
112-
}
113-
}
114-
115-
// Otherwise, we have to go looking for it.
116-
if let Some(p) = subpatterns.iter().find(|p| p.field.index() == i) {
117-
write!(f, "{}", p.pattern)?;
118-
} else {
119-
write!(f, "_")?;
120-
}
104+
for FieldPat { pattern, .. } in subpatterns {
105+
write!(f, "{}{pattern}", start_or_comma())?;
121106
}
122107
if matches!(ty.kind(), ty::Tuple(..)) && num_fields == 1 {
123108
write!(f, ",")?;

0 commit comments

Comments
 (0)