diff options
| author | dianne <diannes.gm@gmail.com> | 2025-08-10 15:52:41 -0700 |
|---|---|---|
| committer | dianne <diannes.gm@gmail.com> | 2025-08-10 16:34:11 -0700 |
| commit | 8f649a7e585f03e69c61a5b8286a61b38307afe8 (patch) | |
| tree | 3ded7873201ed67eb6e7c006fcdf2180ebf034a9 /compiler/rustc_pattern_analysis/src/rustc | |
| parent | 9449b786218d5c5b66222a774f445e1ccf3e3666 (diff) | |
| download | rust-8f649a7e585f03e69c61a5b8286a61b38307afe8.tar.gz rust-8f649a7e585f03e69c61a5b8286a61b38307afe8.zip | |
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.
Diffstat (limited to 'compiler/rustc_pattern_analysis/src/rustc')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/rustc/print.rs | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/compiler/rustc_pattern_analysis/src/rustc/print.rs b/compiler/rustc_pattern_analysis/src/rustc/print.rs index 022fac2a826..cdf62c2553d 100644 --- a/compiler/rustc_pattern_analysis/src/rustc/print.rs +++ b/compiler/rustc_pattern_analysis/src/rustc/print.rs @@ -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, ",")?; |
