Skip to content

Commit 9cabc40

Browse files
authored
Rollup merge of rust-lang#108723 - notriddle:notriddle/where-clause, r=GuillaumeGomez
rustdoc: function signature search with traits in `where` clause ## Before ![image](https://user-images.githubusercontent.com/1593513/222873534-a640a72a-c654-4702-9f3b-175129d9591d.png) ## After ![image](https://user-images.githubusercontent.com/1593513/222873544-fdfc431d-2b65-4b56-bede-0302ea9f153a.png)
2 parents dd6f03d + 9d27028 commit 9cabc40

File tree

4 files changed

+55
-21
lines changed

4 files changed

+55
-21
lines changed

src/librustdoc/html/render/search_index.rs

+13-21
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use rustc_span::symbol::Symbol;
77
use serde::ser::{Serialize, SerializeStruct, Serializer};
88

99
use crate::clean;
10-
use crate::clean::types::{
11-
FnRetTy, Function, GenericBound, Generics, ItemId, Type, WherePredicate,
12-
};
10+
use crate::clean::types::{FnRetTy, Function, Generics, ItemId, Type, WherePredicate};
1311
use crate::formats::cache::{Cache, OrphanImplItem};
1412
use crate::formats::item_type::ItemType;
1513
use crate::html::format::join_with_double_colon;
@@ -482,29 +480,23 @@ fn add_generics_and_bounds_as_types<'tcx, 'a>(
482480
if let Type::Generic(arg_s) = *arg {
483481
// First we check if the bounds are in a `where` predicate...
484482
if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g {
485-
WherePredicate::BoundPredicate { ty, .. } => ty.def_id(cache) == arg.def_id(cache),
483+
WherePredicate::BoundPredicate { ty: Type::Generic(ty_s), .. } => *ty_s == arg_s,
486484
_ => false,
487485
}) {
488486
let mut ty_generics = Vec::new();
489487
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
490488
for bound in bounds.iter() {
491-
if let GenericBound::TraitBound(poly_trait, _) = bound {
492-
for param_def in poly_trait.generic_params.iter() {
493-
match &param_def.kind {
494-
clean::GenericParamDefKind::Type { default: Some(ty), .. } => {
495-
add_generics_and_bounds_as_types(
496-
self_,
497-
generics,
498-
ty,
499-
tcx,
500-
recurse + 1,
501-
&mut ty_generics,
502-
cache,
503-
)
504-
}
505-
_ => {}
506-
}
507-
}
489+
if let Some(path) = bound.get_trait_path() {
490+
let ty = Type::Path { path };
491+
add_generics_and_bounds_as_types(
492+
self_,
493+
generics,
494+
&ty,
495+
tcx,
496+
recurse + 1,
497+
&mut ty_generics,
498+
cache,
499+
);
508500
}
509501
}
510502
insert_ty(res, arg.clone(), ty_generics);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const QUERY = 'option, fnonce -> option';
2+
3+
const EXPECTED = {
4+
'others': [
5+
{ 'path': 'std::option::Option', 'name': 'map' },
6+
],
7+
};

tests/rustdoc-js/where-clause.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const QUERY = ['trait<nested>', '-> trait<nested>', 't1, t2'];
2+
3+
const EXPECTED = [
4+
{
5+
'in_args': [
6+
{ 'path': 'where_clause', 'name': 'abracadabra' },
7+
],
8+
},
9+
{
10+
'others': [
11+
{ 'path': 'where_clause', 'name': 'alacazam' },
12+
],
13+
},
14+
{
15+
'others': [
16+
{ 'path': 'where_clause', 'name': 'presto' },
17+
],
18+
},
19+
];

tests/rustdoc-js/where-clause.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub struct Nested;
2+
3+
pub trait Trait<T> {
4+
fn thank_you(x: T);
5+
}
6+
7+
pub fn abracadabra<X>(_: X) where X: Trait<Nested> {}
8+
9+
pub fn alacazam<X>() -> X where X: Trait<Nested> {}
10+
11+
pub trait T1 {}
12+
pub trait T2<'a, T> {
13+
fn please(_: &'a T);
14+
}
15+
16+
pub fn presto<A, B>(_: A, _: B) where A: T1, B: for <'b> T2<'b, Nested> {}

0 commit comments

Comments
 (0)