Skip to content

Commit

Permalink
Sort negative impls before positive ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsha committed May 24, 2021
1 parent 9f69e2f commit 75a82bb
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,18 +664,18 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
}
}

let (local, foreign) = implementors.iter().partition::<Vec<_>, _>(|i| {
let (mut local, mut foreign) = implementors.iter().partition::<Vec<_>, _>(|i| {
i.inner_impl()
.for_
.def_id_full(cx.cache())
.map_or(true, |d| cx.cache.paths.contains_key(&d))
});

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

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

if !foreign.is_empty() {
write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "");
Expand Down Expand Up @@ -1284,10 +1284,16 @@ fn render_stability_since(
)
}

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

if lhs.inner_impl().negative_polarity && !rhs.inner_impl().negative_polarity {
return Ordering::Less;
} else if rhs.inner_impl().negative_polarity && !lhs.inner_impl().negative_polarity {
return Ordering::Greater;
}

// lhs and rhs are formatted as HTML, which may be unnecessary
compare_names(&lhss, &rhss)
}
Expand Down

0 comments on commit 75a82bb

Please sign in to comment.