@@ -7,7 +7,9 @@ use std::convert::TryFrom;
7
7
use rustc_hir:: def_id:: DefId ;
8
8
use rustc_middle:: mir:: {
9
9
self ,
10
- interpret:: { ConstValue , GlobalId , InterpResult , PointerArithmetic , Scalar } ,
10
+ interpret:: {
11
+ Allocation , ConstAllocation , ConstValue , GlobalId , InterpResult , PointerArithmetic , Scalar ,
12
+ } ,
11
13
BinOp , NonDivergingIntrinsic ,
12
14
} ;
13
15
use rustc_middle:: ty;
@@ -23,7 +25,6 @@ use super::{
23
25
} ;
24
26
25
27
mod caller_location;
26
- mod type_name;
27
28
28
29
fn numeric_intrinsic < Prov > ( name : Symbol , bits : u128 , kind : Primitive ) -> Scalar < Prov > {
29
30
let size = match kind {
@@ -42,6 +43,13 @@ fn numeric_intrinsic<Prov>(name: Symbol, bits: u128, kind: Primitive) -> Scalar<
42
43
Scalar :: from_uint ( bits_out, size)
43
44
}
44
45
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
+
45
53
/// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated
46
54
/// inside an `InterpCx` and instead have their value computed directly from rustc internal info.
47
55
pub ( crate ) fn eval_nullary_intrinsic < ' tcx > (
@@ -55,7 +63,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
55
63
Ok ( match name {
56
64
sym:: type_name => {
57
65
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) ;
59
67
ConstValue :: Slice { data : alloc, start : 0 , end : alloc. inner ( ) . len ( ) }
60
68
}
61
69
sym:: needs_drop => {
0 commit comments