about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david.wood2@arm.com>2025-03-02 23:36:00 +0000
committerDavid Wood <david.wood2@arm.com>2025-06-16 23:04:36 +0000
commit2f8e7600314f902fdb3daccda1ab9b44b4e9e95e (patch)
treea7a97a2658725ba428d78edf4dc492e5774f7b3b
parentd531a84e51e116f7b193d2624037b936987ced07 (diff)
downloadrust-2f8e7600314f902fdb3daccda1ab9b44b4e9e95e.tar.gz
rust-2f8e7600314f902fdb3daccda1ab9b44b4e9e95e.zip
rustdoc: skip `MetaSized` bounds
These should never be shown to users at the moment.
-rw-r--r--src/librustdoc/clean/inline.rs18
-rw-r--r--src/librustdoc/clean/mod.rs19
-rw-r--r--src/librustdoc/clean/simplify.rs12
-rw-r--r--src/librustdoc/clean/types.rs10
4 files changed, 52 insertions, 7 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index 9b5491310b4..dcd499d5f0d 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -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 }
 }
 
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index db4bcdaeb6c..d77bdf09d01 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -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
             {
diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs
index 40efa997868..f813e6c5517 100644
--- a/src/librustdoc/clean/simplify.rs
+++ b/src/librustdoc/clean/simplify.rs
@@ -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
         }
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index 58e05bd1e85..2d9670a3d10 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -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;
         }