@@ -24,10 +24,17 @@ use super::{
24
24
use crate :: fluent_generated as fluent;
25
25
26
26
/// 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
+ } ;
29
36
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 )
31
38
}
32
39
33
40
/// 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>(
43
50
interp_ok ( match name {
44
51
sym:: type_name => {
45
52
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 }
48
55
}
49
56
sym:: needs_drop => {
50
57
ensure_monomorphic_enough ( tcx, tp_ty) ?;
0 commit comments