Rollup merge of #39740 - jimmycuadra:rustdoc-empty-stability, r=aturon
rustdoc: Only include a stability span if needed. This patch gets rid of the empty stability boxes in docs by only including the span that creates it when the item actually has a stability class. Here are images of the issue on `std::process::Output`: Before: <img width="340" alt="before" src="https://cloud.githubusercontent.com/assets/122457/22853638/ff88d1b2-f010-11e6-90d6-bf3d10e2fffa.png"> After: <img width="333" alt="after" src="https://cloud.githubusercontent.com/assets/122457/22853639/06bfe7cc-f011-11e6-9892-f0ea2cc6ec90.png"> This is my first non-trivial patch to Rust, so I'm sure some of my approach is not idiomatic. Let me know how you'd like me to adjust!
This commit is contained in:
@@ -1827,7 +1827,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
||||
stab_docs = stab_docs,
|
||||
docs = shorter(Some(&Markdown(doc_value).to_string())),
|
||||
class = myitem.type_(),
|
||||
stab = myitem.stability_class(),
|
||||
stab = myitem.stability_class().unwrap_or("".to_string()),
|
||||
unsafety_flag = unsafety_flag,
|
||||
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
|
||||
title_type = myitem.type_(),
|
||||
@@ -2378,13 +2378,16 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
write!(w, "<span id='{id}' class='{item_type}'>
|
||||
<span id='{ns_id}' class='invisible'>
|
||||
<code>{name}: {ty}</code>
|
||||
</span></span><span class='stab {stab}'></span>",
|
||||
</span></span>",
|
||||
item_type = ItemType::StructField,
|
||||
id = id,
|
||||
ns_id = ns_id,
|
||||
stab = field.stability_class(),
|
||||
name = field.name.as_ref().unwrap(),
|
||||
ty = ty)?;
|
||||
if let Some(stability_class) = field.stability_class() {
|
||||
write!(w, "<span class='stab {stab}'></span>",
|
||||
stab = stability_class)?;
|
||||
}
|
||||
document(w, cx, field)?;
|
||||
}
|
||||
}
|
||||
@@ -2415,11 +2418,14 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
write!(w, "<h2 class='fields'>Fields</h2>")?;
|
||||
for (field, ty) in fields {
|
||||
write!(w, "<span id='{shortty}.{name}' class='{shortty}'><code>{name}: {ty}</code>
|
||||
</span><span class='stab {stab}'></span>",
|
||||
</span>",
|
||||
shortty = ItemType::StructField,
|
||||
stab = field.stability_class(),
|
||||
name = field.name.as_ref().unwrap(),
|
||||
ty = ty)?;
|
||||
if let Some(stability_class) = field.stability_class() {
|
||||
write!(w, "<span class='stab {stab}'></span>",
|
||||
stab = stability_class)?;
|
||||
}
|
||||
document(w, cx, field)?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user