@@ -1539,76 +1539,93 @@ define_print_and_forward_display! {
1539
1539
1540
1540
& ' tcx ty:: Const <' tcx> {
1541
1541
let u8 = cx. tcx( ) . types. u8 ;
1542
- match ( self . val, & self . ty. sty) {
1543
- ( ConstValue :: Unevaluated ( did, substs) , _) => {
1544
- match cx. tcx( ) . describe_def( did) {
1545
- | Some ( Def :: Static ( _, _) )
1546
- | Some ( Def :: Const ( _) )
1547
- | Some ( Def :: AssociatedConst ( _) ) => p!( write( "{}" , cx. tcx( ) . def_path_str( did) ) ) ,
1548
- _ => p!( write( "_" ) ) ,
1542
+ if let ty:: FnDef ( did, _) = self . ty. sty {
1543
+ p!( write( "{}" , cx. tcx( ) . def_path_str( did) ) ) ;
1544
+ return Ok ( cx) ;
1545
+ }
1546
+ if let ConstValue :: Unevaluated ( did, substs) = self . val {
1547
+ match cx. tcx( ) . describe_def( did) {
1548
+ | Some ( Def :: Static ( _, _) )
1549
+ | Some ( Def :: Const ( _, false ) )
1550
+ | Some ( Def :: AssociatedConst ( _) ) => p!( write( "{}" , cx. tcx( ) . def_path_str( did) ) ) ,
1551
+ _ => p!( write( "_" ) ) ,
1552
+ }
1553
+ return Ok ( cx) ;
1554
+ }
1555
+ if let ConstValue :: Infer ( ..) = self . val {
1556
+ p!( write( "_: " ) , print( self . ty) ) ;
1557
+ return Ok ( cx) ;
1558
+ }
1559
+ if let ConstValue :: Param ( ParamConst { name, .. } ) = self . val {
1560
+ p!( write( "{}" , name) ) ;
1561
+ return Ok ( cx) ;
1562
+ }
1563
+ if let ConstValue :: Scalar ( Scalar :: Bits { bits, .. } ) = self . val {
1564
+ match self . ty. sty {
1565
+ ty:: Bool => {
1566
+ p!( write( "{}" , if bits == 0 { "false" } else { "true" } ) ) ;
1567
+ return Ok ( cx) ;
1568
+ } ,
1569
+ ty:: Float ( ast:: FloatTy :: F32 ) => {
1570
+ p!( write( "{}f32" , Single :: from_bits( bits) ) ) ;
1571
+ return Ok ( cx) ;
1572
+ } ,
1573
+ ty:: Float ( ast:: FloatTy :: F64 ) => {
1574
+ p!( write( "{}f64" , Double :: from_bits( bits) ) ) ;
1575
+ return Ok ( cx) ;
1576
+ } ,
1577
+ ty:: Uint ( ui) => {
1578
+ p!( write( "{}{}" , bits, ui) ) ;
1579
+ return Ok ( cx) ;
1580
+ } ,
1581
+ ty:: Int ( i) =>{
1582
+ let ty = cx. tcx( ) . lift_to_global( & self . ty) . unwrap( ) ;
1583
+ let size = cx. tcx( ) . layout_of( ty:: ParamEnv :: empty( ) . and( ty) )
1584
+ . unwrap( )
1585
+ . size;
1586
+ p!( write( "{}{}" , sign_extend( bits, size) as i128 , i) ) ;
1587
+ return Ok ( cx) ;
1588
+ } ,
1589
+ ty:: Char => {
1590
+ p!( write( "{:?}" , :: std:: char :: from_u32( bits as u32 ) . unwrap( ) ) ) ;
1591
+ return Ok ( cx) ;
1549
1592
}
1593
+ _ => { } ,
1550
1594
}
1551
- ( ConstValue :: Infer ( ..) , _) => p!( write( "_: " ) , print( self . ty) ) ,
1552
- ( ConstValue :: Param ( ParamConst { name, .. } ) , _) => p!( write( "{}" , name) ) ,
1553
- ( ConstValue :: Scalar ( Scalar :: Bits { bits: 0 , .. } ) , ty:: Bool ) => p!( write( "false" ) ) ,
1554
- ( ConstValue :: Scalar ( Scalar :: Bits { bits: 1 , .. } ) , ty:: Bool ) => p!( write( "true" ) ) ,
1555
- ( ConstValue :: Scalar ( Scalar :: Bits { bits, .. } ) , ty:: Float ( ast:: FloatTy :: F32 ) ) =>
1556
- p!( write(
1557
- "{}f32" ,
1558
- Single :: from_bits( bits)
1559
- ) ) ,
1560
- ( ConstValue :: Scalar ( Scalar :: Bits { bits, .. } ) , ty:: Float ( ast:: FloatTy :: F64 ) ) =>
1561
- p!( write(
1562
- "{}f64" ,
1563
- Double :: from_bits( bits)
1564
- ) ) ,
1565
- ( ConstValue :: Scalar ( Scalar :: Bits { bits, ..} ) , ty:: Uint ( ui) ) =>
1566
- p!( write( "{}{}" , bits, ui) ) ,
1567
- ( ConstValue :: Scalar ( Scalar :: Bits { bits, ..} ) , ty:: Int ( i) ) => {
1568
- let ty = cx. tcx( ) . lift_to_global( & self . ty) . unwrap( ) ;
1569
- let size = cx. tcx( ) . layout_of( ty:: ParamEnv :: empty( ) . and( ty) )
1570
- . unwrap( )
1571
- . size;
1572
- p!( write( "{}{}" , sign_extend( bits, size) as i128 , i) )
1573
- } ,
1574
- ( ConstValue :: Scalar ( Scalar :: Bits { bits, ..} ) , ty:: Char )
1575
- => p!( write( "{:?}" , :: std:: char :: from_u32( bits as u32 ) . unwrap( ) ) ) ,
1576
- ( _, ty:: FnDef ( did, _) ) => p!( write( "{}" , cx. tcx( ) . def_path_str( * did) ) ) ,
1577
- ( _, ty:: Ref ( _, ref_ty, _) ) => match ( self . val, & ref_ty. sty) {
1595
+ }
1596
+ if let ty:: Ref ( _, ref_ty, _) = self . ty. sty {
1597
+ let byte_str = match ( self . val, & ref_ty. sty) {
1578
1598
( ConstValue :: Scalar ( Scalar :: Ptr ( ptr) ) , ty:: Array ( t, n) ) if * t == u8 => {
1579
1599
let n = n. unwrap_usize( cx. tcx( ) ) ;
1580
- let slice = cx. tcx( )
1600
+ Some ( cx. tcx( )
1581
1601
. alloc_map. lock( )
1582
1602
. unwrap_memory( ptr. alloc_id)
1583
- . get_bytes( & cx. tcx( ) , ptr, Size :: from_bytes( n) ) . unwrap( ) ;
1584
- p!( write( "b\" " ) ) ;
1585
- for & c in slice {
1586
- for e in std:: ascii:: escape_default( c) {
1587
- p!( write( "{}" , e as char ) ) ;
1588
- }
1589
- }
1590
- p!( write( "\" " ) ) ;
1603
+ . get_bytes( & cx. tcx( ) , ptr, Size :: from_bytes( n) ) . unwrap( ) )
1604
+ } ,
1605
+ ( ConstValue :: Slice { data, start, end } , ty:: Slice ( t) ) if * t == u8 => {
1606
+ Some ( & data. bytes[ start..end] )
1591
1607
} ,
1592
1608
( ConstValue :: Slice { data, start, end } , ty:: Str ) => {
1593
1609
let slice = & data. bytes[ start..end] ;
1594
1610
let s = :: std:: str :: from_utf8( slice)
1595
1611
. expect( "non utf8 str from miri" ) ;
1596
- p!( write( "{:?}" , s) )
1612
+ p!( write( "{:?}" , s) ) ;
1613
+ return Ok ( cx) ;
1597
1614
} ,
1598
- ( ConstValue :: Slice { data , start , end } , ty :: Slice ( t ) ) if * t == u8 => {
1599
- let slice = & data . bytes [ start..end ] ;
1600
- p! ( write ( "b \" " ) ) ;
1601
- for & c in slice {
1602
- for e in std :: ascii :: escape_default ( c ) {
1603
- p! ( write ( "{}" , e as char ) ) ;
1604
- }
1615
+ _ => None ,
1616
+ } ;
1617
+ if let Some ( byte_str ) = byte_str {
1618
+ p! ( write ( "b \" " ) ) ;
1619
+ for & c in byte_str {
1620
+ for e in std :: ascii :: escape_default ( c ) {
1621
+ p! ( write ( "{}" , e as char ) ) ;
1605
1622
}
1606
- p!( write( "\" " ) ) ;
1607
- } ,
1608
- _ => p!( write( "{:?} : " , self . val) , print( self . ty) ) ,
1609
- } ,
1610
- _ => p!( write( "{:?} : " , self . val) , print( self . ty) ) ,
1623
+ }
1624
+ p!( write( "\" " ) ) ;
1625
+ return Ok ( cx) ;
1626
+ }
1611
1627
}
1628
+ p!( write( "{:?} : " , self . val) , print( self . ty) ) ;
1612
1629
}
1613
1630
1614
1631
ty:: ParamTy {
0 commit comments