Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5d43995

Browse files
committed
rustdoc: skip MetaSized bounds
These should never be shown to users at the moment.
1 parent ca8e54f commit 5d43995

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,28 @@ pub(crate) fn build_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait {
267267
let predicates = cx.tcx.predicates_of(did);
268268
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
269269
let generics = filter_non_trait_generics(did, generics);
270-
let (generics, supertrait_bounds) = separate_self_bounds(generics);
270+
let (generics, mut supertrait_bounds) = separate_self_bounds(generics);
271+
272+
supertrait_bounds.retain(|b| {
273+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
274+
// is shown and none of the new sizedness traits leak into documentation.
275+
!b.is_meta_sized_bound(cx)
276+
});
277+
271278
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
272279
}
273280

274281
fn build_trait_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::TraitAlias {
275282
let predicates = cx.tcx.predicates_of(did);
276283
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
277-
let (generics, bounds) = separate_self_bounds(generics);
284+
let (generics, mut bounds) = separate_self_bounds(generics);
285+
286+
bounds.retain(|b| {
287+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
288+
// is shown and none of the new sizedness traits leak into documentation.
289+
!b.is_meta_sized_bound(cx)
290+
});
291+
278292
clean::TraitAlias { generics, bounds }
279293
}
280294

src/librustdoc/clean/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ use rustc_ast::tokenstream::{TokenStream, TokenTree};
3939
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet, IndexEntry};
4040
use rustc_errors::codes::*;
4141
use rustc_errors::{FatalError, struct_span_code_err};
42-
use rustc_hir::PredicateOrigin;
4342
use rustc_hir::def::{CtorKind, DefKind, Res};
4443
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LOCAL_CRATE, LocalDefId};
44+
use rustc_hir::{LangItem, PredicateOrigin};
4545
use rustc_hir_analysis::hir_ty_lowering::FeedConstTy;
4646
use rustc_hir_analysis::{lower_const_arg_for_rustdoc, lower_ty};
4747
use rustc_middle::metadata::Reexport;
@@ -906,6 +906,10 @@ fn clean_ty_generics<'tcx>(
906906
if b.is_sized_bound(cx) {
907907
has_sized = true;
908908
false
909+
} else if b.is_meta_sized_bound(cx) {
910+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
911+
// is shown and none of the new sizedness traits leak into documentation.
912+
false
909913
} else {
910914
true
911915
}
@@ -1472,6 +1476,13 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14721476
}
14731477
_ => true,
14741478
});
1479+
1480+
bounds.retain(|b| {
1481+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
1482+
// is shown and none of the new sizedness traits leak into documentation.
1483+
!b.is_meta_sized_bound(cx)
1484+
});
1485+
14751486
// Our Sized/?Sized bound didn't get handled when creating the generics
14761487
// because we didn't actually get our whole set of bounds until just now
14771488
// (some of them may have come from the trait). If we do have a sized
@@ -2303,6 +2314,12 @@ fn clean_middle_opaque_bounds<'tcx>(
23032314
_ => return None,
23042315
};
23052316

2317+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
2318+
// is shown and none of the new sizedness traits leak into documentation.
2319+
if cx.tcx.is_lang_item(trait_ref.def_id(), LangItem::MetaSized) {
2320+
return None;
2321+
}
2322+
23062323
if let Some(sized) = cx.tcx.lang_items().sized_trait()
23072324
&& trait_ref.def_id() == sized
23082325
{

src/librustdoc/clean/simplify.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,17 @@ pub(crate) fn sized_bounds(cx: &mut DocContext<'_>, generics: &mut clean::Generi
138138
// don't actually know the set of associated types right here so that
139139
// should be handled when cleaning associated types.
140140
generics.where_predicates.retain(|pred| {
141-
if let WP::BoundPredicate { ty: clean::Generic(param), bounds, .. } = pred
142-
&& bounds.iter().any(|b| b.is_sized_bound(cx))
143-
{
141+
let WP::BoundPredicate { ty: clean::Generic(param), bounds, .. } = pred else {
142+
return true;
143+
};
144+
145+
if bounds.iter().any(|b| b.is_sized_bound(cx)) {
144146
sized_params.insert(*param);
145147
false
148+
} else if bounds.iter().any(|b| b.is_meta_sized_bound(cx)) {
149+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
150+
// is shown and none of the new sizedness traits leak into documentation.
151+
false
146152
} else {
147153
true
148154
}

src/librustdoc/clean/types.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,11 +1276,19 @@ impl GenericBound {
12761276
}
12771277

12781278
pub(crate) fn is_sized_bound(&self, cx: &DocContext<'_>) -> bool {
1279+
self.is_bounded_by_lang_item(cx, LangItem::Sized)
1280+
}
1281+
1282+
pub(crate) fn is_meta_sized_bound(&self, cx: &DocContext<'_>) -> bool {
1283+
self.is_bounded_by_lang_item(cx, LangItem::MetaSized)
1284+
}
1285+
1286+
fn is_bounded_by_lang_item(&self, cx: &DocContext<'_>, lang_item: LangItem) -> bool {
12791287
if let GenericBound::TraitBound(
12801288
PolyTrait { ref trait_, .. },
12811289
rustc_hir::TraitBoundModifiers::NONE,
12821290
) = *self
1283-
&& Some(trait_.def_id()) == cx.tcx.lang_items().sized_trait()
1291+
&& cx.tcx.is_lang_item(trait_.def_id(), lang_item)
12841292
{
12851293
return true;
12861294
}

0 commit comments

Comments
 (0)