@@ -7,7 +7,9 @@ use std::convert::TryFrom;
77use rustc_hir:: def_id:: DefId ;
88use rustc_middle:: mir:: {
99 self ,
10- interpret:: { ConstValue , GlobalId , InterpResult , PointerArithmetic , Scalar } ,
10+ interpret:: {
11+ Allocation , ConstAllocation , ConstValue , GlobalId , InterpResult , PointerArithmetic , Scalar ,
12+ } ,
1113 BinOp , NonDivergingIntrinsic ,
1214} ;
1315use rustc_middle:: ty;
@@ -23,7 +25,6 @@ use super::{
2325} ;
2426
2527mod caller_location;
26- mod type_name;
2728
2829fn numeric_intrinsic < Prov > ( name : Symbol , bits : u128 , kind : Primitive ) -> Scalar < Prov > {
2930 let size = match kind {
@@ -42,6 +43,13 @@ fn numeric_intrinsic<Prov>(name: Symbol, bits: u128, kind: Primitive) -> Scalar<
4243 Scalar :: from_uint ( bits_out, size)
4344}
4445
46+ /// Directly returns an `Allocation` containing an absolute path representation of the given type.
47+ pub ( crate ) fn alloc_type_name < ' tcx > ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> ConstAllocation < ' tcx > {
48+ let path = crate :: util:: type_name ( tcx, ty) ;
49+ let alloc = Allocation :: from_bytes_byte_aligned_immutable ( path. into_bytes ( ) ) ;
50+ tcx. intern_const_alloc ( alloc)
51+ }
52+
4553/// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated
4654/// inside an `InterpCx` and instead have their value computed directly from rustc internal info.
4755pub ( crate ) fn eval_nullary_intrinsic < ' tcx > (
@@ -55,7 +63,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
5563 Ok ( match name {
5664 sym:: type_name => {
5765 ensure_monomorphic_enough ( tcx, tp_ty) ?;
58- let alloc = type_name :: alloc_type_name ( tcx, tp_ty) ;
66+ let alloc = alloc_type_name ( tcx, tp_ty) ;
5967 ConstValue :: Slice { data : alloc, start : 0 , end : alloc. inner ( ) . len ( ) }
6068 }
6169 sym:: needs_drop => {
0 commit comments