Skip to content

Commit 1fd4b37

Browse files
authored
Unrolled build for rust-lang#136411
Rollup merge of rust-lang#136411 - dtolnay:fnptr, r=notriddle Omit argument names from function pointers that do not have argument names This matches the style used for the vast majority of function pointer types in real-world code, in my experience. Prefixing `_: ` to every argument does not improve clarity. **Before:** <img src="https://github.com/user-attachments/assets/f07efa8b-d57e-4897-aa97-40db7d207862"> **After:** <img src="https://github.com/user-attachments/assets/8405e08b-d6d2-4904-bcc3-a3eb866cecf0">
2 parents affdb59 + b866deb commit 1fd4b37

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

src/librustdoc/clean/mod.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1104,17 +1104,29 @@ fn clean_args_from_types_and_names<'tcx>(
11041104
types: &[hir::Ty<'tcx>],
11051105
names: &[Ident],
11061106
) -> Arguments {
1107+
fn nonempty_name(ident: &Ident) -> Option<Symbol> {
1108+
if ident.name == kw::Underscore || ident.name == kw::Empty {
1109+
None
1110+
} else {
1111+
Some(ident.name)
1112+
}
1113+
}
1114+
1115+
// If at least one argument has a name, use `_` as the name of unnamed
1116+
// arguments. Otherwise omit argument names.
1117+
let default_name = if names.iter().any(|ident| nonempty_name(ident).is_some()) {
1118+
kw::Underscore
1119+
} else {
1120+
kw::Empty
1121+
};
1122+
11071123
Arguments {
11081124
values: types
11091125
.iter()
11101126
.enumerate()
11111127
.map(|(i, ty)| Argument {
11121128
type_: clean_ty(ty, cx),
1113-
name: names
1114-
.get(i)
1115-
.map(|ident| ident.name)
1116-
.filter(|ident| !ident.is_empty())
1117-
.unwrap_or(kw::Underscore),
1129+
name: names.get(i).and_then(nonempty_name).unwrap_or(default_name),
11181130
is_const: false,
11191131
})
11201132
.collect(),

src/librustdoc/html/format.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,9 @@ impl clean::Arguments {
14081408
) -> impl Display + 'a + Captures<'tcx> {
14091409
fmt::from_fn(move |f| {
14101410
for (i, input) in self.values.iter().enumerate() {
1411-
write!(f, "{}: ", input.name)?;
1411+
if !input.name.is_empty() {
1412+
write!(f, "{}: ", input.name)?;
1413+
}
14121414
input.type_.print(cx).fmt(f)?;
14131415
if i + 1 < self.values.len() {
14141416
write!(f, ", ")?;

tests/rustdoc/assoc-consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn f(_: &(ToString + 'static)) {}
4545

4646
impl Bar {
4747
//@ has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.F"]' \
48-
// "const F: fn(_: &(dyn ToString + 'static))"
48+
// "const F: fn(&(dyn ToString + 'static))"
4949
pub const F: fn(_: &(ToString + 'static)) = f;
5050
}
5151

tests/rustdoc/fn-pointer-arg-name.rs

+8
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
//@ has foo/fn.f.html
44
//@ has - '//pre[@class="rust item-decl"]' 'pub fn f(callback: fn(len: usize, foo: u32))'
55
pub fn f(callback: fn(len: usize, foo: u32)) {}
6+
7+
//@ has foo/fn.g.html
8+
//@ has - '//pre[@class="rust item-decl"]' 'pub fn g(_: fn(usize, u32))'
9+
pub fn g(_: fn(usize, _: u32)) {}
10+
11+
//@ has foo/fn.mixed.html
12+
//@ has - '//pre[@class="rust item-decl"]' 'pub fn mixed(_: fn(_: usize, foo: u32))'
13+
pub fn mixed(_: fn(usize, foo: u32)) {}

tests/rustdoc/inherent-projections.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Owner {
1313
}
1414

1515
// Make sure we handle bound vars correctly.
16-
//@ has 'inherent_projections/fn.user.html' '//pre[@class="rust item-decl"]' "user(_: for<'a> fn(_: Carrier<'a>::Focus))"
16+
//@ has 'inherent_projections/fn.user.html' '//pre[@class="rust item-decl"]' "user(_: for<'a> fn(Carrier<'a>::Focus))"
1717
pub fn user(_: for<'a> fn(Carrier<'a>::Focus)) {}
1818

1919
pub struct Carrier<'a>(&'a ());

tests/rustdoc/macro-higher-kinded-function.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ macro_rules! gen {
1111
}
1212

1313
//@ has 'foo/struct.Providers.html'
14-
//@ has - '//*[@class="rust item-decl"]//code' "pub a: for<'tcx> fn(_: TyCtxt<'tcx>, _: u8) -> i8,"
15-
//@ has - '//*[@class="rust item-decl"]//code' "pub b: for<'tcx> fn(_: TyCtxt<'tcx>, _: u16) -> i16,"
16-
//@ has - '//*[@id="structfield.a"]/code' "a: for<'tcx> fn(_: TyCtxt<'tcx>, _: u8) -> i8"
17-
//@ has - '//*[@id="structfield.b"]/code' "b: for<'tcx> fn(_: TyCtxt<'tcx>, _: u16) -> i16"
14+
//@ has - '//*[@class="rust item-decl"]//code' "pub a: for<'tcx> fn(TyCtxt<'tcx>, u8) -> i8,"
15+
//@ has - '//*[@class="rust item-decl"]//code' "pub b: for<'tcx> fn(TyCtxt<'tcx>, u16) -> i16,"
16+
//@ has - '//*[@id="structfield.a"]/code' "a: for<'tcx> fn(TyCtxt<'tcx>, u8) -> i8"
17+
//@ has - '//*[@id="structfield.b"]/code' "b: for<'tcx> fn(TyCtxt<'tcx>, u16) -> i16"
1818
gen! {
1919
(a, 'tcx, [u8], [i8])
2020
(b, 'tcx, [u16], [i16])

0 commit comments

Comments
 (0)