@@ -15,6 +15,8 @@ use rustc_data_structures::thin_vec::ThinVec;
1515use rustc_hir as hir;
1616use rustc_hir:: def:: { DefKind , Res } ;
1717use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
18+ use rustc_middle:: mir;
19+ use rustc_middle:: mir:: interpret:: ConstValue ;
1820use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
1921use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
2022use rustc_span:: symbol:: { kw, sym, Symbol } ;
@@ -263,13 +265,13 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
263265}
264266
265267pub ( crate ) fn print_evaluated_const ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Option < String > {
266- tcx. const_eval_poly_for_typeck ( def_id) . ok ( ) . and_then ( |val| {
268+ tcx. const_eval_poly ( def_id) . ok ( ) . and_then ( |val| {
267269 let ty = tcx. type_of ( def_id) ;
268270 match ( val, ty. kind ( ) ) {
269271 ( _, & ty:: Ref ( ..) ) => None ,
270- ( Some ( ty :: ValTree :: Branch ( _ ) ) , & ty:: Adt ( _, _) ) => None ,
271- ( Some ( ty :: ValTree :: Leaf ( _ ) ) , _) => {
272- let const_ = ty :: Const :: from_value ( tcx , val. unwrap ( ) , ty) ;
272+ ( ConstValue :: Scalar ( _ ) , & ty:: Adt ( _, _) ) => None ,
273+ ( ConstValue :: Scalar ( _ ) , _) => {
274+ let const_ = mir :: ConstantKind :: from_value ( val, ty) ;
273275 Some ( print_const_with_custom_print_scalar ( tcx, const_) )
274276 }
275277 _ => None ,
@@ -303,19 +305,18 @@ fn format_integer_with_underscore_sep(num: &str) -> String {
303305 . collect ( )
304306}
305307
306- fn print_const_with_custom_print_scalar ( tcx : TyCtxt < ' _ > , ct : ty :: Const < ' _ > ) -> String {
308+ fn print_const_with_custom_print_scalar ( tcx : TyCtxt < ' _ > , ct : mir :: ConstantKind < ' _ > ) -> String {
307309 // Use a slightly different format for integer types which always shows the actual value.
308310 // For all other types, fallback to the original `pretty_print_const`.
309- match ( ct. kind ( ) , ct. ty ( ) . kind ( ) ) {
310- ( ty :: ConstKind :: Value ( ty :: ValTree :: Leaf ( int) ) , ty:: Uint ( ui) ) => {
311+ match ( ct, ct. ty ( ) . kind ( ) ) {
312+ ( mir :: ConstantKind :: Val ( ConstValue :: Scalar ( int) , _ ) , ty:: Uint ( ui) ) => {
311313 format ! ( "{}{}" , format_integer_with_underscore_sep( & int. to_string( ) ) , ui. name_str( ) )
312314 }
313- ( ty :: ConstKind :: Value ( ty :: ValTree :: Leaf ( int) ) , ty:: Int ( i) ) => {
315+ ( mir :: ConstantKind :: Val ( ConstValue :: Scalar ( int) , _ ) , ty:: Int ( i) ) => {
314316 let ty = tcx. lift ( ct. ty ( ) ) . unwrap ( ) ;
315317 let size = tcx. layout_of ( ty:: ParamEnv :: empty ( ) . and ( ty) ) . unwrap ( ) . size ;
316318 let data = int. assert_bits ( size) ;
317319 let sign_extended_data = size. sign_extend ( data) as i128 ;
318-
319320 format ! (
320321 "{}{}" ,
321322 format_integer_with_underscore_sep( & sign_extended_data. to_string( ) ) ,
0 commit comments