Skip to content

Commit fb9d3a5

Browse files
Simplify the sorting of impls and use CSS classes instead of plain JS to show/hide implementors
1 parent 13091dd commit fb9d3a5

File tree

5 files changed

+17
-34
lines changed

5 files changed

+17
-34
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,18 +650,18 @@ fn item_function(cx: &Context<'_>, it: &clean::Item, f: &clean::Function) -> imp
650650
///
651651
/// This marker appears once in all trait impl lists to divide negative impls from positive impls.
652652
struct NegativeMarker {
653-
inserted_negative_marker: bool,
653+
inserted: bool,
654654
}
655655

656656
impl NegativeMarker {
657657
fn new() -> Self {
658-
Self { inserted_negative_marker: false }
658+
Self { inserted: false }
659659
}
660660

661661
fn insert_if_needed(&mut self, w: &mut fmt::Formatter<'_>, implementor: &Impl) -> fmt::Result {
662-
if !self.inserted_negative_marker && !implementor.is_negative_trait_impl() {
663-
write!(w, "<div class=\"negative-marker\"></div>")?;
664-
self.inserted_negative_marker = true;
662+
if !self.inserted && !implementor.is_negative_trait_impl() {
663+
w.write_str("<div class=\"negative-marker\"></div>")?;
664+
self.inserted = true;
665665
}
666666
Ok(())
667667
}

src/librustdoc/html/render/write_shared.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,14 @@ impl TraitAliasPart {
747747
path.push(format!("{remote_item_type}.{}.js", remote_path[remote_path.len() - 1]));
748748

749749
let mut implementors = implementors.collect::<Vec<_>>();
750-
implementors.sort_unstable();
750+
implementors.sort_unstable_by(|a, b| {
751+
// We sort negative impls first.
752+
match (a.is_negative, b.is_negative) {
753+
(false, true) => Ordering::Greater,
754+
(true, false) => Ordering::Less,
755+
_ => compare_names(&a.text, &b.text),
756+
}
757+
});
751758

752759
let part = OrderedJson::array_unsorted(
753760
implementors
@@ -762,7 +769,6 @@ impl TraitAliasPart {
762769
}
763770
}
764771

765-
#[derive(Eq)]
766772
struct Implementor {
767773
text: String,
768774
synthetic: bool,
@@ -786,29 +792,6 @@ impl Serialize for Implementor {
786792
}
787793
}
788794

789-
impl PartialEq for Implementor {
790-
fn eq(&self, other: &Self) -> bool {
791-
self.cmp(other) == Ordering::Equal
792-
}
793-
}
794-
795-
impl PartialOrd for Implementor {
796-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
797-
Some(Ord::cmp(self, other))
798-
}
799-
}
800-
801-
impl Ord for Implementor {
802-
fn cmp(&self, other: &Self) -> Ordering {
803-
// We sort negative impls first.
804-
match (self.is_negative, other.is_negative) {
805-
(false, true) => Ordering::Greater,
806-
(true, false) => Ordering::Less,
807-
_ => compare_names(&self.text, &other.text),
808-
}
809-
}
810-
}
811-
812795
/// Collect the list of aliased types and their aliases.
813796
/// <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
814797
///

src/librustdoc/html/static/css/noscript.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ nav.sub {
2929
display: none;
3030
}
3131

32-
#synthetic-implementors-list, #implementors-list {
32+
#synthetic-implementors-list:not(.loaded), #implementors-list:not(.loaded) {
3333
display: block;
3434
}
3535

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ div.where {
11581158
margin-left: calc(var(--docblock-indent) + var(--impl-items-indent));
11591159
}
11601160

1161-
#synthetic-implementors-list, #implementors-list {
1161+
#synthetic-implementors-list:not(.loaded), #implementors-list:not(.loaded) {
11621162
/* To prevent layout shift when loading the page with extra implementors being loaded
11631163
from JS, we hide the list until it's complete. */
11641164
display: none;

src/librustdoc/html/static/js/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,10 @@ function preLoadCss(cssUrl) {
911911
}
912912
}
913913
if (implementors[0]) {
914-
implementors[0].style.display = "block";
914+
implementors[0].classList.add("loaded");
915915
}
916916
if (syntheticImplementors[0]) {
917-
syntheticImplementors[0].style.display = "block";
917+
syntheticImplementors[0].classList.add("loaded");
918918
}
919919
};
920920
if (window.pending_implementors) {

0 commit comments

Comments
 (0)