Skip to content

Commit 1bfb64b

Browse files
committed
rustdoc: Sort negative impls to the top
1 parent 72da5a9 commit 1bfb64b

File tree

1 file changed

+17
-1
lines changed
  • src/librustdoc/html/render

1 file changed

+17
-1
lines changed

src/librustdoc/html/render/mod.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ use rustc_span::symbol::{sym, Symbol};
6363
use serde::ser::SerializeSeq;
6464
use serde::{Serialize, Serializer};
6565

66-
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, RenderedLink, SelfTy, TypeKind};
66+
use crate::clean::{
67+
self, AttributesExt, Deprecation, GetDefId, ImplPolarity, RenderedLink, SelfTy, TypeKind,
68+
};
6769
use crate::config::{RenderInfo, RenderOptions};
6870
use crate::docfs::{DocFS, PathError};
6971
use crate::doctree;
@@ -2532,6 +2534,16 @@ fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl) -> Ordering {
25322534
compare_names(&lhs, &rhs)
25332535
}
25342536

2537+
fn compare_impl_polarity(a: &Impl, b: &Impl) -> Ordering {
2538+
match (a.inner_impl().polarity.as_ref(), b.inner_impl().polarity.as_ref()) {
2539+
(Some(ImplPolarity::Positive), Some(ImplPolarity::Negative)) => Ordering::Greater,
2540+
(Some(ImplPolarity::Negative), Some(ImplPolarity::Positive)) => Ordering::Less,
2541+
(Some(ImplPolarity::Positive), Some(ImplPolarity::Positive))
2542+
| (Some(ImplPolarity::Negative), Some(ImplPolarity::Negative)) => Ordering::Equal,
2543+
(None, _) | (_, None) => Ordering::Equal,
2544+
}
2545+
}
2546+
25352547
fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait, cache: &Cache) {
25362548
let bounds = bounds(&t.bounds, false);
25372549
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
@@ -2718,6 +2730,10 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
27182730
}
27192731
}
27202732

2733+
let mut implementors = implementors.clone();
2734+
2735+
implementors.sort_by(compare_impl_polarity);
2736+
27212737
let (local, foreign) = implementors.iter().partition::<Vec<_>, _>(|i| {
27222738
i.inner_impl().for_.def_id().map_or(true, |d| cache.paths.contains_key(&d))
27232739
});

0 commit comments

Comments
 (0)