diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 10487dc258078832144326020bc907426c46480a..29be2b9f37ee6f6f9ce10fce33b3fa6673ce1b15 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -499,8 +499,8 @@ fn build_module( } } -fn build_const(cx: &mut DocContext<'_>, did: DefId) -> clean::Constant { - clean::Constant::Extern { type_: cx.tcx.type_of(did).clean(cx), did } +fn build_const(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant { + clean::Constant::Extern { type_: cx.tcx.type_of(def_id).clean(cx), def_id } } fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 953184b0a769f78853c0eb5abb9d1e9589520b73..3dfe1febbd33015f60545a3eb8433b0de4f5a9b9 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1133,7 +1133,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Item { ty::AssocKind::Const => { let ty = tcx.type_of(self.def_id); let default = if self.defaultness.has_value() { - Some(inline::print_inlined_const(cx.tcx, self.def_id)) + Some(inline::print_inlined_const(tcx, self.def_id)) } else { None }; @@ -1743,8 +1743,8 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Type { impl<'tcx> Clean for ty::Const<'tcx> { fn clean(&self, cx: &mut DocContext<'_>) -> Constant { - // FIXME: instead of storing `format!("{}", self)`, store `self` directly instead. - Constant::TyConst { type_: self.ty.clean(cx), expr: format!("{}", self) } + // FIXME: instead of storing the stringified expression, store `self` directly instead. + Constant::TyConst { type_: self.ty.clean(cx), expr: self.to_string() } } } @@ -1945,11 +1945,9 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Vec { ItemKind::Static(ty, mutability, body_id) => { StaticItem(Static { type_: ty.clean(cx), mutability, expr: Some(body_id) }) } - ItemKind::Const(ty, body_id) => ConstantItem(Constant::Local { - type_: ty.clean(cx), - body: body_id, - did: def_id, - }), + ItemKind::Const(ty, body_id) => { + ConstantItem(Constant::Local { type_: ty.clean(cx), body: body_id, def_id }) + } ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy { bounds: ty.bounds.clean(cx), generics: ty.generics.clean(cx), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 5a3f9c8ea52121391d8107b151a40dc156bb531a..a27529caf051c031729709231ad86ac41df46b64 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1995,17 +1995,17 @@ fn def_id_full(&self, cache: &Cache) -> Option { /// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also /// used to define explicit discriminant values for enum variants. Anonymous { type_: Type, body: BodyId }, - /// Inlined constant. - Extern { type_: Type, did: DefId }, + /// A constant from a different crate. + Extern { type_: Type, def_id: DefId }, /// const FOO: u32 = ...; - Local { type_: Type, did: DefId, body: BodyId }, + Local { type_: Type, def_id: DefId, body: BodyId }, } impl Constant { crate fn expr(&self, tcx: TyCtxt<'_>) -> String { match self { Self::TyConst { expr, .. } => expr.clone(), - Self::Extern { did, .. } => print_inlined_const(tcx, *did), + Self::Extern { def_id, .. } => print_inlined_const(tcx, *def_id), Self::Local { body, .. } | Self::Anonymous { body, .. } => print_const_expr(tcx, *body), } } @@ -2013,16 +2013,18 @@ impl Constant { crate fn value(&self, tcx: TyCtxt<'_>) -> Option { match self { Self::TyConst { .. } | Self::Anonymous { .. } => None, - Self::Extern { did, .. } | Self::Local { did, .. } => print_evaluated_const(tcx, *did), + Self::Extern { def_id, .. } | Self::Local { def_id, .. } => { + print_evaluated_const(tcx, *def_id) + } } } crate fn is_literal(&self, tcx: TyCtxt<'_>) -> bool { match self { Self::TyConst { .. } => false, - Self::Extern { did, .. } => did - .as_local() - .map_or(false, |did| is_literal_expr(tcx, tcx.hir().local_def_id_to_hir_id(did))), + Self::Extern { def_id, .. } => def_id.as_local().map_or(false, |def_id| { + is_literal_expr(tcx, tcx.hir().local_def_id_to_hir_id(def_id)) + }), Self::Local { body, .. } | Self::Anonymous { body, .. } => { is_literal_expr(tcx, body.hir_id) }