From bebd91feb32667b6a1bb7a11da91ab8a935b4c24 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 14 Mar 2025 07:29:19 +1100 Subject: [PATCH] Fix HIR param pretty printing some more. Anonymous params are currently represented with `kw::Empty`, so handle that properly. (Subsequent commits will get rid of the `kw::Empty`.) --- compiler/rustc_hir_pretty/src/lib.rs | 8 +++++--- tests/pretty/hir-fn-params.pp | 4 ++-- 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 3067766fb4d..1409310339a 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -2148,9 +2148,11 @@ impl<'a> State<'a> { s.print_implicit_self(&decl.implicit_self); } else { if let Some(arg_name) = arg_names.get(i) { - s.word(arg_name.to_string()); - s.word(":"); - s.space(); + if arg_name.name != kw::Empty { + s.word(arg_name.to_string()); + s.word(":"); + s.space(); + } } else if let Some(body_id) = body_id { s.ann.nested(s, Nested::BodyParamPat(body_id, i)); s.word(":"); diff --git a/tests/pretty/hir-fn-params.pp b/tests/pretty/hir-fn-params.pp index f33e26b7e8c..3799c8a3c3b 100644 --- a/tests/pretty/hir-fn-params.pp +++ b/tests/pretty/hir-fn-params.pp @@ -27,12 +27,12 @@ impl S { // because they had similar problems. But the pretty-printing tests currently // can't contain compile errors. -fn bare_fn(x: fn(: u32, _: u32, a: u32)) { } +fn bare_fn(x: fn(u32, _: u32, a: u32)) { } extern "C" { unsafe fn foreign_fn(_: u32, a: u32); } trait T { - fn trait_fn(: u32, _: u32, a: u32); + fn trait_fn(u32, _: u32, a: u32); }