Skip to content

Commit d61a178

Browse files
Improve new Constant variants' name
1 parent e25e15c commit d61a178

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ crate fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
500500
}
501501

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

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

src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl Clean<Lifetime> for hir::GenericParam<'_> {
393393

394394
impl Clean<Constant> for hir::ConstArg {
395395
fn clean(&self, cx: &mut DocContext<'_>) -> Constant {
396-
Constant::Generic {
396+
Constant::Anonymous {
397397
type_: cx
398398
.tcx
399399
.type_of(cx.tcx.hir().body_owner_def_id(self.value.body).to_def_id())
@@ -1945,7 +1945,7 @@ 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::Const {
1948+
ItemKind::Const(ty, body_id) => ConstantItem(Constant::Local {
19491949
type_: ty.clean(cx),
19501950
body: body_id,
19511951
did: def_id,

src/librustdoc/clean/types.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,41 +1988,42 @@ crate struct Static {
19881988

19891989
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
19901990
crate enum Constant {
1991-
/// Typed constant value.
1991+
/// This is the wrapper around `ty::Const` for a non-local constant. Because it doesn't have a
1992+
/// `BodyId`, we need to handle it on its own.
19921993
TyConst { type_: Type, expr: String },
19931994
/// A constant (expression) that’s not an item or associated item. These are usually found
19941995
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
19951996
/// used to define explicit discriminant values for enum variants.
1996-
Generic { type_: Type, body: BodyId },
1997-
/// Inlined constant (from another crate).
1998-
Inline { type_: Type, did: DefId },
1997+
Anonymous { type_: Type, body: BodyId },
1998+
/// Inlined constant.
1999+
Extern { type_: Type, did: DefId },
19992000
/// const FOO: u32 = ...;
2000-
Const { type_: Type, did: DefId, body: BodyId },
2001+
Local { type_: Type, did: DefId, body: BodyId },
20012002
}
20022003

20032004
impl Constant {
20042005
crate fn expr(&self, tcx: TyCtxt<'_>) -> String {
20052006
match self {
20062007
Self::TyConst { expr, .. } => expr.clone(),
2007-
Self::Inline { did, .. } => print_inlined_const(tcx, *did),
2008-
Self::Const { body, .. } | Self::Generic { body, .. } => print_const_expr(tcx, *body),
2008+
Self::Extern { did, .. } => print_inlined_const(tcx, *did),
2009+
Self::Local { body, .. } | Self::Anonymous { body, .. } => print_const_expr(tcx, *body),
20092010
}
20102011
}
20112012

20122013
crate fn value(&self, tcx: TyCtxt<'_>) -> Option<String> {
20132014
match self {
2014-
Self::TyConst { .. } | Self::Generic { .. } => None,
2015-
Self::Inline { did, .. } | Self::Const { did, .. } => print_evaluated_const(tcx, *did),
2015+
Self::TyConst { .. } | Self::Anonymous { .. } => None,
2016+
Self::Extern { did, .. } | Self::Local { did, .. } => print_evaluated_const(tcx, *did),
20162017
}
20172018
}
20182019

20192020
crate fn is_literal(&self, tcx: TyCtxt<'_>) -> bool {
20202021
match self {
20212022
Self::TyConst { .. } => false,
2022-
Self::Inline { did, .. } => did
2023+
Self::Extern { did, .. } => did
20232024
.as_local()
20242025
.map_or(false, |did| is_literal_expr(tcx, tcx.hir().local_def_id_to_hir_id(did))),
2025-
Self::Const { body, .. } | Self::Generic { body, .. } => {
2026+
Self::Local { body, .. } | Self::Anonymous { body, .. } => {
20262027
is_literal_expr(tcx, body.hir_id)
20272028
}
20282029
}
@@ -2031,18 +2032,18 @@ impl Constant {
20312032
crate fn type_(&self) -> &Type {
20322033
match *self {
20332034
Self::TyConst { ref type_, .. }
2034-
| Self::Inline { ref type_, .. }
2035-
| Self::Const { ref type_, .. }
2036-
| Self::Generic { ref type_, .. } => type_,
2035+
| Self::Extern { ref type_, .. }
2036+
| Self::Local { ref type_, .. }
2037+
| Self::Anonymous { ref type_, .. } => type_,
20372038
}
20382039
}
20392040

20402041
crate fn to_type(self) -> Type {
20412042
match self {
20422043
Self::TyConst { type_, .. }
2043-
| Self::Inline { type_, .. }
2044-
| Self::Const { type_, .. }
2045-
| Self::Generic { type_, .. } => type_,
2044+
| Self::Extern { type_, .. }
2045+
| Self::Local { type_, .. }
2046+
| Self::Anonymous { type_, .. } => type_,
20462047
}
20472048
}
20482049
}

0 commit comments

Comments
 (0)