Skip to content

Commit

Permalink
Make portability part of the summary.
Browse files Browse the repository at this point in the history
That means it will be visible under "Implementors" on trait pages, and
under "Implementations" on struct/enum pages, even when all methods are
collapsed.

Switch to a float layout for rightside elements.
  • Loading branch information
jsha committed Jun 17, 2021
1 parent 910c7fa commit 593d6d1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
17 changes: 12 additions & 5 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@ fn render_impl(
w,
cx,
i,
parent,
outer_version,
outer_const_version,
show_def_docs,
Expand All @@ -1562,11 +1563,6 @@ fn render_impl(
if toggled {
write!(w, "</summary>")
}
if trait_.is_some() {
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
write!(w, "<div class=\"item-info\">{}</div>", portability);
}
}

if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
let mut ids = cx.id_map.borrow_mut();
Expand Down Expand Up @@ -1598,6 +1594,7 @@ pub(crate) fn render_impl_summary(
w: &mut Buffer,
cx: &Context<'_>,
i: &Impl,
parent: &clean::Item,
outer_version: Option<&str>,
outer_const_version: Option<&str>,
show_def_docs: bool,
Expand Down Expand Up @@ -1652,6 +1649,7 @@ pub(crate) fn render_impl_summary(
);
}
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
write!(w, "<div class=\"rightside\">");
render_stability_since_raw(
w,
i.impl_item.stable_since(tcx).as_deref(),
Expand All @@ -1660,6 +1658,15 @@ pub(crate) fn render_impl_summary(
outer_const_version,
);
write_srclink(cx, &i.impl_item, w);
w.write_str("</div>"); // end of "rightside"

let is_trait = i.inner_impl().trait_.is_some();
if is_trait {
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
write!(w, "<div class=\"item-info\">{}</div>", portability);
}
}

w.write_str("</div>");
}

Expand Down
13 changes: 9 additions & 4 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,14 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
if toggled {
write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
}
write!(w, "<div id=\"{}\" class=\"method has-srclink\"><code>", id);
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
w.write_str("</code>");
write!(w, "<div id=\"{}\" class=\"method has-srclink\">", id);
write!(w, "<div class=\"rightside\">");
render_stability_since(w, m, t, cx.tcx());
write_srclink(cx, m, w);
write!(w, "</div>");
write!(w, "<code>");
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
w.write_str("</code>");
w.write_str("</div>");
if toggled {
write!(w, "</summary>");
Expand Down Expand Up @@ -697,6 +700,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
w,
cx,
&implementor,
it,
outer_version.as_deref(),
outer_const_version.as_deref(),
false,
Expand Down Expand Up @@ -1305,7 +1309,7 @@ fn render_implementor(
implementor_dups: &FxHashMap<Symbol, (DefId, bool)>,
aliases: &[String],
) {
// If there's already another implementor that has the same abbridged name, use the
// If there's already another implementor that has the same abridged name, use the
// full path, for example in `std::iter::ExactSizeIterator`
let use_absolute = match implementor.inner_impl().for_ {
clean::ResolvedPath { ref path, is_generic: false, .. }
Expand All @@ -1321,6 +1325,7 @@ fn render_implementor(
w,
cx,
implementor,
trait_,
outer_version.as_deref(),
outer_const_version.as_deref(),
false,
Expand Down
12 changes: 3 additions & 9 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ nav.sub {
.content .item-info {
position: relative;
margin-left: 33px;
margin-top: -13px;
}

.sub-variant > div > .item-info {
Expand Down Expand Up @@ -852,12 +851,12 @@ body.blur > :not(#help) {
}

.stab {
display: table;
border-width: 1px;
border-style: solid;
padding: 3px;
margin-bottom: 5px;
font-size: 90%;
font-weight: normal;
}
.stab p {
display: inline;
Expand Down Expand Up @@ -906,26 +905,22 @@ body.blur > :not(#help) {
}

.impl-items .since, .impl .since, .methods .since {
flex-grow: 0;
padding-left: 12px;
padding-right: 2px;
position: initial;
}

.impl-items .srclink, .impl .srclink, .methods .srclink {
flex-grow: 0;
/* Override header settings otherwise it's too bold */
font-size: 17px;
font-weight: normal;
}

.impl-items code, .impl code, .methods code {
flex-grow: 1;
.rightside {
float: right;
}

.has-srclink {
display: flex;
flex-basis: 100%;
font-size: 16px;
margin-bottom: 12px;
/* Push the src link out to the right edge consistently */
Expand Down Expand Up @@ -986,7 +981,6 @@ a.test-arrow:hover{
}

.since + .srclink {
display: table-cell;
padding-left: 10px;
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/rustdoc/src-links-auto-impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

// @has foo/struct.Unsized.html
// @has - '//div[@id="impl-Sized"]/code' 'impl !Sized for Unsized'
// @!has - '//div[@id="impl-Sized"]/a[@class="srclink"]' '[src]'
// @!has - '//div[@id="impl-Sized"]//a[@class="srclink"]' '[src]'
// @has - '//div[@id="impl-Sync"]/code' 'impl Sync for Unsized'
// @!has - '//div[@id="impl-Sync"]/a[@class="srclink"]' '[src]'
// @!has - '//div[@id="impl-Sync"]//a[@class="srclink"]' '[src]'
// @has - '//div[@id="impl-Any"]/code' 'impl<T> Any for T'
// @has - '//div[@id="impl-Any"]/a[@class="srclink"]' '[src]'
// @has - '//div[@id="impl-Any"]//a[@class="srclink"]' '[src]'
pub struct Unsized {
data: [u8],
}

0 comments on commit 593d6d1

Please sign in to comment.