@@ -8,7 +8,8 @@ use crate::ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr};
8
8
use crate :: ty:: { Param , Bound , RawPtr , Ref , Never , Tuple } ;
9
9
use crate :: ty:: { Closure , Generator , GeneratorWitness , Foreign , Projection , Opaque } ;
10
10
use crate :: ty:: { Placeholder , UnnormalizedProjection , Dynamic , Int , Uint , Infer } ;
11
- use crate :: ty:: { self , Ty , TyCtxt , TypeFoldable , GenericParamCount , GenericParamDefKind } ;
11
+ use crate :: ty:: { self , Ty , TyCtxt , TypeFoldable , GenericParamCount , GenericParamDefKind , ParamConst } ;
12
+ use crate :: mir:: interpret:: ConstValue ;
12
13
use crate :: util:: nodemap:: FxHashSet ;
13
14
14
15
use std:: cell:: Cell ;
@@ -478,6 +479,7 @@ impl PrintContext {
478
479
GenericParamDefKind :: Type { has_default, .. } => {
479
480
Some ( ( param. def_id , has_default) )
480
481
}
482
+ GenericParamDefKind :: Const => None , // FIXME(const_generics:defaults)
481
483
} ) . peekable ( ) ;
482
484
let has_default = {
483
485
let has_default = type_params. peek ( ) . map ( |( _, has_default) | has_default) ;
@@ -571,6 +573,14 @@ impl PrintContext {
571
573
) ?;
572
574
}
573
575
576
+ // FIXME(const_generics::defaults)
577
+ let consts = substs. consts ( ) ;
578
+
579
+ for ct in consts {
580
+ start_or_continue ( f, "<" , ", " ) ?;
581
+ ct. print_display ( f, self ) ?;
582
+ }
583
+
574
584
start_or_continue ( f, "" , ">" ) ?;
575
585
576
586
// For values, also print their name and type parameters.
@@ -763,7 +773,8 @@ impl fmt::Debug for ty::GenericParamDef {
763
773
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
764
774
let type_name = match self . kind {
765
775
ty:: GenericParamDefKind :: Lifetime => "Lifetime" ,
766
- ty:: GenericParamDefKind :: Type { ..} => "Type" ,
776
+ ty:: GenericParamDefKind :: Type { .. } => "Type" ,
777
+ ty:: GenericParamDefKind :: Const => "Const" ,
767
778
} ;
768
779
write ! ( f, "{}({}, {:?}, {})" ,
769
780
type_name,
@@ -1088,6 +1099,12 @@ impl fmt::Debug for ty::TyVid {
1088
1099
}
1089
1100
}
1090
1101
1102
+ impl < ' tcx > fmt:: Debug for ty:: ConstVid < ' tcx > {
1103
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1104
+ write ! ( f, "_#{}f" , self . index)
1105
+ }
1106
+ }
1107
+
1091
1108
impl fmt:: Debug for ty:: IntVid {
1092
1109
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1093
1110
write ! ( f, "_#{}i" , self . index)
@@ -1448,7 +1465,12 @@ define_print! {
1448
1465
write!( f, "_" ) ?;
1449
1466
}
1450
1467
ty:: LazyConst :: Evaluated ( c) => ty:: tls:: with( |tcx| {
1451
- write!( f, "{}" , c. unwrap_usize( tcx) )
1468
+ match c. val {
1469
+ ConstValue :: Infer ( ..) => write!( f, "_" ) ,
1470
+ ConstValue :: Param ( ParamConst { name, .. } ) =>
1471
+ write!( f, "{}" , name) ,
1472
+ _ => write!( f, "{}" , c. unwrap_usize( tcx) ) ,
1473
+ }
1452
1474
} ) ?,
1453
1475
}
1454
1476
write!( f, "]" )
@@ -1472,6 +1494,37 @@ define_print! {
1472
1494
}
1473
1495
}
1474
1496
1497
+ define_print ! {
1498
+ ( ' tcx) ConstValue <' tcx>, ( self , f, cx) {
1499
+ display {
1500
+ match self {
1501
+ ConstValue :: Infer ( ..) => write!( f, "_" ) ,
1502
+ ConstValue :: Param ( ParamConst { name, .. } ) => write!( f, "{}" , name) ,
1503
+ _ => write!( f, "{:?}" , self ) ,
1504
+ }
1505
+ }
1506
+ }
1507
+ }
1508
+
1509
+ define_print ! {
1510
+ ( ' tcx) ty:: Const <' tcx>, ( self , f, cx) {
1511
+ display {
1512
+ write!( f, "{} : {}" , self . val, self . ty)
1513
+ }
1514
+ }
1515
+ }
1516
+
1517
+ define_print ! {
1518
+ ( ' tcx) ty:: LazyConst <' tcx>, ( self , f, cx) {
1519
+ display {
1520
+ match self {
1521
+ ty:: LazyConst :: Unevaluated ( ..) => write!( f, "_ : _" ) ,
1522
+ ty:: LazyConst :: Evaluated ( c) => write!( f, "{}" , c) ,
1523
+ }
1524
+ }
1525
+ }
1526
+ }
1527
+
1475
1528
define_print ! {
1476
1529
( ) ty:: ParamTy , ( self , f, cx) {
1477
1530
display {
@@ -1483,6 +1536,17 @@ define_print! {
1483
1536
}
1484
1537
}
1485
1538
1539
+ define_print ! {
1540
+ ( ) ty:: ParamConst , ( self , f, cx) {
1541
+ display {
1542
+ write!( f, "{}" , self . name)
1543
+ }
1544
+ debug {
1545
+ write!( f, "{}/#{}" , self . name, self . index)
1546
+ }
1547
+ }
1548
+ }
1549
+
1486
1550
define_print ! {
1487
1551
( ' tcx, T : Print + fmt:: Debug , U : Print + fmt:: Debug ) ty:: OutlivesPredicate <T , U >,
1488
1552
( self , f, cx) {
0 commit comments