]> git.lizzy.rs Git - rust.git/commitdiff
Move doc alias discovery into the Attributes struct and some code improvements
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Mon, 4 May 2020 13:26:17 +0000 (15:26 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 14 May 2020 09:35:44 +0000 (11:35 +0200)
src/librustdoc/clean/types.rs
src/librustdoc/html/render.rs
src/librustdoc/html/render/cache.rs
src/librustdoc/html/static/main.js

index 0a682857b18259fee5ff7398681b35c1c4100fff..cd767802714b03ab4bdab3722ae41590b033b651 100644 (file)
@@ -643,6 +643,15 @@ pub fn links(&self, krate: &CrateNum) -> Vec<(String, String)> {
             })
             .collect()
     }
+
+    pub fn get_doc_aliases(&self) -> FxHashSet<String> {
+        self.other_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<_>>()
+    }
 }
 
 impl PartialEq for Attributes {
index 9454baf7640979975b09e5a971c12ef4dd260c01..abca8ab778cc350e44e1815b4167612e67a079b7 100644 (file)
@@ -278,7 +278,7 @@ pub struct RenderInfo {
 /// Struct representing one entry in the JS search index. These are all emitted
 /// by hand to a large JS file at the end of cache-creation.
 #[derive(Debug)]
-pub struct IndexItem {
+struct IndexItem {
     ty: ItemType,
     name: String,
     path: String,
index 53cf1abb16d5639082188fba7e09fd52e31b086c..b8d97c2ac503bae863fbd436954e09b2a8455f61 100644 (file)
@@ -328,15 +328,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
                             search_type: get_index_search_type(&item),
                         });
 
-                        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()
-                        {
+                        for alias in item.attrs.get_doc_aliases() {
                             self.aliases
                                 .entry(alias.to_lowercase())
                                 .or_insert(Vec::with_capacity(1))
@@ -378,9 +370,6 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
             | clean::MacroItem(..)
             | clean::ProcMacroItem(..)
             | clean::VariantItem(..)
-            | clean::StructFieldItem(..)
-            | clean::TyMethodItem(..)
-            | clean::MethodItem(..)
                 if !self.stripped_mod =>
             {
                 // Re-exported items mean that the same id can show up twice
@@ -564,15 +553,7 @@ 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
-                .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()
-            {
+            for alias in item.attrs.get_doc_aliases().into_iter() {
                 aliases
                     .entry(alias.to_lowercase())
                     .or_insert(Vec::with_capacity(1))
@@ -619,22 +600,8 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
         .map(|module| shorten(plain_summary_line(module.doc_value())))
         .unwrap_or(String::new());
 
-    let crate_aliases = aliases
-        .iter()
-        .map(|(k, values)| {
-            (
-                k.clone(),
-                values
-                    .iter()
-                    .filter_map(|v| {
-                        let x = &crate_items[*v];
-                        if x.parent_idx.is_some() == x.parent.is_some() { Some(*v) } else { None }
-                    })
-                    .collect::<Vec<_>>(),
-            )
-        })
-        .filter(|(_, values)| !values.is_empty())
-        .collect::<Vec<_>>();
+    let crate_aliases =
+        aliases.iter().map(|(k, values)| (k.clone(), values.clone())).collect::<Vec<_>>();
 
     #[derive(Serialize)]
     struct CrateData<'a> {
index 94ae69fde57fd5ae9ca153b43c5621ea03432c0d..22e312e13c011e44690d839baa698a2186e1a662 100644 (file)
@@ -972,7 +972,7 @@ function getSearchElement() {
                     desc: item.desc,
                     ty: item.ty,
                     parent: item.parent,
-                    type: item.parent,
+                    type: item.type,
                     is_alias: true,
                 };
             }