@@ -670,7 +670,7 @@ crate enum ItemKind {
670670 MacroItem ( Macro ) ,
671671 ProcMacroItem ( ProcMacro ) ,
672672 PrimitiveItem ( PrimitiveType ) ,
673- AssocConstItem ( Type , Option < String > ) ,
673+ AssocConstItem ( Type , Option < ConstantKind > ) ,
674674 /// An associated item in a trait or trait impl.
675675 ///
676676 /// The bounds may be non-empty if there is a `where` clause.
@@ -2153,7 +2153,21 @@ crate enum ConstantKind {
21532153
21542154impl Constant {
21552155 crate fn expr ( & self , tcx : TyCtxt < ' _ > ) -> String {
2156- match self . kind {
2156+ self . kind . expr ( tcx)
2157+ }
2158+
2159+ crate fn value ( & self , tcx : TyCtxt < ' _ > ) -> Option < String > {
2160+ self . kind . value ( tcx)
2161+ }
2162+
2163+ crate fn is_literal ( & self , tcx : TyCtxt < ' _ > ) -> bool {
2164+ self . kind . is_literal ( tcx)
2165+ }
2166+ }
2167+
2168+ impl ConstantKind {
2169+ crate fn expr ( & self , tcx : TyCtxt < ' _ > ) -> String {
2170+ match * self {
21572171 ConstantKind :: TyConst { ref expr } => expr. clone ( ) ,
21582172 ConstantKind :: Extern { def_id } => print_inlined_const ( tcx, def_id) ,
21592173 ConstantKind :: Local { body, .. } | ConstantKind :: Anonymous { body } => {
@@ -2163,7 +2177,7 @@ impl Constant {
21632177 }
21642178
21652179 crate fn value ( & self , tcx : TyCtxt < ' _ > ) -> Option < String > {
2166- match self . kind {
2180+ match * self {
21672181 ConstantKind :: TyConst { .. } | ConstantKind :: Anonymous { .. } => None ,
21682182 ConstantKind :: Extern { def_id } | ConstantKind :: Local { def_id, .. } => {
21692183 print_evaluated_const ( tcx, def_id)
@@ -2172,7 +2186,7 @@ impl Constant {
21722186 }
21732187
21742188 crate fn is_literal ( & self , tcx : TyCtxt < ' _ > ) -> bool {
2175- match self . kind {
2189+ match * self {
21762190 ConstantKind :: TyConst { .. } => false ,
21772191 ConstantKind :: Extern { def_id } => def_id. as_local ( ) . map_or ( false , |def_id| {
21782192 is_literal_expr ( tcx, tcx. hir ( ) . local_def_id_to_hir_id ( def_id) )
0 commit comments