Skip to content

Commit 75a82bb

Browse files
committed
Sort negative impls before positive ones.
1 parent 9f69e2f commit 75a82bb

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,18 +664,18 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
664664
}
665665
}
666666

667-
let (local, foreign) = implementors.iter().partition::<Vec<_>, _>(|i| {
667+
let (mut local, mut foreign) = implementors.iter().partition::<Vec<_>, _>(|i| {
668668
i.inner_impl()
669669
.for_
670670
.def_id_full(cx.cache())
671671
.map_or(true, |d| cx.cache.paths.contains_key(&d))
672672
});
673673

674-
let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) =
675-
local.iter().partition(|i| i.inner_impl().synthetic);
674+
local.sort_by(|a, b| compare_impl(a, b, cx));
675+
foreign.sort_by(|a, b| compare_impl(a, b, cx));
676676

677-
synthetic.sort_by(|a, b| compare_impl(a, b, cx));
678-
concrete.sort_by(|a, b| compare_impl(a, b, cx));
677+
let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) =
678+
local.iter().partition(|i| i.inner_impl().synthetic);
679679

680680
if !foreign.is_empty() {
681681
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");
@@ -1284,10 +1284,16 @@ fn render_stability_since(
12841284
)
12851285
}
12861286

1287-
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering {
1287+
fn compare_impl<'a, 'b>(lhs: &'a &Impl, rhs: &'b &Impl, cx: &Context<'_>) -> Ordering {
12881288
let lhss = format!("{}", lhs.inner_impl().print(false, cx));
12891289
let rhss = format!("{}", rhs.inner_impl().print(false, cx));
12901290

1291+
if lhs.inner_impl().negative_polarity && !rhs.inner_impl().negative_polarity {
1292+
return Ordering::Less;
1293+
} else if rhs.inner_impl().negative_polarity && !lhs.inner_impl().negative_polarity {
1294+
return Ordering::Greater;
1295+
}
1296+
12911297
// lhs and rhs are formatted as HTML, which may be unnecessary
12921298
compare_names(&lhss, &rhss)
12931299
}

0 commit comments

Comments
 (0)