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).
This commit is contained in:
parent
5965af7010
commit
9cdab67f6e
@ -957,12 +957,14 @@ fn clean_args_from_types_and_names<'tcx>(
|
|||||||
values: types
|
values: types
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, ty)| {
|
.map(|(i, ty)| Argument {
|
||||||
let mut name = names.get(i).map_or(kw::Empty, |ident| ident.name);
|
type_: clean_ty(ty, cx),
|
||||||
if name.is_empty() {
|
name: names
|
||||||
name = kw::Underscore;
|
.get(i)
|
||||||
}
|
.map(|ident| ident.name)
|
||||||
Argument { name, type_: clean_ty(ty, cx), is_const: false }
|
.filter(|ident| !ident.is_empty())
|
||||||
|
.unwrap_or(kw::Underscore),
|
||||||
|
is_const: false,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
@ -1024,7 +1026,11 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|t| Argument {
|
.map(|t| Argument {
|
||||||
type_: clean_middle_ty(*t, cx, None),
|
type_: clean_middle_ty(*t, cx, None),
|
||||||
name: names.next().map_or(kw::Empty, |i| i.name),
|
name: names
|
||||||
|
.next()
|
||||||
|
.map(|i| i.name)
|
||||||
|
.filter(|i| !i.is_empty())
|
||||||
|
.unwrap_or(kw::Underscore),
|
||||||
is_const: false,
|
is_const: false,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
@ -1232,9 +1232,8 @@ pub(crate) fn print<'a, 'tcx: 'a>(
|
|||||||
) -> impl fmt::Display + 'a + Captures<'tcx> {
|
) -> impl fmt::Display + 'a + Captures<'tcx> {
|
||||||
display_fn(move |f| {
|
display_fn(move |f| {
|
||||||
for (i, input) in self.values.iter().enumerate() {
|
for (i, input) in self.values.iter().enumerate() {
|
||||||
if !input.name.is_empty() {
|
write!(f, "{}: ", input.name)?;
|
||||||
write!(f, "{}: ", input.name)?;
|
|
||||||
}
|
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
write!(f, "{:#}", input.type_.print(cx))?;
|
write!(f, "{:#}", input.type_.print(cx))?;
|
||||||
} else {
|
} else {
|
||||||
@ -1367,10 +1366,8 @@ fn inner_full_print(
|
|||||||
args.push_str("const ");
|
args.push_str("const ");
|
||||||
args_plain.push_str("const ");
|
args_plain.push_str("const ");
|
||||||
}
|
}
|
||||||
if !input.name.is_empty() {
|
write!(args, "{}: ", input.name);
|
||||||
write!(args, "{}: ", input.name);
|
write!(args_plain, "{}: ", input.name);
|
||||||
write!(args_plain, "{}: ", input.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
write!(args, "{:#}", input.type_.print(cx));
|
write!(args, "{:#}", input.type_.print(cx));
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
// @snapshot out9 - '//*[@id="associatedtype.Out9"]/*[@class="code-header"]'
|
// @snapshot out9 - '//*[@id="associatedtype.Out9"]/*[@class="code-header"]'
|
||||||
//
|
//
|
||||||
// @has - '//*[@id="tymethod.make"]' \
|
// @has - '//*[@id="tymethod.make"]' \
|
||||||
// "fn make<F>(F, impl FnMut(&str) -> bool)\
|
// "fn make<F>(_: F, _: impl FnMut(&str) -> bool)\
|
||||||
// where \
|
// where \
|
||||||
// F: FnOnce(u32) -> String, \
|
// F: FnOnce(u32) -> String, \
|
||||||
// Self::Out2<()>: Protocol<u8, Q0 = Self::Item, Q1 = ()>"
|
// Self::Out2<()>: Protocol<u8, Q0 = Self::Item, Q1 = ()>"
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
// @has impl_trait/fn.func5.html
|
// @has impl_trait/fn.func5.html
|
||||||
// @has - '//pre[@class="rust fn"]' "func5("
|
// @has - '//pre[@class="rust fn"]' "func5("
|
||||||
// @has - '//pre[@class="rust fn"]' "_f: impl for<'any> Fn(&'any str, &'any str) -> bool + for<'r> Other<T<'r> = ()>,"
|
// @has - '//pre[@class="rust fn"]' "_f: impl for<'any> Fn(&'any str, &'any str) -> bool + for<'r> Other<T<'r> = ()>,"
|
||||||
// @has - '//pre[@class="rust fn"]' "_a: impl for<'alpha, 'beta> Auxiliary<'alpha, Item<'beta> = fn(&'beta ())>"
|
// @has - '//pre[@class="rust fn"]' "_a: impl for<'alpha, 'beta> Auxiliary<'alpha, Item<'beta> = fn(_: &'beta ())>"
|
||||||
// @!has - '//pre[@class="rust fn"]' 'where'
|
// @!has - '//pre[@class="rust fn"]' 'where'
|
||||||
pub use impl_trait_aux::func5;
|
pub use impl_trait_aux::func5;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user