Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
//! various types in `rustdoc::clean`.
//!
//! These implementations all emit HTML. As an internal implementation detail,
//! some of them support an alternate format that emits text, but that should
//! not be used external to this module.
//! some of them support an alternate format that emits plain text.

use std::cmp::Ordering;
use std::fmt::{self, Display, Write};
Expand Down Expand Up @@ -184,9 +183,9 @@ pub(crate) fn print_where_clause(

let clause = if f.alternate() {
if ending == Ending::Newline {
format!(" where{where_preds},")
format!(" where{where_preds:#},")
} else {
format!(" where{where_preds}")
format!(" where{where_preds:#}")
}
} else {
let mut br_with_padding = String::with_capacity(6 * indent + 28);
Expand Down
19 changes: 7 additions & 12 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2324,17 +2324,15 @@ where

#[derive(PartialEq, Eq)]
struct ImplString {
rendered: String,
is_negative: bool,
// Plain text (not HTML text) because this is only used for sorting purposes, and the plain
// text is much shorter and thus faster to compare.
cmp_text: String,
}

impl ImplString {
fn new(i: &Impl, cx: &Context<'_>) -> ImplString {
let impl_ = i.inner_impl();
ImplString {
is_negative: impl_.is_negative_trait_impl(),
rendered: format!("{}", print_impl(impl_, false, cx)),
}
ImplString { cmp_text: format!("{:#}", print_impl(impl_, false, cx)) }
}
}

Expand All @@ -2346,12 +2344,9 @@ impl PartialOrd for ImplString {

impl Ord for ImplString {
fn cmp(&self, other: &Self) -> Ordering {
// We sort negative impls first.
match (self.is_negative, other.is_negative) {
(false, true) => Ordering::Greater,
(true, false) => Ordering::Less,
_ => compare_names(&self.rendered, &other.rendered),
}
// Negative impls are naturally sorted first, because `impl !A` is less than `impl B` for
// any value of `B`, because `!` is less than any identifier-starting char.
compare_names(&self.cmp_text, &other.cmp_text)
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
//! or contains "invocation-specific".

use std::cell::RefCell;
use std::cmp::Ordering;
use std::ffi::{OsStr, OsString};
use std::fs::File;
use std::io::{self, Write as _};
Expand Down Expand Up @@ -730,8 +729,10 @@ impl TraitAliasPart {
None
} else {
let impl_ = imp.inner_impl();
let print = print_impl(impl_, false, cx);
Some(Implementor {
text: print_impl(impl_, false, cx).to_string(),
text: format!("{}", print),
cmp_text: format!("{:#}", print),
synthetic: imp.inner_impl().kind.is_auto(),
types: collect_paths_for_type(&imp.inner_impl().for_, cache),
is_negative: impl_.is_negative_trait_impl(),
Expand All @@ -754,14 +755,9 @@ impl TraitAliasPart {
path.push(format!("{remote_item_type}.{}.js", remote_path[remote_path.len() - 1]));

let mut implementors = implementors.collect::<Vec<_>>();
implementors.sort_unstable_by(|a, b| {
// We sort negative impls first.
match (a.is_negative, b.is_negative) {
(false, true) => Ordering::Greater,
(true, false) => Ordering::Less,
_ => compare_names(&a.text, &b.text),
}
});
// Negative impls are naturally sorted first, because `impl !A` is less than `impl B`
// for any value of `B`, because `!` is less than any identifier-starting char.
implementors.sort_unstable_by(|a, b| compare_names(&a.cmp_text, &b.cmp_text));

let part = OrderedJson::array_unsorted(
implementors
Expand All @@ -777,7 +773,11 @@ impl TraitAliasPart {
}

struct Implementor {
// HTML text used in generated output.
text: String,
// Plain text used just for sorting output. This is a performance win, because this plain text
// is much shorter than the HTML output and sorting is hot.
cmp_text: String,
synthetic: bool,
types: Vec<String>,
is_negative: bool,
Expand Down
Loading