about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-24 15:16:18 +0000
committerbors <bors@rust-lang.org>2023-09-24 15:16:18 +0000
commit26eeea6a1b94418a3f513c0cd81f00c4c2966dfd (patch)
treed92725d245948f974cd9d99334ba21ffc28d06c9
parent70a7fe174321284ab262b64941b123ad081af242 (diff)
parent27fe1c380b481304a75411ac96cac52d5a8f6c2c (diff)
downloadrust-26eeea6a1b94418a3f513c0cd81f00c4c2966dfd.tar.gz
rust-26eeea6a1b94418a3f513c0cd81f00c4c2966dfd.zip
Auto merge of #116069 - compiler-errors:debug-tuple, r=Nilstrieb
Fix debug printing of tuple

Self-explanatory. Didn't create a UI test, but I guess I could -- not sure where debug output shows up in rustc_attrs to make a sufficient test, tho.
-rw-r--r--compiler/rustc_type_ir/src/sty.rs24
1 files changed, 10 insertions, 14 deletions
diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs
index c7fa0dcffa9..091b51440a6 100644
--- a/compiler/rustc_type_ir/src/sty.rs
+++ b/compiler/rustc_type_ir/src/sty.rs
@@ -531,22 +531,18 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
             }
             Never => write!(f, "!"),
             Tuple(t) => {
-                let mut iter = t.clone().into_iter();
-
                 write!(f, "(")?;
-
-                match iter.next() {
-                    None => return write!(f, ")"),
-                    Some(ty) => write!(f, "{:?}", &this.wrap(ty))?,
-                };
-
-                match iter.next() {
-                    None => return write!(f, ",)"),
-                    Some(ty) => write!(f, "{:?})", &this.wrap(ty))?,
+                let mut count = 0;
+                for ty in t.clone() {
+                    if count > 0 {
+                        write!(f, ", ")?;
+                    }
+                    write!(f, "{:?}", &this.wrap(ty))?;
+                    count += 1;
                 }
-
-                for ty in iter {
-                    write!(f, ", {:?}", &this.wrap(ty))?;
+                // unary tuples need a trailing comma
+                if count == 1 {
+                    write!(f, ",")?;
                 }
                 write!(f, ")")
             }