Skip to content

Commit

Permalink
rustdoc: fix type search when more than one where clause applies
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Mar 7, 2023
1 parent a6446c5 commit 44813e0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ fn add_generics_and_bounds_as_types<'tcx, 'a>(
// 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' },
],
},
];
8 changes: 7 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', '-> shazam'];
const QUERY = ['trait<nested>', '-> trait<nested>', 't1, t2', '-> shazam', 'drizzel -> shazam'];

const EXPECTED = [
{
Expand All @@ -19,6 +19,12 @@ const EXPECTED = [
{
'others': [
{ 'path': 'where_clause', 'name': 'bippety' },
{ 'path': 'where_clause::Drizzel', 'name': 'boppety' },
],
},
{
'others': [
{ 'path': 'where_clause::Drizzel', 'name': 'boppety' },
],
},
];
8 changes: 8 additions & 0 deletions tests/rustdoc-js/where-clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ 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!();
}
}

0 comments on commit 44813e0

Please sign in to comment.