Skip to content

Commit 2e465db

Browse files
committed
rustdoc: skip MetaSized bounds
These should never be shown to users at the moment.
1 parent 8d031a9 commit 2e465db

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
@@ -265,13 +265,27 @@ pub(crate) fn build_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait {
265265
.collect();
266266

267267
let generics = clean_ty_generics(cx, did);
268-
let (generics, supertrait_bounds) = separate_self_bounds(generics);
268+
let (generics, mut supertrait_bounds) = separate_self_bounds(generics);
269+
270+
supertrait_bounds.retain(|b| {
271+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
272+
// is shown and none of the new sizedness traits leak into documentation.
273+
!b.is_meta_sized_bound(cx)
274+
});
275+
269276
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
270277
}
271278

272279
fn build_trait_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::TraitAlias {
273280
let generics = clean_ty_generics(cx, did);
274-
let (generics, bounds) = separate_self_bounds(generics);
281+
let (generics, mut bounds) = separate_self_bounds(generics);
282+
283+
bounds.retain(|b| {
284+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
285+
// is shown and none of the new sizedness traits leak into documentation.
286+
!b.is_meta_sized_bound(cx)
287+
});
288+
275289
clean::TraitAlias { generics, bounds }
276290
}
277291

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;
@@ -886,6 +886,10 @@ fn clean_ty_generics_inner<'tcx>(
886886
if b.is_sized_bound(cx) {
887887
has_sized = true;
888888
false
889+
} else if b.is_meta_sized_bound(cx) {
890+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
891+
// is shown and none of the new sizedness traits leak into documentation.
892+
false
889893
} else {
890894
true
891895
}
@@ -1448,6 +1452,13 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14481452
}
14491453
_ => true,
14501454
});
1455+
1456+
bounds.retain(|b| {
1457+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
1458+
// is shown and none of the new sizedness traits leak into documentation.
1459+
!b.is_meta_sized_bound(cx)
1460+
});
1461+
14511462
// Our Sized/?Sized bound didn't get handled when creating the generics
14521463
// because we didn't actually get our whole set of bounds until just now
14531464
// (some of them may have come from the trait). If we do have a sized
@@ -2276,6 +2287,12 @@ fn clean_middle_opaque_bounds<'tcx>(
22762287
_ => return None,
22772288
};
22782289

2290+
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
2291+
// is shown and none of the new sizedness traits leak into documentation.
2292+
if cx.tcx.is_lang_item(trait_ref.def_id(), LangItem::MetaSized) {
2293+
return None;
2294+
}
2295+
22792296
if let Some(sized) = cx.tcx.lang_items().sized_trait()
22802297
&& trait_ref.def_id() == sized
22812298
{

src/librustdoc/clean/simplify.rs

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

src/librustdoc/clean/types.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,11 +1289,19 @@ impl GenericBound {
12891289
}
12901290

12911291
pub(crate) fn is_sized_bound(&self, cx: &DocContext<'_>) -> bool {
1292+
self.is_bounded_by_lang_item(cx, LangItem::Sized)
1293+
}
1294+
1295+
pub(crate) fn is_meta_sized_bound(&self, cx: &DocContext<'_>) -> bool {
1296+
self.is_bounded_by_lang_item(cx, LangItem::MetaSized)
1297+
}
1298+
1299+
fn is_bounded_by_lang_item(&self, cx: &DocContext<'_>, lang_item: LangItem) -> bool {
12921300
if let GenericBound::TraitBound(
12931301
PolyTrait { ref trait_, .. },
12941302
rustc_hir::TraitBoundModifiers::NONE,
12951303
) = *self
1296-
&& Some(trait_.def_id()) == cx.tcx.lang_items().sized_trait()
1304+
&& cx.tcx.is_lang_item(trait_.def_id(), lang_item)
12971305
{
12981306
return true;
12991307
}

0 commit comments

Comments
 (0)