Skip to content

rustdoc: Sort lines in search index and implementors js #38105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2016
Merged
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
50 changes: 26 additions & 24 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::default::Default;
use std::error;
use std::fmt::{self, Display, Formatter};
use std::fmt::{self, Display, Formatter, Write as FmtWrite};
use std::fs::{self, File, OpenOptions};
use std::io::prelude::*;
use std::io::{self, BufWriter, BufReader};
Expand Down Expand Up @@ -718,18 +718,20 @@ fn write_shared(cx: &Context,

// Update the search index
let dst = cx.dst.join("search-index.js");
let all_indexes = try_err!(collect(&dst, &krate.name, "searchIndex"), &dst);
let mut all_indexes = try_err!(collect(&dst, &krate.name, "searchIndex"), &dst);
all_indexes.push(search_index);
// Sort the indexes by crate so the file will be generated identically even
// with rustdoc running in parallel.
all_indexes.sort();
let mut w = try_err!(File::create(&dst), &dst);
try_err!(writeln!(&mut w, "var searchIndex = {{}};"), &dst);
try_err!(writeln!(&mut w, "{}", search_index), &dst);
for index in &all_indexes {
try_err!(writeln!(&mut w, "{}", *index), &dst);
}
try_err!(writeln!(&mut w, "initSearch(searchIndex);"), &dst);

// Update the list of all implementors for traits
let dst = cx.dst.join("implementors");
try_err!(mkdir(&dst), &dst);
for (&did, imps) in &cache.implementors {
// Private modules can leak through to this phase of rustdoc, which
// could contain implementations for otherwise private types. In some
Expand All @@ -746,37 +748,37 @@ fn write_shared(cx: &Context,
}
};

let mut implementors = format!(r#"implementors["{}"] = ["#, krate.name);
for imp in imps {
// If the trait and implementation are in the same crate, then
// there's no need to emit information about it (there's inlining
// going on). If they're in different crates then the crate defining
// the trait will be interested in our implementation.
if imp.def_id.krate == did.krate { continue }
write!(implementors, r#""{}","#, imp.impl_).unwrap();
}
implementors.push_str("];");

let mut mydst = dst.clone();
for part in &remote_path[..remote_path.len() - 1] {
mydst.push(part);
try_err!(mkdir(&mydst), &mydst);
}
try_err!(fs::create_dir_all(&mydst), &mydst);
mydst.push(&format!("{}.{}.js",
remote_item_type.css_class(),
remote_path[remote_path.len() - 1]));
let all_implementors = try_err!(collect(&mydst, &krate.name,
"implementors"),
&mydst);

try_err!(mkdir(mydst.parent().unwrap()),
&mydst.parent().unwrap().to_path_buf());
let mut f = BufWriter::new(try_err!(File::create(&mydst), &mydst));
try_err!(writeln!(&mut f, "(function() {{var implementors = {{}};"), &mydst);
let mut all_implementors = try_err!(collect(&mydst, &krate.name, "implementors"), &mydst);
all_implementors.push(implementors);
// Sort the implementors by crate so the file will be generated
// identically even with rustdoc running in parallel.
all_implementors.sort();

let mut f = try_err!(File::create(&mydst), &mydst);
try_err!(writeln!(&mut f, "(function() {{var implementors = {{}};"), &mydst);
for implementor in &all_implementors {
try_err!(write!(&mut f, "{}", *implementor), &mydst);
}

try_err!(write!(&mut f, r#"implementors["{}"] = ["#, krate.name), &mydst);
for imp in imps {
// If the trait and implementation are in the same crate, then
// there's no need to emit information about it (there's inlining
// going on). If they're in different crates then the crate defining
// the trait will be interested in our implementation.
if imp.def_id.krate == did.krate { continue }
try_err!(write!(&mut f, r#""{}","#, imp.impl_), &mydst);
try_err!(writeln!(&mut f, "{}", *implementor), &mydst);
}
try_err!(writeln!(&mut f, r"];"), &mydst);
try_err!(writeln!(&mut f, "{}", r"
if (window.register_implementors) {
window.register_implementors(implementors);
Expand Down