Skip to content

Commit 31320a9

Browse files
committed
Remove another kw::Empty use in rustdoc.
Again by using `Option<Symbol>` to represent "no name".
1 parent e53f2a0 commit 31320a9

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

Diff for: src/librustdoc/clean/mod.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
117117
hir::ItemKind::Use(path, kind) => {
118118
let hir::UsePath { segments, span, .. } = *path;
119119
let path = hir::Path { segments, res: *res, span };
120-
clean_use_statement_inner(import, Some(name), &path, kind, cx, &mut Default::default())
120+
clean_use_statement_inner(
121+
import,
122+
Some(name),
123+
&path,
124+
kind,
125+
cx,
126+
&mut Default::default(),
127+
)
121128
}
122129
_ => unreachable!(),
123130
}
@@ -1071,10 +1078,10 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
10711078
..
10721079
} = param
10731080
{
1074-
func.decl
1075-
.inputs
1076-
.values
1077-
.insert(a.get() as _, Argument { name, type_: *ty, is_const: true });
1081+
func.decl.inputs.values.insert(
1082+
a.get() as _,
1083+
Argument { name: Some(name), type_: *ty, is_const: true },
1084+
);
10781085
} else {
10791086
panic!("unexpected non const in position {pos}");
10801087
}
@@ -1131,9 +1138,9 @@ fn clean_args_from_types_and_names<'tcx>(
11311138
// If at least one argument has a name, use `_` as the name of unnamed
11321139
// arguments. Otherwise omit argument names.
11331140
let default_name = if idents.iter().any(|ident| nonempty_name(ident).is_some()) {
1134-
kw::Underscore
1141+
Some(kw::Underscore)
11351142
} else {
1136-
kw::Empty
1143+
None
11371144
};
11381145

11391146
Arguments {
@@ -1142,7 +1149,7 @@ fn clean_args_from_types_and_names<'tcx>(
11421149
.enumerate()
11431150
.map(|(i, ty)| Argument {
11441151
type_: clean_ty(ty, cx),
1145-
name: idents.get(i).and_then(nonempty_name).unwrap_or(default_name),
1152+
name: idents.get(i).and_then(nonempty_name).or(default_name),
11461153
is_const: false,
11471154
})
11481155
.collect(),
@@ -1161,7 +1168,7 @@ fn clean_args_from_types_and_body_id<'tcx>(
11611168
.iter()
11621169
.zip(body.params)
11631170
.map(|(ty, param)| Argument {
1164-
name: name_from_pat(param.pat),
1171+
name: Some(name_from_pat(param.pat)),
11651172
type_: clean_ty(ty, cx),
11661173
is_const: false,
11671174
})
@@ -1217,11 +1224,11 @@ fn clean_poly_fn_sig<'tcx>(
12171224
.iter()
12181225
.map(|t| Argument {
12191226
type_: clean_middle_ty(t.map_bound(|t| *t), cx, None, None),
1220-
name: if let Some(Some(ident)) = names.next() {
1227+
name: Some(if let Some(Some(ident)) = names.next() {
12211228
ident.name
12221229
} else {
12231230
kw::Underscore
1224-
},
1231+
}),
12251232
is_const: false,
12261233
})
12271234
.collect(),
@@ -2791,11 +2798,7 @@ fn clean_maybe_renamed_item<'tcx>(
27912798
use hir::ItemKind;
27922799

27932800
let def_id = item.owner_id.to_def_id();
2794-
let mut name = if renamed.is_some() {
2795-
renamed
2796-
} else {
2797-
cx.tcx.hir_opt_name(item.hir_id())
2798-
};
2801+
let mut name = if renamed.is_some() { renamed } else { cx.tcx.hir_opt_name(item.hir_id()) };
27992802

28002803
cx.with_param_env(def_id, |cx| {
28012804
let kind = match item.kind {

Diff for: src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1426,15 +1426,15 @@ pub(crate) struct Arguments {
14261426
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
14271427
pub(crate) struct Argument {
14281428
pub(crate) type_: Type,
1429-
pub(crate) name: Symbol,
1429+
pub(crate) name: Option<Symbol>,
14301430
/// This field is used to represent "const" arguments from the `rustc_legacy_const_generics`
14311431
/// feature. More information in <https://github.com/rust-lang/rust/issues/83167>.
14321432
pub(crate) is_const: bool,
14331433
}
14341434

14351435
impl Argument {
14361436
pub(crate) fn to_receiver(&self) -> Option<&Type> {
1437-
if self.name == kw::SelfLower { Some(&self.type_) } else { None }
1437+
if self.name == Some(kw::SelfLower) { Some(&self.type_) } else { None }
14381438
}
14391439
}
14401440

Diff for: src/librustdoc/html/format.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,8 @@ impl clean::Arguments {
12381238
.iter()
12391239
.map(|input| {
12401240
fmt::from_fn(|f| {
1241-
if !input.name.is_empty() {
1242-
write!(f, "{}: ", input.name)?;
1241+
if let Some(name) = input.name {
1242+
write!(f, "{}: ", name)?;
12431243
}
12441244
input.type_.print(cx).fmt(f)
12451245
})
@@ -1361,7 +1361,9 @@ impl clean::FnDecl {
13611361
if input.is_const {
13621362
write!(f, "const ")?;
13631363
}
1364-
write!(f, "{}: ", input.name)?;
1364+
if let Some(name) = input.name {
1365+
write!(f, "{}: ", name)?;
1366+
}
13651367
input.type_.print(cx).fmt(f)?;
13661368
}
13671369
match (line_wrapping_indent, last_input_index) {

Diff for: src/librustdoc/json/conversions.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::def::CtorKind;
1111
use rustc_hir::def_id::DefId;
1212
use rustc_metadata::rendered_const;
1313
use rustc_middle::{bug, ty};
14-
use rustc_span::{Pos, Symbol};
14+
use rustc_span::{Pos, Symbol, kw};
1515
use rustdoc_json_types::*;
1616

1717
use crate::clean::{self, ItemId};
@@ -611,7 +611,10 @@ impl FromClean<clean::FnDecl> for FunctionSignature {
611611
inputs: inputs
612612
.values
613613
.into_iter()
614-
.map(|arg| (arg.name.to_string(), arg.type_.into_json(renderer)))
614+
// `_` is the most sensible name for missing param names.
615+
.map(|arg| {
616+
(arg.name.unwrap_or(kw::Underscore).to_string(), arg.type_.into_json(renderer))
617+
})
615618
.collect(),
616619
output: if output.is_unit() { None } else { Some(output.into_json(renderer)) },
617620
is_c_variadic: c_variadic,

0 commit comments

Comments
 (0)