From 9449b786218d5c5b66222a774f445e1ccf3e3666 Mon Sep 17 00:00:00 2001 From: dianne Date: Sun, 10 Aug 2025 15:32:14 -0700 Subject: show a trailing comma on singleton tuple constructors in witness pats --- compiler/rustc_pattern_analysis/src/rustc/print.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'compiler/rustc_pattern_analysis/src') diff --git a/compiler/rustc_pattern_analysis/src/rustc/print.rs b/compiler/rustc_pattern_analysis/src/rustc/print.rs index 7649f72f868..022fac2a826 100644 --- a/compiler/rustc_pattern_analysis/src/rustc/print.rs +++ b/compiler/rustc_pattern_analysis/src/rustc/print.rs @@ -119,6 +119,9 @@ pub(crate) fn write_struct_like<'tcx>( write!(f, "_")?; } } + if matches!(ty.kind(), ty::Tuple(..)) && num_fields == 1 { + write!(f, ",")?; + } write!(f, ")")?; } -- cgit 1.4.1-3-g733a5 From 8f649a7e585f03e69c61a5b8286a61b38307afe8 Mon Sep 17 00:00:00 2001 From: dianne Date: Sun, 10 Aug 2025 15:52:41 -0700 Subject: 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. --- compiler/rustc_pattern_analysis/src/rustc/print.rs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'compiler/rustc_pattern_analysis/src') 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, ",")?; -- cgit 1.4.1-3-g733a5