@@ -1988,41 +1988,42 @@ crate struct Static {
1988
1988
1989
1989
#[ derive( Clone , PartialEq , Eq , Hash , Debug ) ]
1990
1990
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.
1992
1993
TyConst { type_ : Type , expr : String } ,
1993
1994
/// A constant (expression) that’s not an item or associated item. These are usually found
1994
1995
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
1995
1996
/// 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 } ,
1999
2000
/// const FOO: u32 = ...;
2000
- Const { type_ : Type , did : DefId , body : BodyId } ,
2001
+ Local { type_ : Type , did : DefId , body : BodyId } ,
2001
2002
}
2002
2003
2003
2004
impl Constant {
2004
2005
crate fn expr ( & self , tcx : TyCtxt < ' _ > ) -> String {
2005
2006
match self {
2006
2007
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) ,
2009
2010
}
2010
2011
}
2011
2012
2012
2013
crate fn value ( & self , tcx : TyCtxt < ' _ > ) -> Option < String > {
2013
2014
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) ,
2016
2017
}
2017
2018
}
2018
2019
2019
2020
crate fn is_literal ( & self , tcx : TyCtxt < ' _ > ) -> bool {
2020
2021
match self {
2021
2022
Self :: TyConst { .. } => false ,
2022
- Self :: Inline { did, .. } => did
2023
+ Self :: Extern { did, .. } => did
2023
2024
. as_local ( )
2024
2025
. 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, .. } => {
2026
2027
is_literal_expr ( tcx, body. hir_id )
2027
2028
}
2028
2029
}
@@ -2031,18 +2032,18 @@ impl Constant {
2031
2032
crate fn type_ ( & self ) -> & Type {
2032
2033
match * self {
2033
2034
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_,
2037
2038
}
2038
2039
}
2039
2040
2040
2041
crate fn to_type ( self ) -> Type {
2041
2042
match self {
2042
2043
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_,
2046
2047
}
2047
2048
}
2048
2049
}
0 commit comments