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

Commit 7f15407

Browse files
committed
rustdoc: skip MetaSized bounds
These should never be shown to users at the moment.
1 parent 3921235 commit 7f15407

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,14 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
273273
let predicates = cx.tcx.predicates_of(did);
274274
let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates);
275275
let generics = filter_non_trait_generics(did, generics);
276-
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
276+
let (generics, mut supertrait_bounds) = separate_supertrait_bounds(generics);
277+
278+
supertrait_bounds.retain(|b| {
279+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
280+
// is shown and none of the new sizedness traits leak into documentation.
281+
!b.is_meta_sized_bound(cx)
282+
});
283+
277284
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
278285
}
279286

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;
@@ -900,6 +900,10 @@ fn clean_ty_generics<'tcx>(
900900
if b.is_sized_bound(cx) {
901901
has_sized = true;
902902
false
903+
} else if b.is_meta_sized_bound(cx) {
904+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
905+
// is shown and none of the new sizedness traits leak into documentation.
906+
false
903907
} else {
904908
true
905909
}
@@ -1497,6 +1501,13 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14971501
}
14981502
_ => true,
14991503
});
1504+
1505+
bounds.retain(|b| {
1506+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
1507+
// is shown and none of the new sizedness traits leak into documentation.
1508+
!b.is_meta_sized_bound(cx)
1509+
});
1510+
15001511
// Our Sized/?Sized bound didn't get handled when creating the generics
15011512
// because we didn't actually get our whole set of bounds until just now
15021513
// (some of them may have come from the trait). If we do have a sized
@@ -2331,6 +2342,12 @@ fn clean_middle_opaque_bounds<'tcx>(
23312342
_ => return None,
23322343
};
23332344

2345+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
2346+
// is shown and none of the new sizedness traits leak into documentation.
2347+
if cx.tcx.is_lang_item(trait_ref.def_id(), LangItem::MetaSized) {
2348+
return None;
2349+
}
2350+
23342351
if let Some(sized) = cx.tcx.lang_items().sized_trait()
23352352
&& trait_ref.def_id() == sized
23362353
{

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
@@ -1274,11 +1274,19 @@ impl GenericBound {
12741274
}
12751275

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

0 commit comments

Comments
 (0)