]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/clean/mod.rs
Auto merge of #94934 - Lireer:const-prop-lint, r=oli-obk
[rust.git] / src / librustdoc / clean / mod.rs
index a58af4f44e2cc9660f140e6d6311a26321a14159..1e3260ce9ae2be0d7a394d754d33f0a4ff14040c 100644 (file)
@@ -107,9 +107,9 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Option<GenericBound> {
                 let trait_ref = ty::TraitRef::identity(cx.tcx, def_id).skip_binder();
 
                 let generic_args = generic_args.clean(cx);
-                let bindings = match generic_args {
-                    GenericArgs::AngleBracketed { bindings, .. } => bindings,
-                    _ => bug!("clean: parenthesized `GenericBound::LangItemTrait`"),
+                let GenericArgs::AngleBracketed { bindings, .. } = generic_args
+                else {
+                    bug!("clean: parenthesized `GenericBound::LangItemTrait`");
                 };
 
                 let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings);
@@ -121,11 +121,20 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Option<GenericBound> {
             hir::GenericBound::Trait(ref t, modifier) => {
                 // `T: ~const Drop` is not equivalent to `T: Drop`, and we don't currently document `~const` bounds
                 // because of its experimental status, so just don't show these.
-                if Some(t.trait_ref.trait_def_id().unwrap()) == cx.tcx.lang_items().drop_trait()
-                    && hir::TraitBoundModifier::MaybeConst == modifier
+                // `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
+                if modifier == hir::TraitBoundModifier::MaybeConst
+                    && [cx.tcx.lang_items().drop_trait(), cx.tcx.lang_items().destruct_trait()]
+                        .iter()
+                        .any(|tr| *tr == Some(t.trait_ref.trait_def_id().unwrap()))
                 {
                     return None;
                 }
+
+                #[cfg(bootstrap)]
+                {
+                    // FIXME: remove `lang_items().drop_trait()` from above logic,
+                    // as well as the comment about `~const Drop` because it was renamed to `Destruct`.
+                }
                 GenericBound::TraitBound(t.clean(cx), modifier)
             }
         })
@@ -306,12 +315,21 @@ impl<'a> Clean<Option<WherePredicate>> for ty::PolyTraitPredicate<'a> {
     fn clean(&self, cx: &mut DocContext<'_>) -> Option<WherePredicate> {
         // `T: ~const Drop` is not equivalent to `T: Drop`, and we don't currently document `~const` bounds
         // because of its experimental status, so just don't show these.
+        // `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
         if self.skip_binder().constness == ty::BoundConstness::ConstIfConst
-            && Some(self.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().drop_trait()
+            && [cx.tcx.lang_items().drop_trait(), cx.tcx.lang_items().destruct_trait()]
+                .iter()
+                .any(|tr| *tr == Some(self.skip_binder().def_id()))
         {
             return None;
         }
 
+        #[cfg(bootstrap)]
+        {
+            // FIXME: remove `lang_items().drop_trait()` from above logic,
+            // as well as the comment about `~const Drop` because it was renamed to `Destruct`.
+        }
+
         let poly_trait_ref = self.map_bound(|pred| pred.trait_ref);
         Some(WherePredicate::BoundPredicate {
             ty: poly_trait_ref.skip_binder().self_ty().clean(cx),
@@ -829,7 +847,7 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[ast::Attrib
                             .values
                             .insert(a as _, Argument { name, type_: *ty, is_const: true });
                     } else {
-                        panic!("unexpected non const in position {}", pos);
+                        panic!("unexpected non const in position {pos}");
                     }
                 }
                 _ => panic!("invalid arg index"),
@@ -1273,10 +1291,7 @@ fn param_eq_arg(param: &GenericParamDef, arg: &GenericArg) -> bool {
 
 fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
     let hir::Ty { hir_id: _, span, ref kind } = *hir_ty;
-    let qpath = match kind {
-        hir::TyKind::Path(qpath) => qpath,
-        _ => unreachable!(),
-    };
+    let hir::TyKind::Path(qpath) = kind else { unreachable!() };
 
     match qpath {
         hir::QPath::Resolved(None, ref path) => {