-
Couldn't load subscription status.
- Fork 13.9k
Doc alias improvements #71724
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
Doc alias improvements #71724
Changes from all commits
d80ac14
7590c39
cf41b1d
3a0727e
9697c46
f581cf7
883c177
c4d9318
e17ac66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,7 +120,7 @@ crate struct Cache { | |
|
|
||
| /// Aliases added through `#[doc(alias = "...")]`. Since a few items can have the same alias, | ||
| /// we need the alias element to have an array of items. | ||
| pub(super) aliases: FxHashMap<String, Vec<IndexItem>>, | ||
| pub(super) aliases: BTreeMap<String, Vec<usize>>, | ||
| } | ||
|
|
||
| impl Cache { | ||
|
|
@@ -311,7 +311,7 @@ impl DocFolder for Cache { | |
| }; | ||
|
|
||
| match parent { | ||
| (parent, Some(path)) if is_inherent_impl_item || (!self.stripped_mod) => { | ||
| (parent, Some(path)) if is_inherent_impl_item || !self.stripped_mod => { | ||
| debug_assert!(!item.is_stripped()); | ||
|
|
||
| // A crate has a module at its root, containing all items, | ||
|
|
@@ -327,6 +327,13 @@ impl DocFolder for Cache { | |
| parent_idx: None, | ||
| search_type: get_index_search_type(&item), | ||
| }); | ||
|
|
||
| for alias in item.attrs.get_doc_aliases() { | ||
| self.aliases | ||
| .entry(alias.to_lowercase()) | ||
|
||
| .or_insert(Vec::new()) | ||
| .push(self.search_index.len() - 1); | ||
| } | ||
| } | ||
| } | ||
| (Some(parent), None) if is_inherent_impl_item => { | ||
|
|
@@ -376,11 +383,8 @@ impl DocFolder for Cache { | |
| { | ||
| self.paths.insert(item.def_id, (self.stack.clone(), item.type_())); | ||
| } | ||
| self.add_aliases(&item); | ||
| } | ||
|
|
||
| clean::PrimitiveItem(..) => { | ||
| self.add_aliases(&item); | ||
| self.paths.insert(item.def_id, (self.stack.clone(), item.type_())); | ||
| } | ||
|
|
||
|
|
@@ -488,40 +492,6 @@ impl DocFolder for Cache { | |
| } | ||
| } | ||
|
|
||
| impl Cache { | ||
| fn add_aliases(&mut self, item: &clean::Item) { | ||
| if item.def_id.index == CRATE_DEF_INDEX { | ||
| return; | ||
| } | ||
| if let Some(ref item_name) = item.name { | ||
| let path = self | ||
| .paths | ||
| .get(&item.def_id) | ||
| .map(|p| p.0[..p.0.len() - 1].join("::")) | ||
| .unwrap_or("std".to_owned()); | ||
| for alias in item | ||
| .attrs | ||
| .lists(sym::doc) | ||
| .filter(|a| a.check_name(sym::alias)) | ||
| .filter_map(|a| a.value_str().map(|s| s.to_string().replace("\"", ""))) | ||
| .filter(|v| !v.is_empty()) | ||
| .collect::<FxHashSet<_>>() | ||
| .into_iter() | ||
| { | ||
| self.aliases.entry(alias).or_insert(Vec::with_capacity(1)).push(IndexItem { | ||
| ty: item.type_(), | ||
| name: item_name.to_string(), | ||
| path: path.clone(), | ||
| desc: shorten(plain_summary_line(item.doc_value())), | ||
| parent: None, | ||
| parent_idx: None, | ||
| search_type: get_index_search_type(&item), | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Attempts to find where an external crate is located, given that we're | ||
| /// rendering in to the specified source destination. | ||
| fn extern_location( | ||
|
|
@@ -567,7 +537,8 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { | |
| let mut crate_items = Vec::with_capacity(cache.search_index.len()); | ||
| let mut crate_paths = vec![]; | ||
|
|
||
| let Cache { ref mut search_index, ref orphan_impl_items, ref paths, .. } = *cache; | ||
| let Cache { ref mut search_index, ref orphan_impl_items, ref paths, ref mut aliases, .. } = | ||
| *cache; | ||
|
|
||
| // Attach all orphan items to the type's definition if the type | ||
| // has since been learned. | ||
|
|
@@ -582,6 +553,12 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { | |
| parent_idx: None, | ||
| search_type: get_index_search_type(&item), | ||
| }); | ||
| for alias in item.attrs.get_doc_aliases() { | ||
| aliases | ||
| .entry(alias.to_lowercase()) | ||
| .or_insert(Vec::new()) | ||
| .push(search_index.len() - 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -630,6 +607,12 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { | |
| items: Vec<&'a IndexItem>, | ||
| #[serde(rename = "p")] | ||
| paths: Vec<(ItemType, String)>, | ||
| // The String is alias name and the vec is the list of the elements with this alias. | ||
| // | ||
| // To be noted: the `usize` elements are indexes to `items`. | ||
| #[serde(rename = "a")] | ||
| #[serde(skip_serializing_if = "BTreeMap::is_empty")] | ||
| aliases: &'a BTreeMap<String, Vec<usize>>, | ||
| } | ||
|
|
||
| // Collect the index into a string | ||
|
|
@@ -640,6 +623,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String { | |
| doc: crate_doc, | ||
| items: crate_items, | ||
| paths: crate_paths, | ||
| aliases, | ||
| }) | ||
| .expect("failed serde conversion") | ||
| // All these `replace` calls are because we have to go through JS string for JSON content. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.