From ec76b6eedddfd601a9684db945ff927e57f2aa03 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Jul 2021 14:48:57 +0200 Subject: [PATCH] Add support for tuple structs' fields documentation --- src/librustdoc/html/render/mod.rs | 3 +++ src/librustdoc/html/render/print_item.rs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 68c59612ccc..5298a560627 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2007,6 +2007,9 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea } sidebar.push_str(""); + } else if let CtorKind::Fn = s.struct_type { + sidebar + .push_str("

Tuple Fields

"); } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 2dfbaff1cc9..8f7e8442895 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1176,21 +1176,21 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St _ => None, }) .peekable(); - if let CtorKind::Fictive = s.struct_type { + if let CtorKind::Fictive | CtorKind::Fn = s.struct_type { if fields.peek().is_some() { write!( w, "

\ - Fields{}

", + {}{}\ + ", + if let CtorKind::Fictive = s.struct_type { "Fields" } else { "Tuple Fields" }, document_non_exhaustive_header(it) ); document_non_exhaustive(w, it); - for (field, ty) in fields { - let id = cx.derive_id(format!( - "{}.{}", - ItemType::StructField, - field.name.as_ref().unwrap() - )); + for (index, (field, ty)) in fields.enumerate() { + let field_name = + field.name.map_or_else(|| index.to_string(), |sym| (*sym.as_str()).to_string()); + let id = cx.derive_id(format!("{}.{}", ItemType::StructField, field_name)); write!( w, "\ @@ -1199,7 +1199,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St ", item_type = ItemType::StructField, id = id, - name = field.name.as_ref().unwrap(), + name = field_name, ty = ty.print(cx) ); document(w, cx, field, Some(it));