Skip to content

Commit 90f7918

Browse files
committed
rustdoc: skip MetaSized bounds
These should never be shown to users at the moment.
1 parent 978100d commit 90f7918

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

src/librustdoc/clean/inline.rs

+8-1
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

+18-1
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;
@@ -892,6 +892,10 @@ fn clean_ty_generics<'tcx>(
892892
if b.is_sized_bound(cx) {
893893
has_sized = true;
894894
false
895+
} else if b.is_metasized_bound(cx) {
896+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
897+
// is shown and none of the new sizedness traits leak into documentation.
898+
false
895899
} else {
896900
true
897901
}
@@ -1486,6 +1490,13 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14861490
}
14871491
_ => true,
14881492
});
1493+
1494+
bounds.retain(|b| {
1495+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
1496+
// is shown and none of the new sizedness traits leak into documentation.
1497+
!b.is_metasized_bound(cx)
1498+
});
1499+
14891500
// Our Sized/?Sized bound didn't get handled when creating the generics
14901501
// because we didn't actually get our whole set of bounds until just now
14911502
// (some of them may have come from the trait). If we do have a sized
@@ -2321,6 +2332,12 @@ fn clean_middle_opaque_bounds<'tcx>(
23212332
_ => return None,
23222333
};
23232334

2335+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
2336+
// is shown and none of the new sizedness traits leak into documentation.
2337+
if cx.tcx.is_lang_item(trait_ref.def_id(), LangItem::MetaSized) {
2338+
return None;
2339+
}
2340+
23242341
if let Some(sized) = cx.tcx.lang_items().sized_trait()
23252342
&& trait_ref.def_id() == sized
23262343
{

src/librustdoc/clean/simplify.rs

+9-3
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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1273,11 +1273,19 @@ impl GenericBound {
12731273
}
12741274

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

0 commit comments

Comments
 (0)