Skip to content

Commit ee50933

Browse files
Rename clean::Constant did fields to def_id
1 parent d61a178 commit ee50933

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ crate fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
499499
}
500500
}
501501

502-
fn build_const(cx: &mut DocContext<'_>, did: DefId) -> clean::Constant {
503-
clean::Constant::Extern { type_: cx.tcx.type_of(did).clean(cx), did }
502+
fn build_const(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
503+
clean::Constant::Extern { type_: cx.tcx.type_of(def_id).clean(cx), def_id }
504504
}
505505

506506
fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {

src/librustdoc/clean/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ impl Clean<Item> for ty::AssocItem {
11331133
ty::AssocKind::Const => {
11341134
let ty = tcx.type_of(self.def_id);
11351135
let default = if self.defaultness.has_value() {
1136-
Some(inline::print_inlined_const(cx.tcx, self.def_id))
1136+
Some(inline::print_inlined_const(tcx, self.def_id))
11371137
} else {
11381138
None
11391139
};
@@ -1743,8 +1743,8 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
17431743

17441744
impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
17451745
fn clean(&self, cx: &mut DocContext<'_>) -> Constant {
1746-
// FIXME: instead of storing `format!("{}", self)`, store `self` directly instead.
1747-
Constant::TyConst { type_: self.ty.clean(cx), expr: format!("{}", self) }
1746+
// FIXME: instead of storing the stringified expression, store `self` directly instead.
1747+
Constant::TyConst { type_: self.ty.clean(cx), expr: self.to_string() }
17481748
}
17491749
}
17501750

@@ -1945,11 +1945,9 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
19451945
ItemKind::Static(ty, mutability, body_id) => {
19461946
StaticItem(Static { type_: ty.clean(cx), mutability, expr: Some(body_id) })
19471947
}
1948-
ItemKind::Const(ty, body_id) => ConstantItem(Constant::Local {
1949-
type_: ty.clean(cx),
1950-
body: body_id,
1951-
did: def_id,
1952-
}),
1948+
ItemKind::Const(ty, body_id) => {
1949+
ConstantItem(Constant::Local { type_: ty.clean(cx), body: body_id, def_id })
1950+
}
19531951
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
19541952
bounds: ty.bounds.clean(cx),
19551953
generics: ty.generics.clean(cx),

src/librustdoc/clean/types.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,34 +1995,36 @@ crate enum Constant {
19951995
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
19961996
/// used to define explicit discriminant values for enum variants.
19971997
Anonymous { type_: Type, body: BodyId },
1998-
/// Inlined constant.
1999-
Extern { type_: Type, did: DefId },
1998+
/// A constant from a different crate.
1999+
Extern { type_: Type, def_id: DefId },
20002000
/// const FOO: u32 = ...;
2001-
Local { type_: Type, did: DefId, body: BodyId },
2001+
Local { type_: Type, def_id: DefId, body: BodyId },
20022002
}
20032003

20042004
impl Constant {
20052005
crate fn expr(&self, tcx: TyCtxt<'_>) -> String {
20062006
match self {
20072007
Self::TyConst { expr, .. } => expr.clone(),
2008-
Self::Extern { did, .. } => print_inlined_const(tcx, *did),
2008+
Self::Extern { def_id, .. } => print_inlined_const(tcx, *def_id),
20092009
Self::Local { body, .. } | Self::Anonymous { body, .. } => print_const_expr(tcx, *body),
20102010
}
20112011
}
20122012

20132013
crate fn value(&self, tcx: TyCtxt<'_>) -> Option<String> {
20142014
match self {
20152015
Self::TyConst { .. } | Self::Anonymous { .. } => None,
2016-
Self::Extern { did, .. } | Self::Local { did, .. } => print_evaluated_const(tcx, *did),
2016+
Self::Extern { def_id, .. } | Self::Local { def_id, .. } => {
2017+
print_evaluated_const(tcx, *def_id)
2018+
}
20172019
}
20182020
}
20192021

20202022
crate fn is_literal(&self, tcx: TyCtxt<'_>) -> bool {
20212023
match self {
20222024
Self::TyConst { .. } => false,
2023-
Self::Extern { did, .. } => did
2024-
.as_local()
2025-
.map_or(false, |did| is_literal_expr(tcx, tcx.hir().local_def_id_to_hir_id(did))),
2025+
Self::Extern { def_id, .. } => def_id.as_local().map_or(false, |def_id| {
2026+
is_literal_expr(tcx, tcx.hir().local_def_id_to_hir_id(def_id))
2027+
}),
20262028
Self::Local { body, .. } | Self::Anonymous { body, .. } => {
20272029
is_literal_expr(tcx, body.hir_id)
20282030
}

0 commit comments

Comments
 (0)