about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-04-15 12:28:18 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2025-04-15 15:34:18 +1000
commit31320a925f53264a1905c5228392de9638bf2d52 (patch)
tree83abfc7fb5d8627e8322ef7159ccb5f744237053
parente53f2a01cea46bd7f9181e76353bde190255ea20 (diff)
downloadrust-31320a925f53264a1905c5228392de9638bf2d52.tar.gz
rust-31320a925f53264a1905c5228392de9638bf2d52.zip
Remove another `kw::Empty` use in rustdoc.
Again by using `Option<Symbol>` to represent "no name".
-rw-r--r--src/librustdoc/clean/mod.rs35
-rw-r--r--src/librustdoc/clean/types.rs4
-rw-r--r--src/librustdoc/html/format.rs8
-rw-r--r--src/librustdoc/json/conversions.rs7
4 files changed, 31 insertions, 23 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 736dd3a1d86..1bba43cc45f 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -117,7 +117,14 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
             hir::ItemKind::Use(path, kind) => {
                 let hir::UsePath { segments, span, .. } = *path;
                 let path = hir::Path { segments, res: *res, span };
-                clean_use_statement_inner(import, Some(name), &path, kind, cx, &mut Default::default())
+                clean_use_statement_inner(
+                    import,
+                    Some(name),
+                    &path,
+                    kind,
+                    cx,
+                    &mut Default::default(),
+                )
             }
             _ => unreachable!(),
         }
@@ -1071,10 +1078,10 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
                         ..
                     } = param
                     {
-                        func.decl
-                            .inputs
-                            .values
-                            .insert(a.get() as _, Argument { name, type_: *ty, is_const: true });
+                        func.decl.inputs.values.insert(
+                            a.get() as _,
+                            Argument { name: Some(name), type_: *ty, is_const: true },
+                        );
                     } else {
                         panic!("unexpected non const in position {pos}");
                     }
@@ -1131,9 +1138,9 @@ fn clean_args_from_types_and_names<'tcx>(
     // If at least one argument has a name, use `_` as the name of unnamed
     // arguments. Otherwise omit argument names.
     let default_name = if idents.iter().any(|ident| nonempty_name(ident).is_some()) {
-        kw::Underscore
+        Some(kw::Underscore)
     } else {
-        kw::Empty
+        None
     };
 
     Arguments {
@@ -1142,7 +1149,7 @@ fn clean_args_from_types_and_names<'tcx>(
             .enumerate()
             .map(|(i, ty)| Argument {
                 type_: clean_ty(ty, cx),
-                name: idents.get(i).and_then(nonempty_name).unwrap_or(default_name),
+                name: idents.get(i).and_then(nonempty_name).or(default_name),
                 is_const: false,
             })
             .collect(),
@@ -1161,7 +1168,7 @@ fn clean_args_from_types_and_body_id<'tcx>(
             .iter()
             .zip(body.params)
             .map(|(ty, param)| Argument {
-                name: name_from_pat(param.pat),
+                name: Some(name_from_pat(param.pat)),
                 type_: clean_ty(ty, cx),
                 is_const: false,
             })
@@ -1217,11 +1224,11 @@ fn clean_poly_fn_sig<'tcx>(
                 .iter()
                 .map(|t| Argument {
                     type_: clean_middle_ty(t.map_bound(|t| *t), cx, None, None),
-                    name: if let Some(Some(ident)) = names.next() {
+                    name: Some(if let Some(Some(ident)) = names.next() {
                         ident.name
                     } else {
                         kw::Underscore
-                    },
+                    }),
                     is_const: false,
                 })
                 .collect(),
@@ -2791,11 +2798,7 @@ fn clean_maybe_renamed_item<'tcx>(
     use hir::ItemKind;
 
     let def_id = item.owner_id.to_def_id();
-    let mut name = if renamed.is_some() {
-        renamed
-    } else {
-        cx.tcx.hir_opt_name(item.hir_id())
-    };
+    let mut name = if renamed.is_some() { renamed } else { cx.tcx.hir_opt_name(item.hir_id()) };
 
     cx.with_param_env(def_id, |cx| {
         let kind = match item.kind {
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index 06e75fe1764..1d398a6458f 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -1426,7 +1426,7 @@ pub(crate) struct Arguments {
 #[derive(Clone, PartialEq, Eq, Debug, Hash)]
 pub(crate) struct Argument {
     pub(crate) type_: Type,
-    pub(crate) name: Symbol,
+    pub(crate) name: Option<Symbol>,
     /// This field is used to represent "const" arguments from the `rustc_legacy_const_generics`
     /// feature. More information in <https://github.com/rust-lang/rust/issues/83167>.
     pub(crate) is_const: bool,
@@ -1434,7 +1434,7 @@ pub(crate) struct Argument {
 
 impl Argument {
     pub(crate) fn to_receiver(&self) -> Option<&Type> {
-        if self.name == kw::SelfLower { Some(&self.type_) } else { None }
+        if self.name == Some(kw::SelfLower) { Some(&self.type_) } else { None }
     }
 }
 
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 41e9a5a6651..4d55df71a91 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -1238,8 +1238,8 @@ impl clean::Arguments {
                 .iter()
                 .map(|input| {
                     fmt::from_fn(|f| {
-                        if !input.name.is_empty() {
-                            write!(f, "{}: ", input.name)?;
+                        if let Some(name) = input.name {
+                            write!(f, "{}: ", name)?;
                         }
                         input.type_.print(cx).fmt(f)
                     })
@@ -1361,7 +1361,9 @@ impl clean::FnDecl {
                 if input.is_const {
                     write!(f, "const ")?;
                 }
-                write!(f, "{}: ", input.name)?;
+                if let Some(name) = input.name {
+                    write!(f, "{}: ", name)?;
+                }
                 input.type_.print(cx).fmt(f)?;
             }
             match (line_wrapping_indent, last_input_index) {
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index 9d8eb70fbe0..5d85a4676b7 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -11,7 +11,7 @@ use rustc_hir::def::CtorKind;
 use rustc_hir::def_id::DefId;
 use rustc_metadata::rendered_const;
 use rustc_middle::{bug, ty};
-use rustc_span::{Pos, Symbol};
+use rustc_span::{Pos, Symbol, kw};
 use rustdoc_json_types::*;
 
 use crate::clean::{self, ItemId};
@@ -611,7 +611,10 @@ impl FromClean<clean::FnDecl> for FunctionSignature {
             inputs: inputs
                 .values
                 .into_iter()
-                .map(|arg| (arg.name.to_string(), arg.type_.into_json(renderer)))
+                // `_` is the most sensible name for missing param names.
+                .map(|arg| {
+                    (arg.name.unwrap_or(kw::Underscore).to_string(), arg.type_.into_json(renderer))
+                })
                 .collect(),
             output: if output.is_unit() { None } else { Some(output.into_json(renderer)) },
             is_c_variadic: c_variadic,