Skip to content

Commit 9cdab67

Browse files
committed
rustdoc: render unnamed arguments as underscores in cross-crate functions & function pointers
for consistency with the way we display local definitions (cleaned from HIR, not from rustc_middle).
1 parent 5965af7 commit 9cdab67

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -957,12 +957,14 @@ fn clean_args_from_types_and_names<'tcx>(
957957
values: types
958958
.iter()
959959
.enumerate()
960-
.map(|(i, ty)| {
961-
let mut name = names.get(i).map_or(kw::Empty, |ident| ident.name);
962-
if name.is_empty() {
963-
name = kw::Underscore;
964-
}
965-
Argument { name, type_: clean_ty(ty, cx), is_const: false }
960+
.map(|(i, ty)| Argument {
961+
type_: clean_ty(ty, cx),
962+
name: names
963+
.get(i)
964+
.map(|ident| ident.name)
965+
.filter(|ident| !ident.is_empty())
966+
.unwrap_or(kw::Underscore),
967+
is_const: false,
966968
})
967969
.collect(),
968970
}
@@ -1024,7 +1026,11 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
10241026
.iter()
10251027
.map(|t| Argument {
10261028
type_: clean_middle_ty(*t, cx, None),
1027-
name: names.next().map_or(kw::Empty, |i| i.name),
1029+
name: names
1030+
.next()
1031+
.map(|i| i.name)
1032+
.filter(|i| !i.is_empty())
1033+
.unwrap_or(kw::Underscore),
10281034
is_const: false,
10291035
})
10301036
.collect(),

src/librustdoc/html/format.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,9 +1232,8 @@ impl clean::Arguments {
12321232
) -> impl fmt::Display + 'a + Captures<'tcx> {
12331233
display_fn(move |f| {
12341234
for (i, input) in self.values.iter().enumerate() {
1235-
if !input.name.is_empty() {
1236-
write!(f, "{}: ", input.name)?;
1237-
}
1235+
write!(f, "{}: ", input.name)?;
1236+
12381237
if f.alternate() {
12391238
write!(f, "{:#}", input.type_.print(cx))?;
12401239
} else {
@@ -1367,10 +1366,8 @@ impl clean::FnDecl {
13671366
args.push_str("const ");
13681367
args_plain.push_str("const ");
13691368
}
1370-
if !input.name.is_empty() {
1371-
write!(args, "{}: ", input.name);
1372-
write!(args_plain, "{}: ", input.name);
1373-
}
1369+
write!(args, "{}: ", input.name);
1370+
write!(args_plain, "{}: ", input.name);
13741371

13751372
if f.alternate() {
13761373
write!(args, "{:#}", input.type_.print(cx));

src/test/rustdoc/inline_cross/assoc_item_trait_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern crate assoc_item_trait_bounds as aux;
3333
// @snapshot out9 - '//*[@id="associatedtype.Out9"]/*[@class="code-header"]'
3434
//
3535
// @has - '//*[@id="tymethod.make"]' \
36-
// "fn make<F>(F, impl FnMut(&str) -> bool)\
36+
// "fn make<F>(_: F, _: impl FnMut(&str) -> bool)\
3737
// where \
3838
// F: FnOnce(u32) -> String, \
3939
// Self::Out2<()>: Protocol<u8, Q0 = Self::Item, Q1 = ()>"

src/test/rustdoc/inline_cross/impl_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use impl_trait_aux::func4;
2929
// @has impl_trait/fn.func5.html
3030
// @has - '//pre[@class="rust fn"]' "func5("
3131
// @has - '//pre[@class="rust fn"]' "_f: impl for<'any> Fn(&'any str, &'any str) -> bool + for<'r> Other<T<'r> = ()>,"
32-
// @has - '//pre[@class="rust fn"]' "_a: impl for<'alpha, 'beta> Auxiliary<'alpha, Item<'beta> = fn(&'beta ())>"
32+
// @has - '//pre[@class="rust fn"]' "_a: impl for<'alpha, 'beta> Auxiliary<'alpha, Item<'beta> = fn(_: &'beta ())>"
3333
// @!has - '//pre[@class="rust fn"]' 'where'
3434
pub use impl_trait_aux::func5;
3535

0 commit comments

Comments
 (0)