about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaik Klein <maikklein@googlemail.com>2017-10-29 22:37:38 +0100
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2017-12-18 17:08:49 +0200
commit7996f63ce48490ea446499550c7e65a82930aae2 (patch)
treef9edd5e6cb9b65d0c00ec8e1647f3cdc20b59e98
parentdfbb6e864091740608fb551fef7eabbd7567351c (diff)
downloadrust-7996f63ce48490ea446499550c7e65a82930aae2.tar.gz
rust-7996f63ce48490ea446499550c7e65a82930aae2.zip
Move meta_data into TyS
-rw-r--r--src/librustc/ty/mod.rs14
-rw-r--r--src/librustc_mir/monomorphize/collector.rs2
-rw-r--r--src/librustc_trans/context.rs3
3 files changed, 16 insertions, 3 deletions
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 220e1e971ac..85f3d692bbe 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 d6321c7577c..35a82ae025b 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 77fdf0ee691..f04381aa212 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> {