Fix target highlighting in rustdoc.
Also factor out outer_version and const_outer_version into render_rightside.
This commit is contained in:
parent
c4fa6d5827
commit
2ac5c1721a
8 changed files with 38 additions and 48 deletions
|
@ -723,6 +723,8 @@ fn short_item_info(
|
||||||
extra_info
|
extra_info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the list of items inside one of the sections "Trait Implementations",
|
||||||
|
// "Auto Trait Implementations," "Blanket Trait Implementations" (on struct/enum pages).
|
||||||
fn render_impls(
|
fn render_impls(
|
||||||
cx: &Context<'_>,
|
cx: &Context<'_>,
|
||||||
w: &mut Buffer,
|
w: &mut Buffer,
|
||||||
|
@ -745,8 +747,6 @@ fn render_impls(
|
||||||
containing_item,
|
containing_item,
|
||||||
assoc_link,
|
assoc_link,
|
||||||
RenderMode::Normal,
|
RenderMode::Normal,
|
||||||
containing_item.stable_since(tcx).as_deref(),
|
|
||||||
containing_item.const_stable_since(tcx).as_deref(),
|
|
||||||
true,
|
true,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
|
@ -1024,7 +1024,6 @@ fn render_assoc_items(
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
let tcx = cx.tcx();
|
|
||||||
let cache = cx.cache();
|
let cache = cx.cache();
|
||||||
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
|
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
|
||||||
if !non_trait.is_empty() {
|
if !non_trait.is_empty() {
|
||||||
|
@ -1058,8 +1057,6 @@ fn render_assoc_items(
|
||||||
containing_item,
|
containing_item,
|
||||||
AssocItemLink::Anchor(None),
|
AssocItemLink::Anchor(None),
|
||||||
render_mode,
|
render_mode,
|
||||||
containing_item.stable_since(tcx).as_deref(),
|
|
||||||
containing_item.const_stable_since(tcx).as_deref(),
|
|
||||||
true,
|
true,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
|
@ -1260,8 +1257,6 @@ fn render_impl(
|
||||||
parent: &clean::Item,
|
parent: &clean::Item,
|
||||||
link: AssocItemLink<'_>,
|
link: AssocItemLink<'_>,
|
||||||
render_mode: RenderMode,
|
render_mode: RenderMode,
|
||||||
outer_version: Option<&str>,
|
|
||||||
outer_const_version: Option<&str>,
|
|
||||||
show_def_docs: bool,
|
show_def_docs: bool,
|
||||||
use_absolute: Option<bool>,
|
use_absolute: Option<bool>,
|
||||||
is_on_foreign_type: bool,
|
is_on_foreign_type: bool,
|
||||||
|
@ -1278,17 +1273,18 @@ fn render_impl(
|
||||||
// For trait implementations, the `interesting` output contains all methods that have doc
|
// For trait implementations, the `interesting` output contains all methods that have doc
|
||||||
// comments, and the `boring` output contains all methods that do not. The distinction is
|
// comments, and the `boring` output contains all methods that do not. The distinction is
|
||||||
// used to allow hiding the boring methods.
|
// used to allow hiding the boring methods.
|
||||||
|
// `containing_item` is used for rendering stability info. If the parent is a trait impl,
|
||||||
|
// `containing_item` will the grandparent, since trait impls can't have stability attached.
|
||||||
fn doc_impl_item(
|
fn doc_impl_item(
|
||||||
boring: &mut Buffer,
|
boring: &mut Buffer,
|
||||||
interesting: &mut Buffer,
|
interesting: &mut Buffer,
|
||||||
cx: &Context<'_>,
|
cx: &Context<'_>,
|
||||||
item: &clean::Item,
|
item: &clean::Item,
|
||||||
parent: &clean::Item,
|
parent: &clean::Item,
|
||||||
|
containing_item: &clean::Item,
|
||||||
link: AssocItemLink<'_>,
|
link: AssocItemLink<'_>,
|
||||||
render_mode: RenderMode,
|
render_mode: RenderMode,
|
||||||
is_default_item: bool,
|
is_default_item: bool,
|
||||||
outer_version: Option<&str>,
|
|
||||||
outer_const_version: Option<&str>,
|
|
||||||
trait_: Option<&clean::Trait>,
|
trait_: Option<&clean::Trait>,
|
||||||
show_def_docs: bool,
|
show_def_docs: bool,
|
||||||
) {
|
) {
|
||||||
|
@ -1362,7 +1358,7 @@ fn render_impl(
|
||||||
"<div id=\"{}\" class=\"{}{} has-srclink\">",
|
"<div id=\"{}\" class=\"{}{} has-srclink\">",
|
||||||
id, item_type, in_trait_class,
|
id, item_type, in_trait_class,
|
||||||
);
|
);
|
||||||
render_rightside(w, cx, item, outer_version, outer_const_version);
|
render_rightside(w, cx, item, containing_item);
|
||||||
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
|
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
|
||||||
w.write_str("<code>");
|
w.write_str("<code>");
|
||||||
render_assoc_item(
|
render_assoc_item(
|
||||||
|
@ -1406,7 +1402,7 @@ fn render_impl(
|
||||||
"<div id=\"{}\" class=\"{}{} has-srclink\">",
|
"<div id=\"{}\" class=\"{}{} has-srclink\">",
|
||||||
id, item_type, in_trait_class
|
id, item_type, in_trait_class
|
||||||
);
|
);
|
||||||
render_rightside(w, cx, item, outer_version, outer_const_version);
|
render_rightside(w, cx, item, containing_item);
|
||||||
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
|
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
|
||||||
w.write_str("<code>");
|
w.write_str("<code>");
|
||||||
assoc_const(
|
assoc_const(
|
||||||
|
@ -1461,11 +1457,10 @@ fn render_impl(
|
||||||
cx,
|
cx,
|
||||||
trait_item,
|
trait_item,
|
||||||
if trait_.is_some() { &i.impl_item } else { parent },
|
if trait_.is_some() { &i.impl_item } else { parent },
|
||||||
|
parent,
|
||||||
link,
|
link,
|
||||||
render_mode,
|
render_mode,
|
||||||
false,
|
false,
|
||||||
outer_version,
|
|
||||||
outer_const_version,
|
|
||||||
trait_.map(|t| &t.trait_),
|
trait_.map(|t| &t.trait_),
|
||||||
show_def_docs,
|
show_def_docs,
|
||||||
);
|
);
|
||||||
|
@ -1478,9 +1473,8 @@ fn render_impl(
|
||||||
t: &clean::Trait,
|
t: &clean::Trait,
|
||||||
i: &clean::Impl,
|
i: &clean::Impl,
|
||||||
parent: &clean::Item,
|
parent: &clean::Item,
|
||||||
|
containing_item: &clean::Item,
|
||||||
render_mode: RenderMode,
|
render_mode: RenderMode,
|
||||||
outer_version: Option<&str>,
|
|
||||||
outer_const_version: Option<&str>,
|
|
||||||
show_def_docs: bool,
|
show_def_docs: bool,
|
||||||
) {
|
) {
|
||||||
for trait_item in &t.items {
|
for trait_item in &t.items {
|
||||||
|
@ -1498,11 +1492,10 @@ fn render_impl(
|
||||||
cx,
|
cx,
|
||||||
trait_item,
|
trait_item,
|
||||||
parent,
|
parent,
|
||||||
|
containing_item,
|
||||||
assoc_link,
|
assoc_link,
|
||||||
render_mode,
|
render_mode,
|
||||||
true,
|
true,
|
||||||
outer_version,
|
|
||||||
outer_const_version,
|
|
||||||
Some(t),
|
Some(t),
|
||||||
show_def_docs,
|
show_def_docs,
|
||||||
);
|
);
|
||||||
|
@ -1522,9 +1515,8 @@ fn render_impl(
|
||||||
&t.trait_,
|
&t.trait_,
|
||||||
&i.inner_impl(),
|
&i.inner_impl(),
|
||||||
&i.impl_item,
|
&i.impl_item,
|
||||||
|
parent,
|
||||||
render_mode,
|
render_mode,
|
||||||
outer_version,
|
|
||||||
outer_const_version,
|
|
||||||
show_def_docs,
|
show_def_docs,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1541,8 +1533,7 @@ fn render_impl(
|
||||||
cx,
|
cx,
|
||||||
i,
|
i,
|
||||||
parent,
|
parent,
|
||||||
outer_version,
|
parent,
|
||||||
outer_const_version,
|
|
||||||
show_def_docs,
|
show_def_docs,
|
||||||
use_absolute,
|
use_absolute,
|
||||||
is_on_foreign_type,
|
is_on_foreign_type,
|
||||||
|
@ -1578,12 +1569,13 @@ fn render_impl(
|
||||||
w.write_str(&close_tags);
|
w.write_str(&close_tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the items that appear on the right side of methods, impls, and
|
||||||
|
// associated types. For example "1.0.0 (const: 1.39.0) [src]".
|
||||||
fn render_rightside(
|
fn render_rightside(
|
||||||
w: &mut Buffer,
|
w: &mut Buffer,
|
||||||
cx: &Context<'_>,
|
cx: &Context<'_>,
|
||||||
item: &clean::Item,
|
item: &clean::Item,
|
||||||
outer_version: Option<&str>,
|
containing_item: &clean::Item,
|
||||||
outer_const_version: Option<&str>,
|
|
||||||
) {
|
) {
|
||||||
let tcx = cx.tcx();
|
let tcx = cx.tcx();
|
||||||
|
|
||||||
|
@ -1592,8 +1584,8 @@ fn render_rightside(
|
||||||
w,
|
w,
|
||||||
item.stable_since(tcx).as_deref(),
|
item.stable_since(tcx).as_deref(),
|
||||||
item.const_stable_since(tcx).as_deref(),
|
item.const_stable_since(tcx).as_deref(),
|
||||||
outer_version,
|
containing_item.stable_since(tcx).as_deref(),
|
||||||
outer_const_version,
|
containing_item.const_stable_since(tcx).as_deref(),
|
||||||
);
|
);
|
||||||
|
|
||||||
write_srclink(cx, item, w);
|
write_srclink(cx, item, w);
|
||||||
|
@ -1605,8 +1597,7 @@ pub(crate) fn render_impl_summary(
|
||||||
cx: &Context<'_>,
|
cx: &Context<'_>,
|
||||||
i: &Impl,
|
i: &Impl,
|
||||||
parent: &clean::Item,
|
parent: &clean::Item,
|
||||||
outer_version: Option<&str>,
|
containing_item: &clean::Item,
|
||||||
outer_const_version: Option<&str>,
|
|
||||||
show_def_docs: bool,
|
show_def_docs: bool,
|
||||||
use_absolute: Option<bool>,
|
use_absolute: Option<bool>,
|
||||||
is_on_foreign_type: bool,
|
is_on_foreign_type: bool,
|
||||||
|
@ -1630,7 +1621,7 @@ pub(crate) fn render_impl_summary(
|
||||||
format!(" data-aliases=\"{}\"", aliases.join(","))
|
format!(" data-aliases=\"{}\"", aliases.join(","))
|
||||||
};
|
};
|
||||||
write!(w, "<div id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases);
|
write!(w, "<div id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases);
|
||||||
render_rightside(w, cx, &i.impl_item, outer_version, outer_const_version);
|
render_rightside(w, cx, &i.impl_item, containing_item);
|
||||||
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
|
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
|
||||||
write!(w, "<code class=\"in-band\">");
|
write!(w, "<code class=\"in-band\">");
|
||||||
|
|
||||||
|
|
|
@ -694,15 +694,12 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");
|
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");
|
||||||
|
|
||||||
for implementor in foreign {
|
for implementor in foreign {
|
||||||
let outer_version = implementor.impl_item.stable_since(cx.tcx());
|
|
||||||
let outer_const_version = implementor.impl_item.const_stable_since(cx.tcx());
|
|
||||||
render_impl_summary(
|
render_impl_summary(
|
||||||
w,
|
w,
|
||||||
cx,
|
cx,
|
||||||
&implementor,
|
&implementor,
|
||||||
it,
|
it,
|
||||||
outer_version.as_deref(),
|
&implementor.impl_item,
|
||||||
outer_const_version.as_deref(),
|
|
||||||
false,
|
false,
|
||||||
None,
|
None,
|
||||||
true,
|
true,
|
||||||
|
@ -1319,15 +1316,12 @@ fn render_implementor(
|
||||||
} => implementor_dups[&path.last()].1,
|
} => implementor_dups[&path.last()].1,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
let outer_version = trait_.stable_since(cx.tcx());
|
|
||||||
let outer_const_version = trait_.const_stable_since(cx.tcx());
|
|
||||||
render_impl_summary(
|
render_impl_summary(
|
||||||
w,
|
w,
|
||||||
cx,
|
cx,
|
||||||
implementor,
|
implementor,
|
||||||
trait_,
|
trait_,
|
||||||
outer_version.as_deref(),
|
trait_,
|
||||||
outer_const_version.as_deref(),
|
|
||||||
false,
|
false,
|
||||||
Some(use_absolute),
|
Some(use_absolute),
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -1037,6 +1037,10 @@ a.test-arrow:hover{
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:target {
|
||||||
|
padding-right: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
.information {
|
.information {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: -25px;
|
left: -25px;
|
||||||
|
|
|
@ -334,8 +334,11 @@ a.test-arrow:hover {
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
:target > code, :target > .in-band {
|
:target, :target * {
|
||||||
background: rgba(255, 236, 164, 0.06);
|
background: rgba(255, 236, 164, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
:target {
|
||||||
border-right: 3px solid rgba(255, 180, 76, 0.85);
|
border-right: 3px solid rgba(255, 180, 76, 0.85);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -282,8 +282,11 @@ a.test-arrow:hover{
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
:target > code, :target > .in-band {
|
:target, :target * {
|
||||||
background-color: #494a3d;
|
background-color: #494a3d;
|
||||||
|
}
|
||||||
|
|
||||||
|
:target {
|
||||||
border-right: 3px solid #bb7410;
|
border-right: 3px solid #bb7410;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,8 +275,11 @@ a.test-arrow:hover{
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
:target > code, :target > .in-band {
|
:target, :target * {
|
||||||
background: #FDFFD3;
|
background: #FDFFD3;
|
||||||
|
}
|
||||||
|
|
||||||
|
:target {
|
||||||
border-right: 3px solid #ffb44c;
|
border-right: 3px solid #ffb44c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
// This test ensures that the [src] link is present on traits items.
|
// This test ensures that the [src] link is present on traits items.
|
||||||
|
|
||||||
// @has foo/trait.Iterator.html '//div[@id="method.zip"]/a[@class="srclink"]' "[src]"
|
// @has foo/trait.Iterator.html '//div[@id="method.zip"]//a[@class="srclink"]' "[src]"
|
||||||
pub use std::iter::Iterator;
|
pub use std::iter::Iterator;
|
||||||
|
|
|
@ -38,23 +38,15 @@ impl MyTrait for Vec<u8> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MyTrait for MyStruct {
|
impl MyTrait for MyStruct {
|
||||||
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-3"]//a[@class="type"]/@href' #associatedtype.Assoc
|
|
||||||
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-3"]//a[@class="anchor"]/@href' #associatedtype.Assoc-3
|
|
||||||
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="type"]/@href' trait.MyTrait.html#associatedtype.Assoc
|
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="type"]/@href' trait.MyTrait.html#associatedtype.Assoc
|
||||||
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="anchor"]/@href' #associatedtype.Assoc
|
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="anchor"]/@href' #associatedtype.Assoc
|
||||||
type Assoc = bool;
|
type Assoc = bool;
|
||||||
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-3"]//a[@class="constant"]/@href' #associatedconstant.VALUE
|
|
||||||
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-3"]//a[@class="anchor"]/@href' #associatedconstant.VALUE-3
|
|
||||||
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedconstant.VALUE"]//a[@class="constant"]/@href' trait.MyTrait.html#associatedconstant.VALUE
|
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedconstant.VALUE"]//a[@class="constant"]/@href' trait.MyTrait.html#associatedconstant.VALUE
|
||||||
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedconstant.VALUE"]//a[@class="anchor"]/@href' #associatedconstant.VALUE
|
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedconstant.VALUE"]//a[@class="anchor"]/@href' #associatedconstant.VALUE
|
||||||
const VALUE: u32 = 20;
|
const VALUE: u32 = 20;
|
||||||
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="method.trait_function-2"]//a[@class="fnname"]/@href' #tymethod.trait_function
|
|
||||||
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="method.trait_function-2"]//a[@class="anchor"]/@href' #method.trait_function-2
|
|
||||||
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="method.trait_function"]//a[@class="fnname"]/@href' trait.MyTrait.html#tymethod.trait_function
|
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="method.trait_function"]//a[@class="fnname"]/@href' trait.MyTrait.html#tymethod.trait_function
|
||||||
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="method.trait_function"]//a[@class="anchor"]/@href' #method.trait_function
|
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="method.trait_function"]//a[@class="anchor"]/@href' #method.trait_function
|
||||||
fn trait_function(&self) {}
|
fn trait_function(&self) {}
|
||||||
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="method.defaulted_override-3"]//a[@class="fnname"]/@href' #method.defaulted_override
|
|
||||||
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="method.defaulted_override-3"]//a[@class="anchor"]/@href' #method.defaulted_override-3
|
|
||||||
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="method.defaulted_override"]//a[@class="fnname"]/@href' trait.MyTrait.html#method.defaulted_override
|
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="method.defaulted_override"]//a[@class="fnname"]/@href' trait.MyTrait.html#method.defaulted_override
|
||||||
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="method.defaulted_override"]//a[@class="anchor"]/@href' #method.defaulted_override
|
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="method.defaulted_override"]//a[@class="anchor"]/@href' #method.defaulted_override
|
||||||
fn defaulted_override(&self) {}
|
fn defaulted_override(&self) {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue