about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2022-07-24 15:08:24 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2022-07-24 15:08:24 +0200
commite55b0206f3e889bb90b734828e9c90dfdb426a92 (patch)
treedde905471610c3668837d86558d4df9cb7d3b1f6
parent8098f5faa880df18b0d7c83fdf5df8211a9e8dee (diff)
downloadrust-e55b0206f3e889bb90b734828e9c90dfdb426a92.tar.gz
rust-e55b0206f3e889bb90b734828e9c90dfdb426a92.zip
Remove Clean trait implementation for Constant
-rw-r--r--src/librustdoc/clean/mod.rs45
-rw-r--r--src/librustdoc/clean/utils.rs8
2 files changed, 27 insertions, 26 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 4c790e809c4..c9ef4748a48 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -237,13 +237,22 @@ impl<'tcx> Clean<'tcx, Lifetime> for hir::Lifetime {
     }
 }
 
-impl<'tcx> Clean<'tcx, Constant> for hir::ConstArg {
-    fn clean(&self, cx: &mut DocContext<'tcx>) -> Constant {
-        let def_id = cx.tcx.hir().body_owner_def_id(self.value.body).to_def_id();
-        Constant {
-            type_: clean_middle_ty(cx.tcx.type_of(def_id), cx, Some(def_id)),
-            kind: ConstantKind::Anonymous { body: self.value.body },
-        }
+pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant {
+    let def_id = cx.tcx.hir().body_owner_def_id(constant.value.body).to_def_id();
+    Constant {
+        type_: clean_middle_ty(cx.tcx.type_of(def_id), cx, Some(def_id)),
+        kind: ConstantKind::Anonymous { body: constant.value.body },
+    }
+}
+
+pub(crate) fn clean_middle_const<'tcx>(
+    constant: ty::Const<'tcx>,
+    cx: &mut DocContext<'tcx>,
+) -> Constant {
+    // FIXME: instead of storing the stringified expression, store `self` directly instead.
+    Constant {
+        type_: clean_middle_ty(constant.ty(), cx, None),
+        kind: ConstantKind::TyConst { expr: constant.to_string() },
     }
 }
 
@@ -392,7 +401,7 @@ impl<'tcx> Clean<'tcx, Term> for ty::Term<'tcx> {
     fn clean(&self, cx: &mut DocContext<'tcx>) -> Term {
         match self {
             ty::Term::Ty(ty) => Term::Type(clean_middle_ty(*ty, cx, None)),
-            ty::Term::Const(c) => Term::Constant(c.clean(cx)),
+            ty::Term::Const(c) => Term::Constant(clean_middle_const(*c, cx)),
         }
     }
 }
@@ -403,7 +412,7 @@ impl<'tcx> Clean<'tcx, Term> for hir::Term<'tcx> {
             hir::Term::Ty(ty) => Term::Type(clean_ty(ty, cx)),
             hir::Term::Const(c) => {
                 let def_id = cx.tcx.hir().local_def_id(c.hir_id);
-                Term::Constant(ty::Const::from_anon_const(cx.tcx, def_id).clean(cx))
+                Term::Constant(clean_middle_const(ty::Const::from_anon_const(cx.tcx, def_id), cx))
             }
         }
     }
@@ -1468,8 +1477,10 @@ fn maybe_expand_private_type_alias<'tcx>(
                     _ => None,
                 });
                 if let Some(ct) = const_ {
-                    substs
-                        .insert(const_param_def_id.to_def_id(), SubstParam::Constant(ct.clean(cx)));
+                    substs.insert(
+                        const_param_def_id.to_def_id(),
+                        SubstParam::Constant(clean_const(ct, cx)),
+                    );
                 }
                 // FIXME(const_generics_defaults)
                 indices.consts += 1;
@@ -1764,16 +1775,6 @@ pub(crate) fn clean_middle_ty<'tcx>(
     }
 }
 
-impl<'tcx> Clean<'tcx, Constant> for ty::Const<'tcx> {
-    fn clean(&self, cx: &mut DocContext<'tcx>) -> Constant {
-        // FIXME: instead of storing the stringified expression, store `self` directly instead.
-        Constant {
-            type_: clean_middle_ty(self.ty(), cx, None),
-            kind: ConstantKind::TyConst { expr: self.to_string() },
-        }
-    }
-}
-
 pub(crate) fn clean_field<'tcx>(field: &hir::FieldDef<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
     let def_id = cx.tcx.hir().local_def_id(field.hir_id).to_def_id();
     clean_field_with_def_id(def_id, field.ident.name, clean_ty(field.ty, cx), cx)
@@ -1895,7 +1896,7 @@ impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> {
                     }
                     hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
                     hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
-                    hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
+                    hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
                     hir::GenericArg::Infer(_inf) => GenericArg::Infer,
                 })
                 .collect::<Vec<_>>()
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index 00d62b37484..27ecea5cc40 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -2,9 +2,9 @@ use crate::clean::auto_trait::AutoTraitFinder;
 use crate::clean::blanket_impl::BlanketImplFinder;
 use crate::clean::render_macro_matchers::render_macro_matcher;
 use crate::clean::{
-    clean_middle_ty, inline, Clean, Crate, ExternalCrate, Generic, GenericArg, GenericArgs,
-    ImportSource, Item, ItemKind, Lifetime, Path, PathSegment, Primitive, PrimitiveType, Type,
-    TypeBinding, Visibility,
+    clean_middle_const, clean_middle_ty, inline, Clean, Crate, ExternalCrate, Generic, GenericArg,
+    GenericArgs, ImportSource, Item, ItemKind, Lifetime, Path, PathSegment, Primitive,
+    PrimitiveType, Type, TypeBinding, Visibility,
 };
 use crate::core::DocContext;
 use crate::formats::item_type::ItemType;
@@ -93,7 +93,7 @@ pub(crate) fn substs_to_args<'tcx>(
             None
         }
         GenericArgKind::Type(ty) => Some(GenericArg::Type(clean_middle_ty(ty, cx, None))),
-        GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
+        GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(clean_middle_const(ct, cx)))),
     }));
     ret_val
 }