From 16670e167664e8ba7f2c1dcd6654988b37b4478e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 15 Apr 2025 10:17:32 +1000 Subject: [PATCH] Fix HIR pretty-printing of fns with just a variadic arg. Avoid the extraneous comma. --- compiler/rustc_hir_pretty/src/lib.rs | 4 +++- tests/pretty/hir-fn-variadic.pp | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 9cae080aeb3..ff4385c3bcc 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -2165,7 +2165,9 @@ impl<'a> State<'a> { s.end(); }); if decl.c_variadic { - self.word(", "); + if !decl.inputs.is_empty() { + self.word(", "); + } print_arg(self, None); self.word("..."); } diff --git a/tests/pretty/hir-fn-variadic.pp b/tests/pretty/hir-fn-variadic.pp index 136e8b44ec2..b6bc8e95127 100644 --- a/tests/pretty/hir-fn-variadic.pp +++ b/tests/pretty/hir-fn-variadic.pp @@ -20,8 +20,8 @@ fn main() { fn g3(_: extern "C" fn(u8, va: ...)) { } fn g4(_: extern "C" fn(u8, ...)) { } - fn g5(_: extern "C" fn(, va: ...)) { } - fn g6(_: extern "C" fn(, ...)) { } + fn g5(_: extern "C" fn(va: ...)) { } + fn g6(_: extern "C" fn(...)) { } { let _ = @@ -39,13 +39,13 @@ fn main() { { let _ = { - unsafe extern "C" fn f5(, va: ...) { } + unsafe extern "C" fn f5(va: ...) { } }; }; { let _ = { - unsafe extern "C" fn f6(, _: ...) { } + unsafe extern "C" fn f6(_: ...) { } }; }; }