@@ -1988,41 +1988,42 @@ crate struct Static {
19881988
19891989#[ derive( Clone , PartialEq , Eq , Hash , Debug ) ]
19901990crate 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
20032004impl 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