Skip to content

Commit 67a91fc

Browse files
GuillaumeGomezjdonszelmann
authored andcommitted
Fix where predicates "cleaning" in rustdoc
1 parent 1ce3041 commit 67a91fc

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

‎src/librustdoc/clean/auto_trait.rs‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_trait_selection::traits::auto_trait::{self, RegionTarget};
1010
use tracing::{debug, instrument};
1111

1212
use crate::clean::{
13-
self, Lifetime, clean_clause_uninterned, clean_generic_param_def, clean_middle_ty,
13+
self, Lifetime, clean_clause, clean_generic_param_def, clean_middle_ty,
1414
clean_trait_ref_with_constraints, clean_ty_generics_inner, simplify,
1515
};
1616
use crate::core::DocContext;
@@ -174,16 +174,20 @@ fn clean_param_env<'tcx>(
174174

175175
// FIXME(#111101): Incorporate the explicit predicates of the item here...
176176
let item_clauses: FxIndexSet<_> =
177-
tcx.param_env(item_def_id).caller_bounds().trait_clauses(tcx).iter().collect();
177+
tcx.param_env(item_def_id).caller_bounds().all_clauses(tcx).iter().collect();
178178
let sized_trait = tcx.lang_items().sized_trait();
179179
let where_predicates = cx.with_exact_param_env(param_env, |cx| {
180180
param_env
181181
.caller_bounds()
182-
.trait_clauses(tcx)
182+
.all_clauses(tcx)
183183
.iter()
184184
// FIXME: ...which hopefully allows us to simplify this:
185-
.filter(|trait_clause| {
186-
!item_clauses.contains(trait_clause) || Some(trait_clause.def_id()) == sized_trait
185+
.filter(|clause| {
186+
!item_clauses.contains(clause)
187+
|| matches!(
188+
clause.skip_binder(),
189+
ty::ClauseKind::Trait(pred) if Some(pred.def_id()) == sized_trait
190+
)
187191
})
188192
.map(|clause| {
189193
fold_regions(tcx, clause, |r, _| match r.kind() {
@@ -200,7 +204,7 @@ fn clean_param_env<'tcx>(
200204
}
201205
})
202206
})
203-
.flat_map(|clause| clean_clause_uninterned(clause.map_bound(ty::ClauseKind::Trait), cx))
207+
.flat_map(|clause| clean_clause(clause, cx))
204208
.chain(clean_region_outlives_constraints(&region_data, generics))
205209
.collect()
206210
});

‎src/librustdoc/clean/mod.rs‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,6 @@ fn clean_where_predicate<'tcx>(
445445
}
446446

447447
pub(crate) fn clean_clause<'tcx>(
448-
clause: ty::Clause<'tcx>,
449-
cx: &mut DocContext<'tcx>,
450-
) -> Option<WherePredicate> {
451-
clean_clause_uninterned(clause.kind(), cx)
452-
}
453-
454-
pub(crate) fn clean_clause_uninterned<'tcx>(
455448
bound_clause: ty::Binder<'tcx, ty::ClauseKind<'tcx>>,
456449
cx: &mut DocContext<'tcx>,
457450
) -> Option<WherePredicate> {
@@ -952,7 +945,7 @@ fn clean_ty_generics_inner<'tcx>(
952945
if let Some(param_idx) = param_idx
953946
&& let Some(bounds) = impl_trait.get_mut(&param_idx)
954947
{
955-
let clause = clean_clause(*clause, cx)?;
948+
let clause = clean_clause(clause.kind(), cx)?;
956949

957950
bounds.extend(clause.get_bounds().into_iter().flatten().cloned());
958951

@@ -1011,7 +1004,8 @@ fn clean_ty_generics_inner<'tcx>(
10111004

10121005
// Now that `cx.impl_trait_bounds` is populated, we can process
10131006
// remaining predicates which could contain `impl Trait`.
1014-
let where_predicates = where_clauses.into_iter().flat_map(|c| clean_clause(*c, cx)).collect();
1007+
let where_predicates =
1008+
where_clauses.into_iter().flat_map(|c| clean_clause(c.kind(), cx)).collect();
10151009

10161010
let mut generics = Generics { params, where_predicates };
10171011
simplify::sizedness_bounds(cx, &mut generics);

‎tests/rustdoc-html/synthetic_auto/complex.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ mod foo {
2121

2222
//@ has complex/struct.NotOuter.html
2323
//@ has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//h3[@class="code-header"]' \
24-
// "impl<'a, T, K> Send for Outer<'a, T, K>where 'a: 'static, T: MyTrait<'a>, \
25-
// K: for<'b> Fn((&'b bool, &'a u8)) -> &'b i8 + ?Sized, <T as MyTrait<'a>>::MyItem: Copy,"
24+
// "impl<'a, T, K> Send for Outer<'a, T, K>where 'a: 'static, <T as MyTrait<'a>>::MyItem: Copy, \
25+
// T: MyTrait<'a>, K: for<'b> Fn((&'b bool, &'a u8)) -> &'b i8 + ?Sized,"
2626

2727
pub use foo::{Foo, Inner as NotInner, MyTrait as NotMyTrait, Outer as NotOuter};
2828

0 commit comments

Comments
 (0)