diff options
| author | TankhouseAle <51239665+TankhouseAle@users.noreply.github.com> | 2019-06-03 14:40:08 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-03 14:40:08 -0400 |
| commit | e2843b792a605f8166515b9f8b9e47794101980d (patch) | |
| tree | aac55391a4f988c38f7ab8220a4f31c282b72717 | |
| parent | 99f66f4045d405e306b6459b6807372a88279875 (diff) | |
| download | rust-e2843b792a605f8166515b9f8b9e47794101980d.tar.gz rust-e2843b792a605f8166515b9f8b9e47794101980d.zip | |
Re-add type_name.rs changes
| -rw-r--r-- | src/librustc_mir/interpret/intrinsics/type_name.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/librustc_mir/interpret/intrinsics/type_name.rs b/src/librustc_mir/interpret/intrinsics/type_name.rs index 456fc70fc0d..1270b35ebb9 100644 --- a/src/librustc_mir/interpret/intrinsics/type_name.rs +++ b/src/librustc_mir/interpret/intrinsics/type_name.rs @@ -213,16 +213,23 @@ impl Write for AbsolutePathPrinter<'_, '_> { /// Produces an absolute path representation of the given type. See also the documentation on /// `std::any::type_name` pub fn type_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> { - let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path; - let len = path.len(); - let alloc = Allocation::from_byte_aligned_bytes(path.into_bytes()); - let alloc = tcx.intern_const_alloc(alloc); + let alloc = alloc_type_name(tcx, ty); tcx.mk_const(ty::Const { val: ConstValue::Slice { data: alloc, start: 0, - end: len, + end: alloc.bytes.len(), }, ty: tcx.mk_static_str(), }) } + +/// Directly returns an `Allocation` containing an absolute path representation of the given type. +pub(super) fn alloc_type_name<'a, 'tcx>( + tcx: TyCtxt<'a, 'tcx, 'tcx>, + ty: Ty<'tcx> +) -> &'tcx Allocation { + let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path; + let alloc = Allocation::from_byte_aligned_bytes(path.into_bytes()); + tcx.intern_const_alloc(alloc) +} |
