Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ fn add_generics_and_bounds_as_types<'tcx, 'a>(
}

// First, check if it's "Self".
let arg = if let Some(self_) = self_ {
let mut arg = if let Some(self_) = self_ {
match &*arg {
Type::BorrowedRef { type_, .. } if type_.is_self_type() => self_,
type_ if type_.is_self_type() => self_,
Expand All @@ -475,11 +475,16 @@ fn add_generics_and_bounds_as_types<'tcx, 'a>(
arg
};

// strip references from the argument type
while let Type::BorrowedRef { type_, .. } = &*arg {
arg = &*type_;
}

// If this argument is a type parameter and not a trait bound or a type, we need to look
// for its bounds.
if let Type::Generic(arg_s) = *arg {
// First we check if the bounds are in a `where` predicate...
if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g {
for where_pred in generics.where_predicates.iter().filter(|g| match g {
WherePredicate::BoundPredicate { ty: Type::Generic(ty_s), .. } => *ty_s == arg_s,
_ => false,
}) {
Expand Down
23 changes: 17 additions & 6 deletions tests/rustdoc-js-std/option-type-signatures.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
const QUERY = 'option, fnonce -> option';
const QUERY = [
'option, fnonce -> option',
'option -> default',
];

const EXPECTED = {
'others': [
{ 'path': 'std::option::Option', 'name': 'map' },
],
};
const EXPECTED = [
{
'others': [
{ 'path': 'std::option::Option', 'name': 'map' },
],
},
{
'others': [
{ 'path': 'std::option::Option', 'name': 'unwrap_or_default' },
{ 'path': 'std::option::Option', 'name': 'get_or_insert_default' },
],
},
];
13 changes: 12 additions & 1 deletion tests/rustdoc-js/where-clause.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const QUERY = ['trait<nested>', '-> trait<nested>', 't1, t2'];
const QUERY = ['trait<nested>', '-> trait<nested>', 't1, t2', '-> shazam', 'drizzel -> shazam'];

const EXPECTED = [
{
Expand All @@ -16,4 +16,15 @@ const EXPECTED = [
{ 'path': 'where_clause', 'name': 'presto' },
],
},
{
'others': [
{ 'path': 'where_clause', 'name': 'bippety' },
{ 'path': 'where_clause::Drizzel', 'name': 'boppety' },
],
},
{
'others': [
{ 'path': 'where_clause::Drizzel', 'name': 'boppety' },
],
},
];
14 changes: 14 additions & 0 deletions tests/rustdoc-js/where-clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ pub trait T2<'a, T> {
}

pub fn presto<A, B>(_: A, _: B) where A: T1, B: for <'b> T2<'b, Nested> {}

pub trait Shazam {}

pub fn bippety<X>() -> &'static X where X: Shazam {
panic!()
}

pub struct Drizzel<T>(T);

impl<T> Drizzel<T> {
pub fn boppety(&self) -> &T where T: Shazam {
panic!();
}
}