Skip to content

Commit 4e76b7e

Browse files
committed
rustdoc: skip MetaSized bounds
These should never be shown to users at the moment.
1 parent f9e8ad9 commit 4e76b7e

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_metasized_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;
@@ -888,6 +888,10 @@ fn clean_ty_generics<'tcx>(
888888
if b.is_sized_bound(cx) {
889889
has_sized = true;
890890
false
891+
} else if b.is_metasized_bound(cx) {
892+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
893+
// is shown and none of the new sizedness traits leak into documentation.
894+
false
891895
} else {
892896
true
893897
}
@@ -1482,6 +1486,13 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14821486
}
14831487
_ => true,
14841488
});
1489+
1490+
bounds.retain(|b| {
1491+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
1492+
// is shown and none of the new sizedness traits leak into documentation.
1493+
!b.is_metasized_bound(cx)
1494+
});
1495+
14851496
// Our Sized/?Sized bound didn't get handled when creating the generics
14861497
// because we didn't actually get our whole set of bounds until just now
14871498
// (some of them may have come from the trait). If we do have a sized
@@ -2317,6 +2328,12 @@ fn clean_middle_opaque_bounds<'tcx>(
23172328
_ => return None,
23182329
};
23192330

2331+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
2332+
// is shown and none of the new sizedness traits leak into documentation.
2333+
if cx.tcx.is_lang_item(trait_ref.def_id(), LangItem::MetaSized) {
2334+
return None;
2335+
}
2336+
23202337
if let Some(sized) = cx.tcx.lang_items().sized_trait()
23212338
&& trait_ref.def_id() == sized
23222339
{

src/librustdoc/clean/simplify.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,17 @@ pub(crate) fn sized_bounds(cx: &mut DocContext<'_>, generics: &mut clean::Generi
134134
// don't actually know the set of associated types right here so that
135135
// should be handled when cleaning associated types.
136136
generics.where_predicates.retain(|pred| {
137-
if let WP::BoundPredicate { ty: clean::Generic(param), bounds, .. } = pred
138-
&& bounds.iter().any(|b| b.is_sized_bound(cx))
139-
{
137+
let WP::BoundPredicate { ty: clean::Generic(param), bounds, .. } = pred else {
138+
return true;
139+
};
140+
141+
if bounds.iter().any(|b| b.is_sized_bound(cx)) {
140142
sized_params.insert(*param);
141143
false
144+
} else if bounds.iter().any(|b| b.is_metasized_bound(cx)) {
145+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
146+
// is shown and none of the new sizedness traits leak into documentation.
147+
false
142148
} else {
143149
true
144150
}

src/librustdoc/clean/types.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,11 +1271,19 @@ impl GenericBound {
12711271
}
12721272

12731273
pub(crate) fn is_sized_bound(&self, cx: &DocContext<'_>) -> bool {
1274+
self.is_bounded_by_lang_item(cx, LangItem::Sized)
1275+
}
1276+
1277+
pub(crate) fn is_metasized_bound(&self, cx: &DocContext<'_>) -> bool {
1278+
self.is_bounded_by_lang_item(cx, LangItem::MetaSized)
1279+
}
1280+
1281+
fn is_bounded_by_lang_item(&self, cx: &DocContext<'_>, lang_item: LangItem) -> bool {
12741282
if let GenericBound::TraitBound(
12751283
PolyTrait { ref trait_, .. },
12761284
rustc_hir::TraitBoundModifiers::NONE,
12771285
) = *self
1278-
&& Some(trait_.def_id()) == cx.tcx.lang_items().sized_trait()
1286+
&& cx.tcx.is_lang_item(trait_.def_id(), lang_item)
12791287
{
12801288
return true;
12811289
}

0 commit comments

Comments
 (0)