From 7996f63ce48490ea446499550c7e65a82930aae2 Mon Sep 17 00:00:00 2001 From: Maik Klein Date: Sun, 29 Oct 2017 22:37:38 +0100 Subject: [PATCH] Move meta_data into TyS --- src/librustc/ty/mod.rs | 14 ++++++++++++++ src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_trans/context.rs | 3 +-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 220e1e971acc..85f3d692bbeb 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2040,6 +2040,20 @@ impl<'tcx> TyS<'tcx> { } } } + + pub fn has_metadata<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> bool { + use syntax_pos::DUMMY_SP; + if self.is_sized(tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP) { + return false; + } + + let tail = tcx.struct_tail(self); + match tail.sty { + ty::TyForeign(..) => false, + ty::TyStr | ty::TySlice(..) | ty::TyDynamic(..) => true, + _ => bug!("unexpected unsized tail: {:?}", tail.sty), + } + } } #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index d6321c7577c9..35a82ae025bb 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -789,7 +789,7 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, target_ty: Ty<'tcx>) -> (Ty<'tcx>, Ty<'tcx>) { let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| { - if type_has_metadata(tcx, inner_source) { + if inner_source.has_metadata(tcx) { (inner_source, inner_target) } else { tcx.struct_lockstep_tails(inner_source, inner_target) diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 77fdf0ee691e..f04381aa212b 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -34,7 +34,6 @@ use rustc::session::Session; use rustc::ty::layout::{LayoutError, LayoutOf, Size, TyLayout}; use rustc::ty::{self, Ty, TyCtxt}; use rustc::util::nodemap::FxHashMap; -use rustc_trans_utils; use std::ffi::{CStr, CString}; use std::cell::{Cell, RefCell}; @@ -325,7 +324,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> { } pub fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool { - rustc_trans_utils::common::type_has_metadata(self.tcx, ty) + ty.has_metadata(self.tcx) } pub fn tcx(&self) -> TyCtxt<'b, 'tcx, 'tcx> {