提交 ee509337 编写于 作者: G Guillaume Gomez

Rename clean::Constant did fields to def_id

上级 d61a1786
......@@ -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 {
......
......@@ -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<Constant> 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<Item> {
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),
......
......@@ -1995,17 +1995,17 @@ fn def_id_full(&self, cache: &Cache) -> Option<DefId> {
/// 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<String> {
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)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册