about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2022-01-17 14:50:48 +0100
committerGuillaume Gomez <guillaume.gomez@huawei.com>2022-01-17 14:50:48 +0100
commit0a95cefb62cc39b1e27ac8eecfe13369439330ca (patch)
tree88cdef35dd1ccd20c8cc6c7cc80c7ca49509636a
parent16679a616187b6f14b308aba5b1dcef8887b231f (diff)
downloadrust-0a95cefb62cc39b1e27ac8eecfe13369439330ca.tar.gz
rust-0a95cefb62cc39b1e27ac8eecfe13369439330ca.zip
Correctly handle pure generics
-rw-r--r--src/librustdoc/html/render/search_index.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs
index af14efe8aa0..0ee67467c38 100644
--- a/src/librustdoc/html/render/search_index.rs
+++ b/src/librustdoc/html/render/search_index.rs
@@ -3,7 +3,7 @@ use std::collections::BTreeMap;
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_middle::ty::TyCtxt;
-use rustc_span::symbol::Symbol;
+use rustc_span::symbol::{kw, Symbol};
 use serde::ser::{Serialize, SerializeStruct, Serializer};
 
 use crate::clean;
@@ -220,7 +220,8 @@ fn get_index_type_name(clean_type: &clean::Type) -> Option<Symbol> {
             let path = &bounds[0].trait_;
             Some(path.segments.last().unwrap().name)
         }
-        clean::Generic(s) => Some(s),
+        // We return an empty name because we don't care about the generic name itself.
+        clean::Generic(_) => Some(kw::Empty),
         clean::Primitive(ref p) => Some(p.as_sym()),
         clean::BorrowedRef { ref type_, .. } => get_index_type_name(type_),
         clean::BareFunction(_)
@@ -258,9 +259,10 @@ fn add_generics_and_bounds_as_types<'tcx>(
         cache: &Cache,
     ) {
         let is_full_generic = ty.is_full_generic();
+        let generics_empty = generics.is_empty();
 
         if is_full_generic {
-            if generics.is_empty() {
+            if generics_empty {
                 // This is a type parameter with no trait bounds (for example: `T` in
                 // `fn f<T>(p: T)`, so not useful for the rustdoc search because we would end up
                 // with an empty type with an empty name. Let's just discard it.
@@ -307,7 +309,7 @@ fn add_generics_and_bounds_as_types<'tcx>(
             }
         }
         let mut index_ty = get_index_type(&ty, generics);
-        if index_ty.name.as_ref().map(|s| s.is_empty()).unwrap_or(true) {
+        if index_ty.name.as_ref().map(|s| s.is_empty() && generics_empty).unwrap_or(true) {
             return;
         }
         if is_full_generic {