diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 291fc8dfa9680..751ed7d443d29 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -327,17 +327,24 @@ impl Item { } } - pub fn stability_class(&self) -> String { - self.stability.as_ref().map(|ref s| { - let mut base = match s.level { - stability::Unstable => "unstable".to_string(), - stability::Stable => String::new(), - }; + pub fn stability_class(&self) -> Option { + self.stability.as_ref().and_then(|ref s| { + let mut classes = Vec::with_capacity(2); + + if s.level == stability::Unstable { + classes.push("unstable"); + } + if !s.deprecated_since.is_empty() { - base.push_str(" deprecated"); + classes.push("deprecated"); } - base - }).unwrap_or(String::new()) + + if classes.len() != 0 { + Some(classes.join(" ")) + } else { + None + } + }) } pub fn stable_since(&self) -> Option<&str> { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 6234d89024441..fd83711f1f446 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -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 = full_path(cx, myitem))?; @@ -2369,13 +2369,16 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, " ", + ", 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, "", + stab = stability_class)?; + } document(w, cx, field)?; } } @@ -2406,11 +2409,14 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, "

Fields

")?; for (field, ty) in fields { write!(w, "{name}: {ty} - ", + ", 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, "", + stab = stability_class)?; + } document(w, cx, field)?; } }