Skip to content

Commit d40a18e

Browse files
Remove the extra DOM level if there is only one child in rightside elements
1 parent 097b382 commit d40a18e

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -834,12 +834,13 @@ fn assoc_method(
834834
/// Note that it is possible for an unstable function to be const-stable. In that case, the span
835835
/// will include the const-stable version, but no stable version will be emitted, as a natural
836836
/// consequence of the above rules.
837-
fn render_stability_since_raw(
837+
fn render_stability_since_raw_with_extra(
838838
w: &mut Buffer,
839839
ver: Option<Symbol>,
840840
const_stability: Option<ConstStability>,
841841
containing_ver: Option<Symbol>,
842842
containing_const_ver: Option<Symbol>,
843+
extra_class: &str,
843844
) -> bool {
844845
let stable_version = ver.filter(|inner| !inner.is_empty() && Some(*inner) != containing_ver);
845846

@@ -887,12 +888,30 @@ fn render_stability_since_raw(
887888
}
888889

889890
if !stability.is_empty() {
890-
write!(w, r#"<span class="since" title="{}">{}</span>"#, title, stability);
891+
write!(w, r#"<span class="since{extra_class}" title="{title}">{stability}</span>"#);
891892
}
892893

893894
!stability.is_empty()
894895
}
895896

897+
#[inline]
898+
fn render_stability_since_raw(
899+
w: &mut Buffer,
900+
ver: Option<Symbol>,
901+
const_stability: Option<ConstStability>,
902+
containing_ver: Option<Symbol>,
903+
containing_const_ver: Option<Symbol>,
904+
) -> bool {
905+
render_stability_since_raw_with_extra(
906+
w,
907+
ver,
908+
const_stability,
909+
containing_ver,
910+
containing_const_ver,
911+
"",
912+
)
913+
}
914+
896915
fn render_assoc_item(
897916
w: &mut Buffer,
898917
item: &clean::Item,
@@ -1675,25 +1694,29 @@ fn render_rightside(
16751694
RenderMode::Normal => (item.const_stability(tcx), containing_item.const_stable_since(tcx)),
16761695
RenderMode::ForDeref { .. } => (None, None),
16771696
};
1697+
let src_href = cx.src_href(item);
1698+
let has_src_ref = src_href.is_some();
16781699

16791700
let mut rightside = Buffer::new();
1680-
let has_stability = render_stability_since_raw(
1701+
let has_stability = render_stability_since_raw_with_extra(
16811702
&mut rightside,
16821703
item.stable_since(tcx),
16831704
const_stability,
16841705
containing_item.stable_since(tcx),
16851706
const_stable_since,
1707+
if has_src_ref { "" } else { " rightside" },
16861708
);
1687-
let mut srclink = Buffer::empty_from(w);
1688-
if let Some(l) = cx.src_href(item) {
1689-
write!(srclink, "<a class=\"srclink\" href=\"{}\">source</a>", l)
1690-
}
1691-
if has_stability && !srclink.is_empty() {
1692-
rightside.write_str(" · ");
1709+
if let Some(l) = src_href {
1710+
if has_stability {
1711+
write!(rightside, " · <a class=\"srclink\" href=\"{}\">source</a>", l)
1712+
} else {
1713+
write!(rightside, "<a class=\"srclink rightside\" href=\"{}\">source</a>", l)
1714+
}
16931715
}
1694-
rightside.push_buffer(srclink);
1695-
if !rightside.is_empty() {
1716+
if has_stability && has_src_ref {
16961717
write!(w, "<span class=\"rightside\">{}</span>", rightside.into_inner());
1718+
} else {
1719+
w.push_buffer(rightside);
16971720
}
16981721
}
16991722

src/librustdoc/html/static/css/themes/ayu.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ details.rustdoc-toggle > summary::before {
199199
background: none;
200200
}
201201

202-
.rightside,
202+
.rightside:not(a),
203203
.out-of-band {
204204
color: grey;
205205
}

src/librustdoc/html/static/css/themes/dark.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ details.rustdoc-toggle > summary::before {
165165
background: none;
166166
}
167167

168-
.rightside,
168+
.rightside:not(a),
169169
.out-of-band {
170170
color: grey;
171171
}

src/librustdoc/html/static/css/themes/light.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ details.rustdoc-toggle > summary::before {
148148
.stab { background: #FFF5D6; border-color: #FFC600; }
149149
.stab.portability > code { background: none; }
150150

151-
.rightside,
151+
.rightside:not(a),
152152
.out-of-band {
153153
color: grey;
154154
}

0 commit comments

Comments
 (0)