@@ -607,45 +607,40 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
607607 let _ = write ! ( self . out, "{bits:x}_" ) ;
608608 }
609609
610+ // Handle `str` as partial support for unsized constants
611+ ty:: Str => {
612+ let tcx = self . tcx ( ) ;
613+ // HACK(jaic1): hide the `str` type behind a reference
614+ // for the following transformation from valtree to raw bytes
615+ let ref_ty = Ty :: new_imm_ref ( tcx, tcx. lifetimes . re_static , ct_ty) ;
616+ let slice = valtree. try_to_raw_bytes ( tcx, ref_ty) . unwrap_or_else ( || {
617+ bug ! ( "expected to get raw bytes from valtree {:?} for type {:}" , valtree, ct_ty)
618+ } ) ;
619+ let s = std:: str:: from_utf8 ( slice) . expect ( "non utf8 str from MIR interpreter" ) ;
620+
621+ // "e" for str as a basic type
622+ self . push ( "e" ) ;
623+
624+ // FIXME(eddyb) use a specialized hex-encoding loop.
625+ for byte in s. bytes ( ) {
626+ let _ = write ! ( self . out, "{byte:02x}" ) ;
627+ }
628+
629+ self . push ( "_" ) ;
630+ }
631+
610632 // FIXME(valtrees): Remove the special case for `str`
611633 // here and fully support unsized constants.
612- ty:: Ref ( _, inner_ty , mutbl) => {
634+ ty:: Ref ( _, _ , mutbl) => {
613635 self . push ( match mutbl {
614636 hir:: Mutability :: Not => "R" ,
615637 hir:: Mutability :: Mut => "Q" ,
616638 } ) ;
617639
618- match inner_ty. kind ( ) {
619- ty:: Str if mutbl. is_not ( ) => {
620- let slice =
621- valtree. try_to_raw_bytes ( self . tcx ( ) , ct_ty) . unwrap_or_else ( || {
622- bug ! (
623- "expected to get raw bytes from valtree {:?} for type {:}" ,
624- valtree,
625- ct_ty
626- )
627- } ) ;
628- let s =
629- std:: str:: from_utf8 ( slice) . expect ( "non utf8 str from MIR interpreter" ) ;
630-
631- self . push ( "e" ) ;
632-
633- // FIXME(eddyb) use a specialized hex-encoding loop.
634- for byte in s. bytes ( ) {
635- let _ = write ! ( self . out, "{byte:02x}" ) ;
636- }
637-
638- self . push ( "_" ) ;
639- }
640- _ => {
641- let pointee_ty = ct_ty
642- . builtin_deref ( true )
643- . expect ( "tried to dereference on non-ptr type" ) ;
644- let dereferenced_const =
645- ty:: Const :: new_value ( self . tcx , valtree, pointee_ty) ;
646- dereferenced_const. print ( self ) ?;
647- }
648- }
640+ let pointee_ty =
641+ ct_ty. builtin_deref ( true ) . expect ( "tried to dereference on non-ptr type" ) ;
642+ let dereferenced_const = ty:: Const :: new_value ( self . tcx , valtree, pointee_ty) ;
643+ dereferenced_const. print ( self ) ?;
649644 }
650645
651646 ty:: Array ( ..) | ty:: Tuple ( ..) | ty:: Adt ( ..) | ty:: Slice ( _) => {
0 commit comments