@@ -15,6 +15,8 @@ use rustc_data_structures::thin_vec::ThinVec;
15
15
use rustc_hir as hir;
16
16
use rustc_hir:: def:: { DefKind , Res } ;
17
17
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
18
+ use rustc_middle:: mir;
19
+ use rustc_middle:: mir:: interpret:: ConstValue ;
18
20
use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
19
21
use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
20
22
use rustc_span:: symbol:: { kw, sym, Symbol } ;
@@ -263,13 +265,13 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
263
265
}
264
266
265
267
pub ( 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| {
267
269
let ty = tcx. type_of ( def_id) ;
268
270
match ( val, ty. kind ( ) ) {
269
271
( _, & 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) ;
273
275
Some ( print_const_with_custom_print_scalar ( tcx, const_) )
274
276
}
275
277
_ => None ,
@@ -303,19 +305,18 @@ fn format_integer_with_underscore_sep(num: &str) -> String {
303
305
. collect ( )
304
306
}
305
307
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 {
307
309
// Use a slightly different format for integer types which always shows the actual value.
308
310
// 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) ) => {
311
313
format ! ( "{}{}" , format_integer_with_underscore_sep( & int. to_string( ) ) , ui. name_str( ) )
312
314
}
313
- ( ty :: ConstKind :: Value ( ty :: ValTree :: Leaf ( int) ) , ty:: Int ( i) ) => {
315
+ ( mir :: ConstantKind :: Val ( ConstValue :: Scalar ( int) , _ ) , ty:: Int ( i) ) => {
314
316
let ty = tcx. lift ( ct. ty ( ) ) . unwrap ( ) ;
315
317
let size = tcx. layout_of ( ty:: ParamEnv :: empty ( ) . and ( ty) ) . unwrap ( ) . size ;
316
318
let data = int. assert_bits ( size) ;
317
319
let sign_extended_data = size. sign_extend ( data) as i128 ;
318
-
319
320
format ! (
320
321
"{}{}" ,
321
322
format_integer_with_underscore_sep( & sign_extended_data. to_string( ) ) ,
0 commit comments