Add tests and improve rendering of features on traits
This commit is contained in:
parent
98d66340d6
commit
c34350ab4f
3 changed files with 174 additions and 32 deletions
|
@ -2251,6 +2251,22 @@ fn stability_tags(item: &clean::Item, parent: &clean::Item) -> String {
|
||||||
tags
|
tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn portability(item: &clean::Item, parent: Option<&clean::Item>) -> Option<String> {
|
||||||
|
let cfg = match (&item.attrs.cfg, parent.and_then(|p| p.attrs.cfg.as_ref())) {
|
||||||
|
(Some(cfg), Some(parent_cfg)) => cfg.simplify_with(parent_cfg),
|
||||||
|
(cfg, _) => cfg.as_deref().cloned(),
|
||||||
|
};
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"Portability {:?} - {:?} = {:?}",
|
||||||
|
item.attrs.cfg,
|
||||||
|
parent.and_then(|p| p.attrs.cfg.as_ref()),
|
||||||
|
cfg
|
||||||
|
);
|
||||||
|
|
||||||
|
Some(format!("<div class=\"stab portability\">{}</div>", cfg?.render_long_html()))
|
||||||
|
}
|
||||||
|
|
||||||
/// Render the stability and/or deprecation warning that is displayed at the top of the item's
|
/// Render the stability and/or deprecation warning that is displayed at the top of the item's
|
||||||
/// documentation.
|
/// documentation.
|
||||||
fn short_stability(item: &clean::Item, cx: &Context, parent: Option<&clean::Item>) -> Vec<String> {
|
fn short_stability(item: &clean::Item, cx: &Context, parent: Option<&clean::Item>) -> Vec<String> {
|
||||||
|
@ -2328,19 +2344,8 @@ fn short_stability(item: &clean::Item, cx: &Context, parent: Option<&clean::Item
|
||||||
stability.push(format!("<div class=\"stab unstable\">{}</div>", message));
|
stability.push(format!("<div class=\"stab unstable\">{}</div>", message));
|
||||||
}
|
}
|
||||||
|
|
||||||
let cfg = match (&item.attrs.cfg, parent.and_then(|p| p.attrs.cfg.as_ref())) {
|
if let Some(portability) = portability(item, parent) {
|
||||||
(Some(cfg), Some(parent_cfg)) => cfg.simplify_with(parent_cfg),
|
stability.push(portability);
|
||||||
(cfg, _) => cfg.as_deref().cloned(),
|
|
||||||
};
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
"Portability {:?} - {:?} = {:?}",
|
|
||||||
item.attrs.cfg,
|
|
||||||
parent.and_then(|p| p.attrs.cfg.as_ref()),
|
|
||||||
cfg
|
|
||||||
);
|
|
||||||
if let Some(cfg) = cfg {
|
|
||||||
stability.push(format!("<div class=\"stab portability\">{}</div>", cfg.render_long_html()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stability
|
stability
|
||||||
|
@ -2431,6 +2436,7 @@ fn item_function(w: &mut Buffer, cx: &Context, it: &clean::Item, f: &clean::Func
|
||||||
fn render_implementor(
|
fn render_implementor(
|
||||||
cx: &Context,
|
cx: &Context,
|
||||||
implementor: &Impl,
|
implementor: &Impl,
|
||||||
|
parent: &clean::Item,
|
||||||
w: &mut Buffer,
|
w: &mut Buffer,
|
||||||
implementor_dups: &FxHashMap<&str, (DefId, bool)>,
|
implementor_dups: &FxHashMap<&str, (DefId, bool)>,
|
||||||
aliases: &[String],
|
aliases: &[String],
|
||||||
|
@ -2450,7 +2456,7 @@ fn render_implementor(
|
||||||
w,
|
w,
|
||||||
cx,
|
cx,
|
||||||
implementor,
|
implementor,
|
||||||
None,
|
parent,
|
||||||
AssocItemLink::Anchor(None),
|
AssocItemLink::Anchor(None),
|
||||||
RenderMode::Normal,
|
RenderMode::Normal,
|
||||||
implementor.impl_item.stable_since().as_deref(),
|
implementor.impl_item.stable_since().as_deref(),
|
||||||
|
@ -2480,7 +2486,7 @@ fn render_impls(
|
||||||
&mut buffer,
|
&mut buffer,
|
||||||
cx,
|
cx,
|
||||||
i,
|
i,
|
||||||
Some(containing_item),
|
containing_item,
|
||||||
assoc_link,
|
assoc_link,
|
||||||
RenderMode::Normal,
|
RenderMode::Normal,
|
||||||
containing_item.stable_since().as_deref(),
|
containing_item.stable_since().as_deref(),
|
||||||
|
@ -2727,7 +2733,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
|
||||||
w,
|
w,
|
||||||
cx,
|
cx,
|
||||||
&implementor,
|
&implementor,
|
||||||
None,
|
it,
|
||||||
assoc_link,
|
assoc_link,
|
||||||
RenderMode::Normal,
|
RenderMode::Normal,
|
||||||
implementor.impl_item.stable_since().as_deref(),
|
implementor.impl_item.stable_since().as_deref(),
|
||||||
|
@ -2749,7 +2755,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
|
||||||
"<div class=\"item-list\" id=\"implementors-list\">",
|
"<div class=\"item-list\" id=\"implementors-list\">",
|
||||||
);
|
);
|
||||||
for implementor in concrete {
|
for implementor in concrete {
|
||||||
render_implementor(cx, implementor, w, &implementor_dups, &[], cache);
|
render_implementor(cx, implementor, it, w, &implementor_dups, &[], cache);
|
||||||
}
|
}
|
||||||
write_loading_content(w, "</div>");
|
write_loading_content(w, "</div>");
|
||||||
|
|
||||||
|
@ -2764,6 +2770,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
|
||||||
render_implementor(
|
render_implementor(
|
||||||
cx,
|
cx,
|
||||||
implementor,
|
implementor,
|
||||||
|
it,
|
||||||
w,
|
w,
|
||||||
&implementor_dups,
|
&implementor_dups,
|
||||||
&collect_paths_for_type(implementor.inner_impl().for_.clone()),
|
&collect_paths_for_type(implementor.inner_impl().for_.clone()),
|
||||||
|
@ -3431,7 +3438,7 @@ fn render_assoc_items(
|
||||||
w,
|
w,
|
||||||
cx,
|
cx,
|
||||||
i,
|
i,
|
||||||
Some(containing_item),
|
containing_item,
|
||||||
AssocItemLink::Anchor(None),
|
AssocItemLink::Anchor(None),
|
||||||
render_mode,
|
render_mode,
|
||||||
containing_item.stable_since().as_deref(),
|
containing_item.stable_since().as_deref(),
|
||||||
|
@ -3623,7 +3630,7 @@ fn render_impl(
|
||||||
w: &mut Buffer,
|
w: &mut Buffer,
|
||||||
cx: &Context,
|
cx: &Context,
|
||||||
i: &Impl,
|
i: &Impl,
|
||||||
parent: Option<&clean::Item>,
|
parent: &clean::Item,
|
||||||
link: AssocItemLink<'_>,
|
link: AssocItemLink<'_>,
|
||||||
render_mode: RenderMode,
|
render_mode: RenderMode,
|
||||||
outer_version: Option<&str>,
|
outer_version: Option<&str>,
|
||||||
|
@ -3636,6 +3643,9 @@ fn render_impl(
|
||||||
aliases: &[String],
|
aliases: &[String],
|
||||||
cache: &Cache,
|
cache: &Cache,
|
||||||
) {
|
) {
|
||||||
|
let traits = &cache.traits;
|
||||||
|
let trait_ = i.trait_did().map(|did| &traits[&did]);
|
||||||
|
|
||||||
if render_mode == RenderMode::Normal {
|
if render_mode == RenderMode::Normal {
|
||||||
let id = cx.derive_id(match i.inner_impl().trait_ {
|
let id = cx.derive_id(match i.inner_impl().trait_ {
|
||||||
Some(ref t) => {
|
Some(ref t) => {
|
||||||
|
@ -3688,6 +3698,13 @@ fn render_impl(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
write!(w, "</h3>");
|
write!(w, "</h3>");
|
||||||
|
|
||||||
|
if trait_.is_some() {
|
||||||
|
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
|
||||||
|
write!(w, "<div class=\"stability\">{}</div>", portability);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
|
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
|
||||||
let mut ids = cx.id_map.borrow_mut();
|
let mut ids = cx.id_map.borrow_mut();
|
||||||
write!(
|
write!(
|
||||||
|
@ -3710,7 +3727,7 @@ fn render_impl(
|
||||||
w: &mut Buffer,
|
w: &mut Buffer,
|
||||||
cx: &Context,
|
cx: &Context,
|
||||||
item: &clean::Item,
|
item: &clean::Item,
|
||||||
parent: Option<&clean::Item>,
|
parent: &clean::Item,
|
||||||
link: AssocItemLink<'_>,
|
link: AssocItemLink<'_>,
|
||||||
render_mode: RenderMode,
|
render_mode: RenderMode,
|
||||||
is_default_item: bool,
|
is_default_item: bool,
|
||||||
|
@ -3795,7 +3812,7 @@ fn render_impl(
|
||||||
if let Some(it) = t.items.iter().find(|i| i.name == item.name) {
|
if let Some(it) = t.items.iter().find(|i| i.name == item.name) {
|
||||||
// We need the stability of the item from the trait
|
// We need the stability of the item from the trait
|
||||||
// because impls can't have a stability.
|
// because impls can't have a stability.
|
||||||
document_stability(w, cx, it, is_hidden, parent);
|
document_stability(w, cx, it, is_hidden, Some(parent));
|
||||||
if item.doc_value().is_some() {
|
if item.doc_value().is_some() {
|
||||||
document_full(w, item, cx, "", is_hidden);
|
document_full(w, item, cx, "", is_hidden);
|
||||||
} else if show_def_docs {
|
} else if show_def_docs {
|
||||||
|
@ -3805,13 +3822,13 @@ fn render_impl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
document_stability(w, cx, item, is_hidden, parent);
|
document_stability(w, cx, item, is_hidden, Some(parent));
|
||||||
if show_def_docs {
|
if show_def_docs {
|
||||||
document_full(w, item, cx, "", is_hidden);
|
document_full(w, item, cx, "", is_hidden);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
document_stability(w, cx, item, is_hidden, parent);
|
document_stability(w, cx, item, is_hidden, Some(parent));
|
||||||
if show_def_docs {
|
if show_def_docs {
|
||||||
document_short(w, item, link, "", is_hidden);
|
document_short(w, item, link, "", is_hidden);
|
||||||
}
|
}
|
||||||
|
@ -3819,16 +3836,13 @@ fn render_impl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let traits = &cache.traits;
|
|
||||||
let trait_ = i.trait_did().map(|did| &traits[&did]);
|
|
||||||
|
|
||||||
write!(w, "<div class=\"impl-items\">");
|
write!(w, "<div class=\"impl-items\">");
|
||||||
for trait_item in &i.inner_impl().items {
|
for trait_item in &i.inner_impl().items {
|
||||||
doc_impl_item(
|
doc_impl_item(
|
||||||
w,
|
w,
|
||||||
cx,
|
cx,
|
||||||
trait_item,
|
trait_item,
|
||||||
parent,
|
if trait_.is_some() { &i.impl_item } else { parent },
|
||||||
link,
|
link,
|
||||||
render_mode,
|
render_mode,
|
||||||
false,
|
false,
|
||||||
|
@ -3844,7 +3858,7 @@ fn render_impl(
|
||||||
cx: &Context,
|
cx: &Context,
|
||||||
t: &clean::Trait,
|
t: &clean::Trait,
|
||||||
i: &clean::Impl,
|
i: &clean::Impl,
|
||||||
parent: Option<&clean::Item>,
|
parent: &clean::Item,
|
||||||
render_mode: RenderMode,
|
render_mode: RenderMode,
|
||||||
outer_version: Option<&str>,
|
outer_version: Option<&str>,
|
||||||
show_def_docs: bool,
|
show_def_docs: bool,
|
||||||
|
@ -3885,7 +3899,7 @@ fn render_impl(
|
||||||
cx,
|
cx,
|
||||||
t,
|
t,
|
||||||
&i.inner_impl(),
|
&i.inner_impl(),
|
||||||
parent,
|
&i.impl_item,
|
||||||
render_mode,
|
render_mode,
|
||||||
outer_version,
|
outer_version,
|
||||||
show_def_docs,
|
show_def_docs,
|
||||||
|
|
|
@ -2439,12 +2439,13 @@ function defocusSearchBar() {
|
||||||
|
|
||||||
var func = function(e) {
|
var func = function(e) {
|
||||||
var next = e.nextElementSibling;
|
var next = e.nextElementSibling;
|
||||||
|
if (next && hasClass(next, "stability")) {
|
||||||
|
next = next.nextElementSibling;
|
||||||
|
}
|
||||||
if (!next) {
|
if (!next) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (hasClass(next, "docblock") === true ||
|
if (hasClass(next, "docblock")) {
|
||||||
(hasClass(next, "stability") === true &&
|
|
||||||
hasClass(next.nextElementSibling, "docblock") === true)) {
|
|
||||||
var newToggle = toggle.cloneNode(true);
|
var newToggle = toggle.cloneNode(true);
|
||||||
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
|
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
|
||||||
if (hideMethodDocs === true && hasClass(e, "method") === true) {
|
if (hideMethodDocs === true && hasClass(e, "method") === true) {
|
||||||
|
@ -2455,6 +2456,9 @@ function defocusSearchBar() {
|
||||||
|
|
||||||
var funcImpl = function(e) {
|
var funcImpl = function(e) {
|
||||||
var next = e.nextElementSibling;
|
var next = e.nextElementSibling;
|
||||||
|
if (next && hasClass(next, "stability")) {
|
||||||
|
next = next.nextElementSibling;
|
||||||
|
}
|
||||||
if (next && hasClass(next, "docblock")) {
|
if (next && hasClass(next, "docblock")) {
|
||||||
next = next.nextElementSibling;
|
next = next.nextElementSibling;
|
||||||
}
|
}
|
||||||
|
|
124
src/test/rustdoc/doc-cfg-traits.rs
Normal file
124
src/test/rustdoc/doc-cfg-traits.rs
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
#![crate_name = "myrmecophagous"]
|
||||||
|
#![feature(doc_cfg, associated_type_defaults)]
|
||||||
|
|
||||||
|
// @has 'myrmecophagous/index.html'
|
||||||
|
// @count - '//*[@class="stab portability"]' 2
|
||||||
|
// @matches - '//*[@class="stab portability"]' '^jurisconsult$'
|
||||||
|
// @matches - '//*[@class="stab portability"]' '^quarter$'
|
||||||
|
|
||||||
|
pub trait Lea {}
|
||||||
|
|
||||||
|
// @has 'myrmecophagous/trait.Vortoscope.html'
|
||||||
|
// @count - '//*[@class="stab portability"]' 6
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature zibib'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature poriform'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature ethopoeia'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature lea'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature unit'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature quarter'
|
||||||
|
pub trait Vortoscope {
|
||||||
|
type Batology = ();
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "zibib"))]
|
||||||
|
type Zibib = ();
|
||||||
|
|
||||||
|
const YAHRZEIT: () = ();
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "poriform"))]
|
||||||
|
const PORIFORM: () = ();
|
||||||
|
|
||||||
|
fn javanais() {}
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "ethopoeia"))]
|
||||||
|
fn ethopoeia() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "lea"))]
|
||||||
|
impl<T: Lea> Vortoscope for T {}
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "unit"))]
|
||||||
|
impl Vortoscope for () {}
|
||||||
|
|
||||||
|
// @has 'myrmecophagous/trait.Jurisconsult.html'
|
||||||
|
// @count - '//*[@class="stab portability"]' 7
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature jurisconsult'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature lithomancy'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature boodle'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature mistetch'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature lea'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature unit'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature quarter'
|
||||||
|
#[doc(cfg(feature = "jurisconsult"))]
|
||||||
|
pub trait Jurisconsult {
|
||||||
|
type Urbanist = ();
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "lithomancy"))]
|
||||||
|
type Lithomancy = ();
|
||||||
|
|
||||||
|
const UNIFILAR: () = ();
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "boodle"))]
|
||||||
|
const BOODLE: () = ();
|
||||||
|
|
||||||
|
fn mersion() {}
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "mistetch"))]
|
||||||
|
fn mistetch() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "lea"))]
|
||||||
|
impl<T: Lea> Jurisconsult for T {}
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "unit"))]
|
||||||
|
impl Jurisconsult for () {}
|
||||||
|
|
||||||
|
// @has 'myrmecophagous/struct.Ultimogeniture.html'
|
||||||
|
// @count - '//*[@class="stab portability"]' 8
|
||||||
|
//
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature zibib'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature poriform'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature ethopoeia'
|
||||||
|
//
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature jurisconsult'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature lithomancy'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature boodle'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature mistetch'
|
||||||
|
//
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature copy'
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Ultimogeniture;
|
||||||
|
|
||||||
|
impl Vortoscope for Ultimogeniture {}
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "jurisconsult"))]
|
||||||
|
impl Jurisconsult for Ultimogeniture {}
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "copy"))]
|
||||||
|
impl Copy for Ultimogeniture {}
|
||||||
|
|
||||||
|
// @has 'myrmecophagous/struct.Quarter.html'
|
||||||
|
// @count - '//*[@class="stab portability"]' 9
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature quarter'
|
||||||
|
//
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature zibib'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature poriform'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature ethopoeia'
|
||||||
|
//
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature jurisconsult'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature lithomancy'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature boodle'
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature mistetch'
|
||||||
|
//
|
||||||
|
// @matches - '//*[@class="stab portability"]' 'crate feature copy'
|
||||||
|
#[doc(cfg(feature = "quarter"))]
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Quarter;
|
||||||
|
|
||||||
|
#[doc(cfg(feature = "quarter"))]
|
||||||
|
impl Vortoscope for Quarter {}
|
||||||
|
|
||||||
|
#[doc(cfg(all(feature = "jurisconsult", feature = "quarter")))]
|
||||||
|
impl Jurisconsult for Quarter {}
|
||||||
|
|
||||||
|
#[doc(cfg(all(feature = "copy", feature = "quarter")))]
|
||||||
|
impl Copy for Quarter {}
|
Loading…
Add table
Add a link
Reference in a new issue