@@ -574,31 +574,6 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
574574
575575 let start = self . out . len ( ) ;
576576
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-
602577 match ct_ty. kind ( ) {
603578 ty:: Uint ( _) | ty:: Int ( _) | ty:: Bool | ty:: Char => {
604579 ct_ty. print ( self ) ?;
@@ -619,30 +594,43 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
619594 }
620595
621596 // Handle `str` as partial support for unsized constants
622- ty:: Str => print_str ( self ) ,
597+ ty:: Str => {
598+ let tcx = self . tcx ( ) ;
599+ let ref_ty = if matches ! ( ct_ty. kind( ) , ty:: Str ) {
600+ // HACK(jaic1): hide the `str` type behind a reference
601+ // for the following transformation from valtree to raw bytes
602+ Ty :: new_imm_ref ( tcx, tcx. lifetimes . re_static , ct_ty)
603+ } else {
604+ ct_ty
605+ } ;
606+ let slice = valtree. try_to_raw_bytes ( tcx, ref_ty) . unwrap_or_else ( || {
607+ bug ! ( "expected to get raw bytes from valtree {:?} for type {:}" , valtree, ct_ty)
608+ } ) ;
609+ let s = std:: str:: from_utf8 ( slice) . expect ( "non utf8 str from MIR interpreter" ) ;
610+
611+ // "e" for str as a basic type
612+ self . push ( "e" ) ;
613+
614+ // FIXME(eddyb) use a specialized hex-encoding loop.
615+ for byte in s. bytes ( ) {
616+ let _ = write ! ( self . out, "{byte:02x}" ) ;
617+ }
618+
619+ self . push ( "_" ) ;
620+ }
623621
624622 // FIXME(valtrees): Remove the special case for `str`
625623 // here and fully support unsized constants.
626- ty:: Ref ( _, inner_ty , mutbl) => {
624+ ty:: Ref ( _, _ , mutbl) => {
627625 self . push ( match mutbl {
628626 hir:: Mutability :: Not => "R" ,
629627 hir:: Mutability :: Mut => "Q" ,
630628 } ) ;
631629
632- match inner_ty. kind ( ) {
633- ty:: Str => {
634- assert ! ( mutbl. is_not( ) , "&mut str is not expected" ) ;
635- print_str ( self ) ;
636- }
637- _ => {
638- let pointee_ty = ct_ty
639- . builtin_deref ( true )
640- . expect ( "tried to dereference on non-ptr type" ) ;
641- let dereferenced_const =
642- ty:: Const :: new_value ( self . tcx , valtree, pointee_ty) ;
643- dereferenced_const. print ( self ) ?;
644- }
645- }
630+ let pointee_ty =
631+ ct_ty. builtin_deref ( true ) . expect ( "tried to dereference on non-ptr type" ) ;
632+ let dereferenced_const = ty:: Const :: new_value ( self . tcx , valtree, pointee_ty) ;
633+ dereferenced_const. print ( self ) ?;
646634 }
647635
648636 ty:: Array ( ..) | ty:: Tuple ( ..) | ty:: Adt ( ..) | ty:: Slice ( _) => {
0 commit comments