Move meta_data into TyS

This commit is contained in:
Maik Klein 2017-10-29 22:37:38 +01:00 committed by Ariel Ben-Yehuda
parent dfbb6e8640
commit 7996f63ce4
3 changed files with 16 additions and 3 deletions

View file

@ -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)]

View file

@ -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)

View file

@ -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> {