rustdoc-search: add slices and arrays to index
This indexes them as primitives with generics, so `slice<u32>` is how you search for `[u32]`, and `array<u32>` for `[u32; 1]`. A future commit will desugar the square bracket syntax to search both arrays and slices at once.
This commit is contained in:
parent
b72460fe46
commit
c4e00f7bd5
3 changed files with 109 additions and 2 deletions
|
@ -391,12 +391,14 @@ fn get_index_type_id(clean_type: &clean::Type) -> Option<RenderTypeId> {
|
||||||
clean::BorrowedRef { ref type_, .. } | clean::RawPointer(_, ref type_) => {
|
clean::BorrowedRef { ref type_, .. } | clean::RawPointer(_, ref type_) => {
|
||||||
get_index_type_id(type_)
|
get_index_type_id(type_)
|
||||||
}
|
}
|
||||||
|
// The type parameters are converted to generics in `add_generics_and_bounds_as_types`
|
||||||
|
clean::Slice(_) => Some(RenderTypeId::Primitive(clean::PrimitiveType::Slice)),
|
||||||
|
clean::Array(_, _) => Some(RenderTypeId::Primitive(clean::PrimitiveType::Array)),
|
||||||
|
// Not supported yet
|
||||||
clean::BareFunction(_)
|
clean::BareFunction(_)
|
||||||
| clean::Generic(_)
|
| clean::Generic(_)
|
||||||
| clean::ImplTrait(_)
|
| clean::ImplTrait(_)
|
||||||
| clean::Tuple(_)
|
| clean::Tuple(_)
|
||||||
| clean::Slice(_)
|
|
||||||
| clean::Array(_, _)
|
|
||||||
| clean::QPath { .. }
|
| clean::QPath { .. }
|
||||||
| clean::Infer => None,
|
| clean::Infer => None,
|
||||||
}
|
}
|
||||||
|
@ -563,6 +565,30 @@ fn add_generics_and_bounds_as_types<'tcx, 'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insert_ty(res, arg.clone(), ty_generics);
|
insert_ty(res, arg.clone(), ty_generics);
|
||||||
|
} else if let Type::Slice(ref ty) = *arg {
|
||||||
|
let mut ty_generics = Vec::new();
|
||||||
|
add_generics_and_bounds_as_types(
|
||||||
|
self_,
|
||||||
|
generics,
|
||||||
|
&ty,
|
||||||
|
tcx,
|
||||||
|
recurse + 1,
|
||||||
|
&mut ty_generics,
|
||||||
|
cache,
|
||||||
|
);
|
||||||
|
insert_ty(res, arg.clone(), ty_generics);
|
||||||
|
} else if let Type::Array(ref ty, _) = *arg {
|
||||||
|
let mut ty_generics = Vec::new();
|
||||||
|
add_generics_and_bounds_as_types(
|
||||||
|
self_,
|
||||||
|
generics,
|
||||||
|
&ty,
|
||||||
|
tcx,
|
||||||
|
recurse + 1,
|
||||||
|
&mut ty_generics,
|
||||||
|
cache,
|
||||||
|
);
|
||||||
|
insert_ty(res, arg.clone(), ty_generics);
|
||||||
} else {
|
} else {
|
||||||
// This is not a type parameter. So for example if we have `T, U: Option<T>`, and we're
|
// This is not a type parameter. So for example if we have `T, U: Option<T>`, and we're
|
||||||
// looking at `Option`, we enter this "else" condition, otherwise if it's `T`, we don't.
|
// looking at `Option`, we enter this "else" condition, otherwise if it's `T`, we don't.
|
||||||
|
|
65
tests/rustdoc-js/slice-array.js
Normal file
65
tests/rustdoc-js/slice-array.js
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// exact-check
|
||||||
|
|
||||||
|
const QUERY = [
|
||||||
|
'R<primitive:slice<P>>',
|
||||||
|
'primitive:slice<R<P>>',
|
||||||
|
'R<primitive:slice<Q>>',
|
||||||
|
'primitive:slice<R<Q>>',
|
||||||
|
'R<primitive:array<Q>>',
|
||||||
|
'primitive:array<R<Q>>',
|
||||||
|
'primitive:array<TraitCat>',
|
||||||
|
'primitive:array<TraitDog>',
|
||||||
|
];
|
||||||
|
|
||||||
|
const EXPECTED = [
|
||||||
|
{
|
||||||
|
// R<primitive:slice<P>>
|
||||||
|
'returned': [],
|
||||||
|
'in_args': [
|
||||||
|
{ 'path': 'slice_array', 'name': 'alpha' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// primitive:slice<R<P>>
|
||||||
|
'returned': [
|
||||||
|
{ 'path': 'slice_array', 'name': 'alef' },
|
||||||
|
],
|
||||||
|
'in_args': [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// R<primitive:slice<Q>>
|
||||||
|
'returned': [],
|
||||||
|
'in_args': [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// primitive:slice<R<Q>>
|
||||||
|
'returned': [],
|
||||||
|
'in_args': [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// R<primitive:array<Q>>
|
||||||
|
'returned': [
|
||||||
|
{ 'path': 'slice_array', 'name': 'bet' },
|
||||||
|
],
|
||||||
|
'in_args': [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// primitive:array<R<Q>>
|
||||||
|
'returned': [],
|
||||||
|
'in_args': [
|
||||||
|
{ 'path': 'slice_array', 'name': 'beta' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// primitive::array<TraitCat>
|
||||||
|
'in_args': [
|
||||||
|
{ 'path': 'slice_array', 'name': 'gamma' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// primitive::array<TraitDog>
|
||||||
|
'in_args': [
|
||||||
|
{ 'path': 'slice_array', 'name': 'gamma' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
16
tests/rustdoc-js/slice-array.rs
Normal file
16
tests/rustdoc-js/slice-array.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
pub struct P;
|
||||||
|
pub struct Q;
|
||||||
|
pub struct R<T>(T);
|
||||||
|
|
||||||
|
// returns test
|
||||||
|
pub fn alef() -> &'static [R<P>] { loop {} }
|
||||||
|
pub fn bet() -> R<[Q; 32]> { loop {} }
|
||||||
|
|
||||||
|
// in_args test
|
||||||
|
pub fn alpha(_x: R<&'static [P]>) { loop {} }
|
||||||
|
pub fn beta(_x: [R<Q>; 32]) { loop {} }
|
||||||
|
|
||||||
|
pub trait TraitCat {}
|
||||||
|
pub trait TraitDog {}
|
||||||
|
|
||||||
|
pub fn gamma<T: TraitCat + TraitDog>(t: [T; 32]) {}
|
Loading…
Add table
Add a link
Reference in a new issue