Skip to content

Commit 7996f63

Browse files
MaikKleinarielb1
authored andcommitted
Move meta_data into TyS
1 parent dfbb6e8 commit 7996f63

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/librustc/ty/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,20 @@ impl<'tcx> TyS<'tcx> {
20402040
}
20412041
}
20422042
}
2043+
2044+
pub fn has_metadata<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> bool {
2045+
use syntax_pos::DUMMY_SP;
2046+
if self.is_sized(tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP) {
2047+
return false;
2048+
}
2049+
2050+
let tail = tcx.struct_tail(self);
2051+
match tail.sty {
2052+
ty::TyForeign(..) => false,
2053+
ty::TyStr | ty::TySlice(..) | ty::TyDynamic(..) => true,
2054+
_ => bug!("unexpected unsized tail: {:?}", tail.sty),
2055+
}
2056+
}
20432057
}
20442058

20452059
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

src/librustc_mir/monomorphize/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
789789
target_ty: Ty<'tcx>)
790790
-> (Ty<'tcx>, Ty<'tcx>) {
791791
let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| {
792-
if type_has_metadata(tcx, inner_source) {
792+
if inner_source.has_metadata(tcx) {
793793
(inner_source, inner_target)
794794
} else {
795795
tcx.struct_lockstep_tails(inner_source, inner_target)

src/librustc_trans/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use rustc::session::Session;
3434
use rustc::ty::layout::{LayoutError, LayoutOf, Size, TyLayout};
3535
use rustc::ty::{self, Ty, TyCtxt};
3636
use rustc::util::nodemap::FxHashMap;
37-
use rustc_trans_utils;
3837

3938
use std::ffi::{CStr, CString};
4039
use std::cell::{Cell, RefCell};
@@ -325,7 +324,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
325324
}
326325

327326
pub fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
328-
rustc_trans_utils::common::type_has_metadata(self.tcx, ty)
327+
ty.has_metadata(self.tcx)
329328
}
330329

331330
pub fn tcx(&self) -> TyCtxt<'b, 'tcx, 'tcx> {

0 commit comments

Comments
 (0)