@@ -1995,34 +1995,36 @@ crate enum Constant {
1995
1995
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
1996
1996
/// used to define explicit discriminant values for enum variants.
1997
1997
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 } ,
2000
2000
/// const FOO: u32 = ...;
2001
- Local { type_ : Type , did : DefId , body : BodyId } ,
2001
+ Local { type_ : Type , def_id : DefId , body : BodyId } ,
2002
2002
}
2003
2003
2004
2004
impl Constant {
2005
2005
crate fn expr ( & self , tcx : TyCtxt < ' _ > ) -> String {
2006
2006
match self {
2007
2007
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 ) ,
2009
2009
Self :: Local { body, .. } | Self :: Anonymous { body, .. } => print_const_expr ( tcx, * body) ,
2010
2010
}
2011
2011
}
2012
2012
2013
2013
crate fn value ( & self , tcx : TyCtxt < ' _ > ) -> Option < String > {
2014
2014
match self {
2015
2015
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
+ }
2017
2019
}
2018
2020
}
2019
2021
2020
2022
crate fn is_literal ( & self , tcx : TyCtxt < ' _ > ) -> bool {
2021
2023
match self {
2022
2024
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
+ } ) ,
2026
2028
Self :: Local { body, .. } | Self :: Anonymous { body, .. } => {
2027
2029
is_literal_expr ( tcx, body. hir_id )
2028
2030
}
0 commit comments