diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs
index 0991778f87d79..4c93e632ab467 100644
--- a/src/librustdoc/html/render/search_index.rs
+++ b/src/librustdoc/html/render/search_index.rs
@@ -315,6 +315,29 @@ impl SerializedSearchIndex {
let other_entryid_offset = self.names.len();
let mut map_other_pathid_to_self_pathid = Vec::new();
let mut skips = FxHashSet::default();
+
+ fn remap_entry_data(
+ other_entry_data: &EntryData,
+ map_other_pathid_to_self_pathid: &[usize],
+ ) -> EntryData {
+ EntryData {
+ parent: other_entry_data
+ .parent
+ .map(|parent| map_other_pathid_to_self_pathid[parent])
+ .clone(),
+ module_path: other_entry_data
+ .module_path
+ .map(|path| map_other_pathid_to_self_pathid[path])
+ .clone(),
+ exact_module_path: other_entry_data
+ .exact_module_path
+ .map(|exact_path| map_other_pathid_to_self_pathid[exact_path])
+ .clone(),
+ krate: map_other_pathid_to_self_pathid[other_entry_data.krate],
+ ..other_entry_data.clone()
+ }
+ }
+
for (other_pathid, other_path_data) in other.path_data.iter().enumerate() {
if let Some(other_path_data) = other_path_data {
let name = Symbol::intern(&other.names[other_pathid]);
@@ -439,87 +462,72 @@ impl SerializedSearchIndex {
}
}
for other_entryid in 0..other.names.len() {
- if skips.contains(&other_entryid) {
- // we push tombstone entries to keep the IDs lined up
- self.push(String::new(), None, None, String::new(), None, None, None);
- } else {
- self.push(
- other.names[other_entryid].clone(),
- other.path_data[other_entryid].clone(),
- other.entry_data[other_entryid].as_ref().map(|other_entry_data| EntryData {
- parent: other_entry_data
- .parent
- .map(|parent| map_other_pathid_to_self_pathid[parent])
- .clone(),
- module_path: other_entry_data
- .module_path
- .map(|path| map_other_pathid_to_self_pathid[path])
- .clone(),
- exact_module_path: other_entry_data
- .exact_module_path
- .map(|exact_path| map_other_pathid_to_self_pathid[exact_path])
- .clone(),
- krate: map_other_pathid_to_self_pathid[other_entry_data.krate],
- ..other_entry_data.clone()
- }),
- other.descs[other_entryid].clone(),
- other.function_data[other_entryid].clone().map(|mut func| {
- fn map_fn_sig_item(
- map_other_pathid_to_self_pathid: &Vec,
- ty: &mut RenderType,
- ) {
- match ty.id {
- None => {}
- Some(RenderTypeId::Index(generic)) if generic < 0 => {}
- Some(RenderTypeId::Index(id)) => {
- let id = usize::try_from(id).unwrap();
- let id = map_other_pathid_to_self_pathid[id];
- assert!(id != !0);
- ty.id = Some(RenderTypeId::Index(isize::try_from(id).unwrap()));
- }
- _ => unreachable!(),
+ self.push(
+ other.names[other_entryid].clone(),
+ if skips.contains(&other_entryid) {
+ None
+ } else {
+ other.path_data[other_entryid].clone()
+ },
+ other.entry_data[other_entryid].as_ref().map(|other_entry_data| {
+ remap_entry_data(other_entry_data, &map_other_pathid_to_self_pathid)
+ }),
+ other.descs[other_entryid].clone(),
+ other.function_data[other_entryid].clone().map(|mut func| {
+ fn map_fn_sig_item(
+ map_other_pathid_to_self_pathid: &Vec,
+ ty: &mut RenderType,
+ ) {
+ match ty.id {
+ None => {}
+ Some(RenderTypeId::Index(generic)) if generic < 0 => {}
+ Some(RenderTypeId::Index(id)) => {
+ let id = usize::try_from(id).unwrap();
+ let id = map_other_pathid_to_self_pathid[id];
+ assert!(id != !0);
+ ty.id = Some(RenderTypeId::Index(isize::try_from(id).unwrap()));
}
- if let Some(generics) = &mut ty.generics {
- for generic in generics {
- map_fn_sig_item(map_other_pathid_to_self_pathid, generic);
- }
+ _ => unreachable!(),
+ }
+ if let Some(generics) = &mut ty.generics {
+ for generic in generics {
+ map_fn_sig_item(map_other_pathid_to_self_pathid, generic);
}
- if let Some(bindings) = &mut ty.bindings {
- for (param, constraints) in bindings {
- *param = match *param {
- param @ RenderTypeId::Index(generic) if generic < 0 => {
- param
- }
- RenderTypeId::Index(id) => {
- let id = usize::try_from(id).unwrap();
- let id = map_other_pathid_to_self_pathid[id];
- assert!(id != !0);
- RenderTypeId::Index(isize::try_from(id).unwrap())
- }
- _ => unreachable!(),
- };
- for constraint in constraints {
- map_fn_sig_item(
- map_other_pathid_to_self_pathid,
- constraint,
- );
+ }
+ if let Some(bindings) = &mut ty.bindings {
+ for (param, constraints) in bindings {
+ *param = match *param {
+ param @ RenderTypeId::Index(generic) if generic < 0 => param,
+ RenderTypeId::Index(id) => {
+ let id = usize::try_from(id).unwrap();
+ let id = map_other_pathid_to_self_pathid[id];
+ assert!(id != !0);
+ RenderTypeId::Index(isize::try_from(id).unwrap())
}
+ _ => unreachable!(),
+ };
+ for constraint in constraints {
+ map_fn_sig_item(map_other_pathid_to_self_pathid, constraint);
}
}
}
- for input in &mut func.inputs {
- map_fn_sig_item(&map_other_pathid_to_self_pathid, input);
- }
- for output in &mut func.output {
- map_fn_sig_item(&map_other_pathid_to_self_pathid, output);
- }
- for clause in &mut func.where_clause {
- for entry in clause {
- map_fn_sig_item(&map_other_pathid_to_self_pathid, entry);
- }
+ }
+ for input in &mut func.inputs {
+ map_fn_sig_item(&map_other_pathid_to_self_pathid, input);
+ }
+ for output in &mut func.output {
+ map_fn_sig_item(&map_other_pathid_to_self_pathid, output);
+ }
+ for clause in &mut func.where_clause {
+ for entry in clause {
+ map_fn_sig_item(&map_other_pathid_to_self_pathid, entry);
}
- func
- }),
+ }
+ func
+ }),
+ if skips.contains(&other_entryid) {
+ None
+ } else {
other.type_data[other_entryid].as_ref().map(|type_data| TypeData {
inverted_function_inputs_index: type_data
.inverted_function_inputs_index
@@ -556,11 +564,11 @@ impl SerializedSearchIndex {
})
.collect(),
search_unbox: type_data.search_unbox,
- }),
- other.alias_pointers[other_entryid]
- .map(|alias_pointer| alias_pointer + other_entryid_offset),
- );
- }
+ })
+ },
+ other.alias_pointers[other_entryid]
+ .map(|alias_pointer| alias_pointer + other_entryid_offset),
+ );
}
if other.generic_inverted_index.len() > self.generic_inverted_index.len() {
self.generic_inverted_index.resize(other.generic_inverted_index.len(), Vec::new());
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index b3c2563aa3f97..ab72edacae296 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -375,15 +375,20 @@ impl CrateInfo {
.fold(Ok(Vec::new()), |acc, parts_path| {
let mut acc = acc?;
let dir = &parts_path.0;
- acc.append(&mut try_err!(std::fs::read_dir(dir), dir.as_path())
+ let mut files: Vec> = try_err!(std::fs::read_dir(dir), dir.as_path())
+ .map(|file| Ok(file?.path()))
+ .collect();
+ files.sort_by_key(|p| p.as_ref().map_or(PathBuf::new(), |p| p.clone()));
+ acc.append(&mut files
+ .into_iter()
.filter_map(|file| {
- let to_crate_info = |file: Result| -> Result