@@ -574,6 +574,31 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
574
574
575
575
let start = self . out . len ( ) ;
576
576
577
+ let print_str = |this : & mut Self | {
578
+ let tcx = this. tcx ( ) ;
579
+ let ref_ty = if matches ! ( ct_ty. kind( ) , ty:: Str ) {
580
+ // HACK(jaic1): hide the `str` type behind a reference
581
+ // for the following transformation from valtree to raw bytes
582
+ Ty :: new_imm_ref ( tcx, tcx. lifetimes . re_static , ct_ty)
583
+ } else {
584
+ ct_ty
585
+ } ;
586
+ let slice = valtree. try_to_raw_bytes ( tcx, ref_ty) . unwrap_or_else ( || {
587
+ bug ! ( "expected to get raw bytes from valtree {:?} for type {:}" , valtree, ct_ty)
588
+ } ) ;
589
+ let s = std:: str:: from_utf8 ( slice) . expect ( "non utf8 str from MIR interpreter" ) ;
590
+
591
+ // "e" for str as a basic type
592
+ this. push ( "e" ) ;
593
+
594
+ // FIXME(eddyb) use a specialized hex-encoding loop.
595
+ for byte in s. bytes ( ) {
596
+ let _ = write ! ( this. out, "{byte:02x}" ) ;
597
+ }
598
+
599
+ this. push ( "_" ) ;
600
+ } ;
601
+
577
602
match ct_ty. kind ( ) {
578
603
ty:: Uint ( _) | ty:: Int ( _) | ty:: Bool | ty:: Char => {
579
604
ct_ty. print ( self ) ?;
@@ -593,6 +618,9 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
593
618
let _ = write ! ( self . out, "{bits:x}_" ) ;
594
619
}
595
620
621
+ // Handle `str` as partial support for unsized constants
622
+ ty:: Str => print_str ( self ) ,
623
+
596
624
// FIXME(valtrees): Remove the special case for `str`
597
625
// here and fully support unsized constants.
598
626
ty:: Ref ( _, inner_ty, mutbl) => {
@@ -602,26 +630,9 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
602
630
} ) ;
603
631
604
632
match inner_ty. kind ( ) {
605
- ty:: Str if mutbl. is_not ( ) => {
606
- let slice =
607
- valtree. try_to_raw_bytes ( self . tcx ( ) , ct_ty) . unwrap_or_else ( || {
608
- bug ! (
609
- "expected to get raw bytes from valtree {:?} for type {:}" ,
610
- valtree,
611
- ct_ty
612
- )
613
- } ) ;
614
- let s =
615
- std:: str:: from_utf8 ( slice) . expect ( "non utf8 str from MIR interpreter" ) ;
616
-
617
- self . push ( "e" ) ;
618
-
619
- // FIXME(eddyb) use a specialized hex-encoding loop.
620
- for byte in s. bytes ( ) {
621
- let _ = write ! ( self . out, "{byte:02x}" ) ;
622
- }
623
-
624
- self . push ( "_" ) ;
633
+ ty:: Str => {
634
+ assert ! ( mutbl. is_not( ) , "&mut str is not expected" ) ;
635
+ print_str ( self ) ;
625
636
}
626
637
_ => {
627
638
let pointee_ty = ct_ty
0 commit comments