rustdoc: skip MetaSized bounds
These should never be shown to users at the moment.
This commit is contained in:
parent
d531a84e51
commit
2f8e760031
4 changed files with 52 additions and 7 deletions
|
|
@ -265,13 +265,27 @@ pub(crate) fn build_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait {
|
|||
.collect();
|
||||
|
||||
let generics = clean_ty_generics(cx, did);
|
||||
let (generics, supertrait_bounds) = separate_self_bounds(generics);
|
||||
let (generics, mut supertrait_bounds) = separate_self_bounds(generics);
|
||||
|
||||
supertrait_bounds.retain(|b| {
|
||||
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
|
||||
// is shown and none of the new sizedness traits leak into documentation.
|
||||
!b.is_meta_sized_bound(cx)
|
||||
});
|
||||
|
||||
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
|
||||
}
|
||||
|
||||
fn build_trait_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::TraitAlias {
|
||||
let generics = clean_ty_generics(cx, did);
|
||||
let (generics, bounds) = separate_self_bounds(generics);
|
||||
let (generics, mut bounds) = separate_self_bounds(generics);
|
||||
|
||||
bounds.retain(|b| {
|
||||
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
|
||||
// is shown and none of the new sizedness traits leak into documentation.
|
||||
!b.is_meta_sized_bound(cx)
|
||||
});
|
||||
|
||||
clean::TraitAlias { generics, bounds }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
|||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet, IndexEntry};
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_errors::{FatalError, struct_span_code_err};
|
||||
use rustc_hir::PredicateOrigin;
|
||||
use rustc_hir::def::{CtorKind, DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LOCAL_CRATE, LocalDefId};
|
||||
use rustc_hir::{LangItem, PredicateOrigin};
|
||||
use rustc_hir_analysis::hir_ty_lowering::FeedConstTy;
|
||||
use rustc_hir_analysis::{lower_const_arg_for_rustdoc, lower_ty};
|
||||
use rustc_middle::metadata::Reexport;
|
||||
|
|
@ -886,6 +886,10 @@ fn clean_ty_generics_inner<'tcx>(
|
|||
if b.is_sized_bound(cx) {
|
||||
has_sized = true;
|
||||
false
|
||||
} else if b.is_meta_sized_bound(cx) {
|
||||
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
|
||||
// is shown and none of the new sizedness traits leak into documentation.
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
|
@ -1448,6 +1452,13 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
|
|||
}
|
||||
_ => true,
|
||||
});
|
||||
|
||||
bounds.retain(|b| {
|
||||
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
|
||||
// is shown and none of the new sizedness traits leak into documentation.
|
||||
!b.is_meta_sized_bound(cx)
|
||||
});
|
||||
|
||||
// Our Sized/?Sized bound didn't get handled when creating the generics
|
||||
// because we didn't actually get our whole set of bounds until just now
|
||||
// (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>(
|
|||
_ => return None,
|
||||
};
|
||||
|
||||
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
|
||||
// is shown and none of the new sizedness traits leak into documentation.
|
||||
if cx.tcx.is_lang_item(trait_ref.def_id(), LangItem::MetaSized) {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(sized) = cx.tcx.lang_items().sized_trait()
|
||||
&& trait_ref.def_id() == sized
|
||||
{
|
||||
|
|
|
|||
|
|
@ -135,11 +135,17 @@ pub(crate) fn sized_bounds(cx: &mut DocContext<'_>, generics: &mut clean::Generi
|
|||
// don't actually know the set of associated types right here so that
|
||||
// should be handled when cleaning associated types.
|
||||
generics.where_predicates.retain(|pred| {
|
||||
if let WP::BoundPredicate { ty: clean::Generic(param), bounds, .. } = pred
|
||||
&& bounds.iter().any(|b| b.is_sized_bound(cx))
|
||||
{
|
||||
let WP::BoundPredicate { ty: clean::Generic(param), bounds, .. } = pred else {
|
||||
return true;
|
||||
};
|
||||
|
||||
if bounds.iter().any(|b| b.is_sized_bound(cx)) {
|
||||
sized_params.insert(*param);
|
||||
false
|
||||
} else if bounds.iter().any(|b| b.is_meta_sized_bound(cx)) {
|
||||
// FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized`
|
||||
// is shown and none of the new sizedness traits leak into documentation.
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1289,11 +1289,19 @@ impl GenericBound {
|
|||
}
|
||||
|
||||
pub(crate) fn is_sized_bound(&self, cx: &DocContext<'_>) -> bool {
|
||||
self.is_bounded_by_lang_item(cx, LangItem::Sized)
|
||||
}
|
||||
|
||||
pub(crate) fn is_meta_sized_bound(&self, cx: &DocContext<'_>) -> bool {
|
||||
self.is_bounded_by_lang_item(cx, LangItem::MetaSized)
|
||||
}
|
||||
|
||||
fn is_bounded_by_lang_item(&self, cx: &DocContext<'_>, lang_item: LangItem) -> bool {
|
||||
if let GenericBound::TraitBound(
|
||||
PolyTrait { ref trait_, .. },
|
||||
rustc_hir::TraitBoundModifiers::NONE,
|
||||
) = *self
|
||||
&& Some(trait_.def_id()) == cx.tcx.lang_items().sized_trait()
|
||||
&& cx.tcx.is_lang_item(trait_.def_id(), lang_item)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue