@@ -24,10 +24,17 @@ use super::{
2424use crate :: fluent_generated as fluent;
2525
2626/// Directly returns an `Allocation` containing an absolute path representation of the given type.
27- pub ( crate ) fn alloc_type_name < ' tcx > ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> ConstAllocation < ' tcx > {
28- let path = crate :: util:: type_name ( tcx, ty) ;
27+ pub ( crate ) fn alloc_type_name < ' tcx > (
28+ tcx : TyCtxt < ' tcx > ,
29+ ty : Ty < ' tcx > ,
30+ ) -> ( ConstAllocation < ' tcx > , u64 ) {
31+ let mut path = crate :: util:: type_name ( tcx, ty) ;
32+ let path_len = path. len ( ) . try_into ( ) . unwrap ( ) ;
33+ if !path. contains ( '\0' ) {
34+ path. push ( '\0' ) ;
35+ } ;
2936 let alloc = Allocation :: from_bytes_byte_aligned_immutable ( path. into_bytes ( ) ) ;
30- tcx. mk_const_alloc ( alloc)
37+ ( tcx. mk_const_alloc ( alloc) , path_len )
3138}
3239
3340/// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated
@@ -43,8 +50,8 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
4350 interp_ok ( match name {
4451 sym:: type_name => {
4552 ensure_monomorphic_enough ( tcx, tp_ty) ?;
46- let alloc = alloc_type_name ( tcx, tp_ty) ;
47- ConstValue :: Slice { data : alloc, meta : alloc . inner ( ) . size ( ) . bytes ( ) }
53+ let ( alloc, path_len ) = alloc_type_name ( tcx, tp_ty) ;
54+ ConstValue :: Slice { data : alloc, meta : path_len }
4855 }
4956 sym:: needs_drop => {
5057 ensure_monomorphic_enough ( tcx, tp_ty) ?;
0 commit comments