Skip to content

Commit

Permalink
Rollup merge of rust-lang#116069 - compiler-errors:debug-tuple, r=Nil…
Browse files Browse the repository at this point in the history
…strieb

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.
  • Loading branch information
GuillaumeGomez authored Sep 24, 2023
2 parents a87b9da + 27fe1c3 commit 5112cf7
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions compiler/rustc_type_ir/src/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ")")
}
Expand Down

0 comments on commit 5112cf7

Please sign in to comment.