diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2021-07-25 14:48:57 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2021-07-25 21:19:21 +0200 |
| commit | ec76b6eedddfd601a9684db945ff927e57f2aa03 (patch) | |
| tree | 31d00149e55177fd477fe082a2a632ae550c582d /src/librustdoc/html/render | |
| parent | 478126c0f3520ccd95a6f16be2812a78e3da711c (diff) | |
| download | rust-ec76b6eedddfd601a9684db945ff927e57f2aa03.tar.gz rust-ec76b6eedddfd601a9684db945ff927e57f2aa03.zip | |
Add support for tuple structs' fields documentation
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 3 | ||||
| -rw-r--r-- | 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("</div>"); + } else if let CtorKind::Fn = s.struct_type { + sidebar + .push_str("<h3 class=\"sidebar-title\"><a href=\"#fields\">Tuple Fields</a></h3>"); } } 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, "<h2 id=\"fields\" class=\"fields small-section-header\">\ - Fields{}<a href=\"#fields\" class=\"anchor\"></a></h2>", + {}{}<a href=\"#fields\" class=\"anchor\"></a>\ + </h2>", + 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, "<span id=\"{id}\" class=\"{item_type} small-section-header\">\ @@ -1199,7 +1199,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St </span>", 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)); |
