about summary refs log tree commit diff
path: root/src/librustdoc/clean/mod.rs
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2025-02-01 14:54:02 -0800
committerDavid Tolnay <dtolnay@gmail.com>2025-02-01 15:04:19 -0800
commitb866debf3cdbc30f71b0800684236213ebbb2d8c (patch)
treefabb1a5f4726fc6e6623972972a89272633a58b0 /src/librustdoc/clean/mod.rs
parent5f447a1ca6516fefe33fa0351aaf2c27b2911d98 (diff)
downloadrust-b866debf3cdbc30f71b0800684236213ebbb2d8c.tar.gz
rust-b866debf3cdbc30f71b0800684236213ebbb2d8c.zip
Omit argument names from function pointers that do not have argument names
Diffstat (limited to 'src/librustdoc/clean/mod.rs')
-rw-r--r--src/librustdoc/clean/mod.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 7853e311a04..0d4ff6e7aa5 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1104,17 +1104,29 @@ fn clean_args_from_types_and_names<'tcx>(
     types: &[hir::Ty<'tcx>],
     names: &[Ident],
 ) -> Arguments {
+    fn nonempty_name(ident: &Ident) -> Option<Symbol> {
+        if ident.name == kw::Underscore || ident.name == kw::Empty {
+            None
+        } else {
+            Some(ident.name)
+        }
+    }
+
+    // If at least one argument has a name, use `_` as the name of unnamed
+    // arguments. Otherwise omit argument names.
+    let default_name = if names.iter().any(|ident| nonempty_name(ident).is_some()) {
+        kw::Underscore
+    } else {
+        kw::Empty
+    };
+
     Arguments {
         values: types
             .iter()
             .enumerate()
             .map(|(i, ty)| Argument {
                 type_: clean_ty(ty, cx),
-                name: names
-                    .get(i)
-                    .map(|ident| ident.name)
-                    .filter(|ident| !ident.is_empty())
-                    .unwrap_or(kw::Underscore),
+                name: names.get(i).and_then(nonempty_name).unwrap_or(default_name),
                 is_const: false,
             })
             .collect(),