Remove adt_def from PlaceTy and make it a struct
This commit is contained in:
parent
ac29ca75e0
commit
4122d2221e
@ -4,21 +4,17 @@
|
||||
*/
|
||||
|
||||
use crate::mir::*;
|
||||
use crate::ty::subst::{Subst, SubstsRef};
|
||||
use crate::ty::{self, AdtDef, Ty, TyCtxt};
|
||||
use crate::ty::subst::Subst;
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use crate::ty::layout::VariantIdx;
|
||||
use crate::hir;
|
||||
use crate::ty::util::IntTypeExt;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum PlaceTy<'tcx> {
|
||||
/// Normal type.
|
||||
Ty { ty: Ty<'tcx> },
|
||||
|
||||
/// Downcast to a particular variant of an enum.
|
||||
Downcast { adt_def: &'tcx AdtDef,
|
||||
substs: SubstsRef<'tcx>,
|
||||
variant_index: VariantIdx },
|
||||
pub struct PlaceTy<'tcx> {
|
||||
pub ty: Ty<'tcx>,
|
||||
/// Downcast to a particular variant of an enum, if included.
|
||||
pub variant_index: Option<VariantIdx>,
|
||||
}
|
||||
|
||||
static_assert!(PLACE_TY_IS_3_PTRS_LARGE:
|
||||
@ -27,16 +23,7 @@ pub enum PlaceTy<'tcx> {
|
||||
|
||||
impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
|
||||
pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> {
|
||||
PlaceTy::Ty { ty }
|
||||
}
|
||||
|
||||
pub fn to_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
match *self {
|
||||
PlaceTy::Ty { ty } =>
|
||||
ty,
|
||||
PlaceTy::Downcast { adt_def, substs, variant_index: _ } =>
|
||||
tcx.mk_adt(adt_def, substs),
|
||||
}
|
||||
PlaceTy { ty, variant_index: None }
|
||||
}
|
||||
|
||||
/// `place_ty.field_ty(tcx, f)` computes the type at a given field
|
||||
@ -48,21 +35,20 @@ pub fn to_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||
/// Note that the resulting type has not been normalized.
|
||||
pub fn field_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, f: &Field) -> Ty<'tcx>
|
||||
{
|
||||
// Pass `0` here so it can be used as a "default" variant_index in first arm below
|
||||
let answer = match (self, VariantIdx::new(0)) {
|
||||
(PlaceTy::Ty {
|
||||
ty: &ty::TyS { sty: ty::TyKind::Adt(adt_def, substs), .. } }, variant_index) |
|
||||
(PlaceTy::Downcast { adt_def, substs, variant_index }, _) => {
|
||||
let variant_def = &adt_def.variants[variant_index];
|
||||
let answer = match self.ty.sty {
|
||||
ty::TyKind::Adt(adt_def, substs) => {
|
||||
let variant_def = match self.variant_index {
|
||||
None => adt_def.non_enum_variant(),
|
||||
Some(variant_index) => {
|
||||
assert!(adt_def.is_enum());
|
||||
&adt_def.variants[variant_index]
|
||||
}
|
||||
};
|
||||
let field_def = &variant_def.fields[f.index()];
|
||||
field_def.ty(tcx, substs)
|
||||
}
|
||||
(PlaceTy::Ty { ty }, _) => {
|
||||
match ty.sty {
|
||||
ty::Tuple(ref tys) => tys[f.index()],
|
||||
_ => bug!("extracting field of non-tuple non-adt: {:?}", self),
|
||||
}
|
||||
}
|
||||
ty::Tuple(ref tys) => tys[f.index()],
|
||||
_ => bug!("extracting field of non-tuple non-adt: {:?}", self),
|
||||
};
|
||||
debug!("field_ty self: {:?} f: {:?} yields: {:?}", self, f, answer);
|
||||
answer
|
||||
@ -94,61 +80,43 @@ pub fn projection_ty_core<V, T>(
|
||||
{
|
||||
let answer = match *elem {
|
||||
ProjectionElem::Deref => {
|
||||
let ty = self.to_ty(tcx)
|
||||
let ty = self.ty
|
||||
.builtin_deref(true)
|
||||
.unwrap_or_else(|| {
|
||||
bug!("deref projection of non-dereferencable ty {:?}", self)
|
||||
})
|
||||
.ty;
|
||||
PlaceTy::Ty {
|
||||
ty,
|
||||
}
|
||||
PlaceTy::from_ty(ty)
|
||||
}
|
||||
ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } =>
|
||||
PlaceTy::Ty {
|
||||
ty: self.to_ty(tcx).builtin_index().unwrap()
|
||||
},
|
||||
PlaceTy::from_ty(self.ty.builtin_index().unwrap()),
|
||||
ProjectionElem::Subslice { from, to } => {
|
||||
let ty = self.to_ty(tcx);
|
||||
PlaceTy::Ty {
|
||||
ty: match ty.sty {
|
||||
ty::Array(inner, size) => {
|
||||
let size = size.unwrap_usize(tcx);
|
||||
let len = size - (from as u64) - (to as u64);
|
||||
tcx.mk_array(inner, len)
|
||||
}
|
||||
ty::Slice(..) => ty,
|
||||
_ => {
|
||||
bug!("cannot subslice non-array type: `{:?}`", self)
|
||||
}
|
||||
PlaceTy::from_ty(match self.ty.sty {
|
||||
ty::Array(inner, size) => {
|
||||
let size = size.unwrap_usize(tcx);
|
||||
let len = size - (from as u64) - (to as u64);
|
||||
tcx.mk_array(inner, len)
|
||||
}
|
||||
}
|
||||
ty::Slice(..) => self.ty,
|
||||
_ => {
|
||||
bug!("cannot subslice non-array type: `{:?}`", self)
|
||||
}
|
||||
})
|
||||
}
|
||||
ProjectionElem::Downcast(_name, index) =>
|
||||
match self.to_ty(tcx).sty {
|
||||
ty::Adt(adt_def, substs) => {
|
||||
assert!(adt_def.is_enum());
|
||||
assert!(index.as_usize() < adt_def.variants.len());
|
||||
PlaceTy::Downcast { adt_def,
|
||||
substs,
|
||||
variant_index: index }
|
||||
}
|
||||
_ => {
|
||||
bug!("cannot downcast non-ADT type: `{:?}`", self)
|
||||
}
|
||||
},
|
||||
PlaceTy { ty: self.ty, variant_index: Some(index) },
|
||||
ProjectionElem::Field(ref f, ref fty) =>
|
||||
PlaceTy::Ty { ty: handle_field(&self, f, fty) },
|
||||
PlaceTy::from_ty(handle_field(&self, f, fty)),
|
||||
};
|
||||
debug!("projection_ty self: {:?} elem: {:?} yields: {:?}", self, elem, answer);
|
||||
answer
|
||||
}
|
||||
}
|
||||
|
||||
EnumTypeFoldableImpl! {
|
||||
BraceStructTypeFoldableImpl! {
|
||||
impl<'tcx> TypeFoldable<'tcx> for PlaceTy<'tcx> {
|
||||
(PlaceTy::Ty) { ty },
|
||||
(PlaceTy::Downcast) { adt_def, substs, variant_index },
|
||||
ty,
|
||||
variant_index,
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,9 +126,9 @@ pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> P
|
||||
{
|
||||
match *self {
|
||||
Place::Base(PlaceBase::Local(index)) =>
|
||||
PlaceTy::Ty { ty: local_decls.local_decls()[index].ty },
|
||||
PlaceTy::from_ty(local_decls.local_decls()[index].ty),
|
||||
Place::Base(PlaceBase::Static(ref data)) =>
|
||||
PlaceTy::Ty { ty: data.ty },
|
||||
PlaceTy::from_ty(data.ty),
|
||||
Place::Projection(ref proj) =>
|
||||
proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem),
|
||||
}
|
||||
@ -185,7 +153,7 @@ pub fn is_upvar_field_projection<'cx, 'gcx>(&self, mir: &'cx Mir<'tcx>,
|
||||
match place {
|
||||
Place::Projection(ref proj) => match proj.elem {
|
||||
ProjectionElem::Field(field, _ty) => {
|
||||
let base_ty = proj.base.ty(mir, *tcx).to_ty(*tcx);
|
||||
let base_ty = proj.base.ty(mir, *tcx).ty;
|
||||
|
||||
if (base_ty.is_closure() || base_ty.is_generator()) &&
|
||||
(!by_ref || mir.upvar_decls[field.index()].by_ref)
|
||||
@ -217,7 +185,7 @@ pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> T
|
||||
tcx.mk_array(operand.ty(local_decls, tcx), count)
|
||||
}
|
||||
Rvalue::Ref(reg, bk, ref place) => {
|
||||
let place_ty = place.ty(local_decls, tcx).to_ty(tcx);
|
||||
let place_ty = place.ty(local_decls, tcx).ty;
|
||||
tcx.mk_ref(reg,
|
||||
ty::TypeAndMut {
|
||||
ty: place_ty,
|
||||
@ -243,7 +211,7 @@ pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> T
|
||||
operand.ty(local_decls, tcx)
|
||||
}
|
||||
Rvalue::Discriminant(ref place) => {
|
||||
let ty = place.ty(local_decls, tcx).to_ty(tcx);
|
||||
let ty = place.ty(local_decls, tcx).ty;
|
||||
if let ty::Adt(adt_def, _) = ty.sty {
|
||||
adt_def.repr.discr_type().to_ty(tcx)
|
||||
} else {
|
||||
@ -292,7 +260,7 @@ pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> T
|
||||
{
|
||||
match self {
|
||||
&Operand::Copy(ref l) |
|
||||
&Operand::Move(ref l) => l.ty(local_decls, tcx).to_ty(tcx),
|
||||
&Operand::Move(ref l) => l.ty(local_decls, tcx).ty,
|
||||
&Operand::Constant(ref c) => c.ty,
|
||||
}
|
||||
}
|
||||
|
@ -172,14 +172,14 @@ fn visit_place(&mut self,
|
||||
// ZSTs don't require any actual memory access.
|
||||
let elem_ty = base_ty
|
||||
.projection_ty(cx.tcx(), &proj.elem)
|
||||
.to_ty(cx.tcx());
|
||||
.ty;
|
||||
let elem_ty = self.fx.monomorphize(&elem_ty);
|
||||
if cx.layout_of(elem_ty).is_zst() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let mir::ProjectionElem::Field(..) = proj.elem {
|
||||
let layout = cx.layout_of(base_ty.to_ty(cx.tcx()));
|
||||
let layout = cx.layout_of(base_ty.ty);
|
||||
if cx.is_backend_immediate(layout) || cx.is_backend_scalar_pair(layout) {
|
||||
// Recurse with the same context, instead of `Projection`,
|
||||
// potentially stopping at non-operand projections,
|
||||
@ -247,7 +247,7 @@ fn visit_local(&mut self,
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Drop) => {
|
||||
let ty = mir::Place::Base(mir::PlaceBase::Local(local)).ty(self.fx.mir,
|
||||
self.fx.cx.tcx());
|
||||
let ty = self.fx.monomorphize(&ty.to_ty(self.fx.cx.tcx()));
|
||||
let ty = self.fx.monomorphize(&ty.ty);
|
||||
|
||||
// Only need the place if we're actually dropping it.
|
||||
if self.fx.cx.type_needs_drop(ty) {
|
||||
|
@ -301,7 +301,7 @@ fn codegen_drop_terminator<'b>(
|
||||
target: mir::BasicBlock,
|
||||
unwind: Option<mir::BasicBlock>,
|
||||
) {
|
||||
let ty = location.ty(self.mir, bx.tcx()).to_ty(bx.tcx());
|
||||
let ty = location.ty(self.mir, bx.tcx()).ty;
|
||||
let ty = self.monomorphize(&ty);
|
||||
let drop_fn = monomorphize::resolve_drop_in_place(bx.tcx(), ty);
|
||||
|
||||
|
@ -494,8 +494,8 @@ pub fn codegen_place(
|
||||
mir::ProjectionElem::Subslice { from, to } => {
|
||||
let mut subslice = cg_base.project_index(bx,
|
||||
bx.cx().const_usize(from as u64));
|
||||
let projected_ty = PlaceTy::Ty { ty: cg_base.layout.ty }
|
||||
.projection_ty(tcx, &projection.elem).to_ty(tcx);
|
||||
let projected_ty = PlaceTy::from_ty(cg_base.layout.ty)
|
||||
.projection_ty(tcx, &projection.elem).ty;
|
||||
subslice.layout = bx.cx().layout_of(self.monomorphize(&projected_ty));
|
||||
|
||||
if subslice.layout.is_unsized() {
|
||||
@ -523,6 +523,6 @@ pub fn codegen_place(
|
||||
pub fn monomorphized_place_ty(&self, place: &mir::Place<'tcx>) -> Ty<'tcx> {
|
||||
let tcx = self.cx.tcx();
|
||||
let place_ty = place.ty(self.mir, tcx);
|
||||
self.monomorphize(&place_ty.to_ty(tcx))
|
||||
self.monomorphize(&place_ty.ty)
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ pub(super) fn report_use_of_moved_or_uninitialized(
|
||||
);
|
||||
}
|
||||
|
||||
let ty = used_place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
|
||||
let ty = used_place.ty(self.mir, self.infcx.tcx).ty;
|
||||
let needs_note = match ty.sty {
|
||||
ty::Closure(id, _) => {
|
||||
let tables = self.infcx.tcx.typeck_tables_of(id);
|
||||
@ -217,7 +217,7 @@ pub(super) fn report_use_of_moved_or_uninitialized(
|
||||
let mpi = self.move_data.moves[move_out_indices[0]].path;
|
||||
let place = &self.move_data.move_paths[mpi].place;
|
||||
|
||||
let ty = place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
|
||||
let ty = place.ty(self.mir, self.infcx.tcx).ty;
|
||||
let opt_name = self.describe_place_with_options(place, IncludingDowncast(true));
|
||||
let note_msg = match opt_name {
|
||||
Some(ref name) => format!("`{}`", name),
|
||||
@ -601,8 +601,7 @@ pub(super) fn describe_place_for_conflicting_borrow(
|
||||
// Define a small closure that we can use to check if the type of a place
|
||||
// is a union.
|
||||
let is_union = |place: &Place<'tcx>| -> bool {
|
||||
place.ty(self.mir, self.infcx.tcx)
|
||||
.to_ty(self.infcx.tcx)
|
||||
place.ty(self.mir, self.infcx.tcx).ty
|
||||
.ty_adt_def()
|
||||
.map(|adt| adt.is_union())
|
||||
.unwrap_or(false)
|
||||
@ -651,7 +650,7 @@ pub(super) fn describe_place_for_conflicting_borrow(
|
||||
|
||||
// Also compute the name of the union type, eg. `Foo` so we
|
||||
// can add a helpful note with it.
|
||||
let ty = base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
|
||||
let ty = base.ty(self.mir, self.infcx.tcx).ty;
|
||||
|
||||
return Some((desc_base, desc_first, desc_second, ty.to_string()));
|
||||
},
|
||||
@ -1777,7 +1776,7 @@ fn describe_field(&self, base: &Place<'tcx>, field: Field) -> String {
|
||||
Place::Projection(ref proj) => match proj.elem {
|
||||
ProjectionElem::Deref => self.describe_field(&proj.base, field),
|
||||
ProjectionElem::Downcast(_, variant_index) => {
|
||||
let base_ty = base.ty(self.mir, self.infcx.tcx).to_ty();
|
||||
let base_ty = base.ty(self.mir, self.infcx.tcx).ty;
|
||||
self.describe_field_from_ty(&base_ty, field, Some(variant_index))
|
||||
}
|
||||
ProjectionElem::Field(_, field_type) => {
|
||||
@ -1878,7 +1877,7 @@ fn classify_drop_access_kind(&self, place: &Place<'tcx>) -> StorageDeadOrDrop<'t
|
||||
StorageDeadOrDrop::LocalStorageDead
|
||||
| StorageDeadOrDrop::BoxedStorageDead => {
|
||||
assert!(
|
||||
base.ty(self.mir, tcx).to_ty(tcx).is_box(),
|
||||
base.ty(self.mir, tcx).ty.is_box(),
|
||||
"Drop of value behind a reference or raw pointer"
|
||||
);
|
||||
StorageDeadOrDrop::BoxedStorageDead
|
||||
@ -1886,7 +1885,7 @@ fn classify_drop_access_kind(&self, place: &Place<'tcx>) -> StorageDeadOrDrop<'t
|
||||
StorageDeadOrDrop::Destructor(_) => base_access,
|
||||
},
|
||||
ProjectionElem::Field(..) | ProjectionElem::Downcast(..) => {
|
||||
let base_ty = base.ty(self.mir, tcx).to_ty(tcx);
|
||||
let base_ty = base.ty(self.mir, tcx).ty;
|
||||
match base_ty.sty {
|
||||
ty::Adt(def, _) if def.has_dtor(tcx) => {
|
||||
// Report the outermost adt with a destructor
|
||||
|
@ -616,8 +616,7 @@ fn visit_terminator_entry(
|
||||
let drop_place_ty = drop_place.ty(self.mir, self.infcx.tcx);
|
||||
|
||||
// Erase the regions.
|
||||
let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty)
|
||||
.to_ty(self.infcx.tcx);
|
||||
let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty;
|
||||
|
||||
// "Lift" into the gcx -- once regions are erased, this type should be in the
|
||||
// global arenas; this "lift" operation basically just asserts that is true, but
|
||||
@ -1641,7 +1640,7 @@ fn check_if_assigned_path_is_moved(
|
||||
// assigning to `P.f` requires `P` itself
|
||||
// be already initialized
|
||||
let tcx = self.infcx.tcx;
|
||||
match base.ty(self.mir, tcx).to_ty(tcx).sty {
|
||||
match base.ty(self.mir, tcx).ty.sty {
|
||||
ty::Adt(def, _) if def.has_dtor(tcx) => {
|
||||
self.check_if_path_or_subpath_is_moved(
|
||||
context, InitializationRequiringAction::Assignment,
|
||||
@ -1746,7 +1745,7 @@ fn check_parent_of_field<'cx, 'gcx, 'tcx>(
|
||||
// no move out from an earlier location) then this is an attempt at initialization
|
||||
// of the union - we should error in that case.
|
||||
let tcx = this.infcx.tcx;
|
||||
if let ty::TyKind::Adt(def, _) = base.ty(this.mir, tcx).to_ty(tcx).sty {
|
||||
if let ty::TyKind::Adt(def, _) = base.ty(this.mir, tcx).ty.sty {
|
||||
if def.is_union() {
|
||||
if this.move_data.path_map[mpi].iter().any(|moi| {
|
||||
this.move_data.moves[*moi].source.is_predecessor_of(
|
||||
@ -2007,7 +2006,7 @@ fn is_mutable<'d>(
|
||||
Place::Projection(ref proj) => {
|
||||
match proj.elem {
|
||||
ProjectionElem::Deref => {
|
||||
let base_ty = proj.base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
|
||||
let base_ty = proj.base.ty(self.mir, self.infcx.tcx).ty;
|
||||
|
||||
// Check the kind of deref to decide
|
||||
match base_ty.sty {
|
||||
|
@ -266,7 +266,7 @@ fn report(&mut self, error: GroupedMoveError<'tcx>) {
|
||||
// Inspect the type of the content behind the
|
||||
// borrow to provide feedback about why this
|
||||
// was a move rather than a copy.
|
||||
let ty = place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
|
||||
let ty = place.ty(self.mir, self.infcx.tcx).ty;
|
||||
let is_upvar_field_projection =
|
||||
self.prefixes(&original_path, PrefixSet::All)
|
||||
.any(|p| p.is_upvar_field_projection(self.mir, &self.infcx.tcx)
|
||||
@ -530,7 +530,7 @@ fn borrowed_content_source(&self, place: &Place<'tcx>) -> BorrowedContentSource
|
||||
// We're only interested in assignments (in particular, where the
|
||||
// assignment came from - was it an `Rc` or `Arc`?).
|
||||
if let StatementKind::Assign(_, box Rvalue::Ref(_, _, source)) = &stmt.kind {
|
||||
let ty = source.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
|
||||
let ty = source.ty(self.mir, self.infcx.tcx).ty;
|
||||
let ty = match ty.sty {
|
||||
ty::TyKind::Ref(_, ty, _) => ty,
|
||||
_ => ty,
|
||||
@ -555,7 +555,7 @@ fn borrowed_content_source(&self, place: &Place<'tcx>) -> BorrowedContentSource
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
let ty = source.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
|
||||
let ty = source.ty(self.mir, self.infcx.tcx).ty;
|
||||
let ty = match ty.sty {
|
||||
ty::TyKind::Ref(_, ty, _) => ty,
|
||||
_ => ty,
|
||||
@ -581,7 +581,7 @@ fn borrowed_content_source(&self, place: &Place<'tcx>) -> BorrowedContentSource
|
||||
base,
|
||||
elem: ProjectionElem::Deref,
|
||||
}) = place {
|
||||
if base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx).is_unsafe_ptr() {
|
||||
if base.ty(self.mir, self.infcx.tcx).ty.is_unsafe_ptr() {
|
||||
return BorrowedContentSource::DerefRawPointer;
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ pub(super) fn report_mutability_error(
|
||||
elem: ProjectionElem::Field(upvar_index, _),
|
||||
}) => {
|
||||
debug_assert!(is_closure_or_generator(
|
||||
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx)
|
||||
base.ty(self.mir, self.infcx.tcx).ty
|
||||
));
|
||||
|
||||
item_msg = format!("`{}`", access_place_desc.unwrap());
|
||||
@ -85,7 +85,7 @@ pub(super) fn report_mutability_error(
|
||||
item_msg = format!("`{}`", access_place_desc.unwrap());
|
||||
debug_assert!(self.mir.local_decls[Local::new(1)].ty.is_region_ptr());
|
||||
debug_assert!(is_closure_or_generator(
|
||||
the_place_err.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx)
|
||||
the_place_err.ty(self.mir, self.infcx.tcx).ty
|
||||
));
|
||||
|
||||
reason = if access_place.is_upvar_field_projection(self.mir,
|
||||
@ -110,7 +110,7 @@ pub(super) fn report_mutability_error(
|
||||
reason = ", as it is immutable for the pattern guard".to_string();
|
||||
} else {
|
||||
let pointer_type =
|
||||
if base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx).is_region_ptr() {
|
||||
if base.ty(self.mir, self.infcx.tcx).ty.is_region_ptr() {
|
||||
"`&` reference"
|
||||
} else {
|
||||
"`*const` pointer"
|
||||
@ -232,7 +232,7 @@ pub(super) fn report_mutability_error(
|
||||
|
||||
if let Some((span, message)) = annotate_struct_field(
|
||||
self.infcx.tcx,
|
||||
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx),
|
||||
base.ty(self.mir, self.infcx.tcx).ty,
|
||||
field,
|
||||
) {
|
||||
err.span_suggestion(
|
||||
@ -304,7 +304,7 @@ pub(super) fn report_mutability_error(
|
||||
elem: ProjectionElem::Field(upvar_index, _),
|
||||
}) => {
|
||||
debug_assert!(is_closure_or_generator(
|
||||
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx)
|
||||
base.ty(self.mir, self.infcx.tcx).ty
|
||||
));
|
||||
|
||||
err.span_label(span, format!("cannot {ACT}", ACT = act));
|
||||
|
@ -450,9 +450,8 @@ fn sanitize_place(
|
||||
) -> PlaceTy<'tcx> {
|
||||
debug!("sanitize_place: {:?}", place);
|
||||
let place_ty = match place {
|
||||
Place::Base(PlaceBase::Local(index)) => PlaceTy::Ty {
|
||||
ty: self.mir.local_decls[*index].ty,
|
||||
},
|
||||
Place::Base(PlaceBase::Local(index)) =>
|
||||
PlaceTy::from_ty(self.mir.local_decls[*index].ty),
|
||||
Place::Base(PlaceBase::Static(box Static { kind, ty: sty })) => {
|
||||
let sty = self.sanitize_type(place, sty);
|
||||
let check_err =
|
||||
@ -493,7 +492,7 @@ fn sanitize_place(
|
||||
check_err(self, place, ty, sty);
|
||||
}
|
||||
}
|
||||
PlaceTy::Ty { ty: sty }
|
||||
PlaceTy::from_ty(sty)
|
||||
}
|
||||
Place::Projection(ref proj) => {
|
||||
let base_context = if context.is_mutating_use() {
|
||||
@ -502,12 +501,10 @@ fn sanitize_place(
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
|
||||
};
|
||||
let base_ty = self.sanitize_place(&proj.base, location, base_context);
|
||||
if let PlaceTy::Ty { ty } = base_ty {
|
||||
if ty.references_error() {
|
||||
if base_ty.variant_index.is_none() {
|
||||
if base_ty.ty.references_error() {
|
||||
assert!(self.errors_reported);
|
||||
return PlaceTy::Ty {
|
||||
ty: self.tcx().types.err,
|
||||
};
|
||||
return PlaceTy::from_ty(self.tcx().types.err);
|
||||
}
|
||||
}
|
||||
self.sanitize_projection(base_ty, &proj.elem, place, location)
|
||||
@ -517,7 +514,7 @@ fn sanitize_place(
|
||||
let tcx = self.tcx();
|
||||
let trait_ref = ty::TraitRef {
|
||||
def_id: tcx.lang_items().copy_trait().unwrap(),
|
||||
substs: tcx.mk_substs_trait(place_ty.to_ty(tcx), &[]),
|
||||
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
|
||||
};
|
||||
|
||||
// In order to have a Copy operand, the type T of the
|
||||
@ -615,40 +612,40 @@ fn sanitize_projection(
|
||||
) -> PlaceTy<'tcx> {
|
||||
debug!("sanitize_projection: {:?} {:?} {:?}", base, pi, place);
|
||||
let tcx = self.tcx();
|
||||
let base_ty = base.to_ty(tcx);
|
||||
let base_ty = base.ty;
|
||||
match *pi {
|
||||
ProjectionElem::Deref => {
|
||||
let deref_ty = base_ty.builtin_deref(true);
|
||||
PlaceTy::Ty {
|
||||
ty: deref_ty.map(|t| t.ty).unwrap_or_else(|| {
|
||||
PlaceTy::from_ty(
|
||||
deref_ty.map(|t| t.ty).unwrap_or_else(|| {
|
||||
span_mirbug_and_err!(self, place, "deref of non-pointer {:?}", base_ty)
|
||||
}),
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
ProjectionElem::Index(i) => {
|
||||
let index_ty = Place::Base(PlaceBase::Local(i)).ty(self.mir, tcx).to_ty(tcx);
|
||||
let index_ty = Place::Base(PlaceBase::Local(i)).ty(self.mir, tcx).ty;
|
||||
if index_ty != tcx.types.usize {
|
||||
PlaceTy::Ty {
|
||||
ty: span_mirbug_and_err!(self, i, "index by non-usize {:?}", i),
|
||||
}
|
||||
PlaceTy::from_ty(
|
||||
span_mirbug_and_err!(self, i, "index by non-usize {:?}", i),
|
||||
)
|
||||
} else {
|
||||
PlaceTy::Ty {
|
||||
ty: base_ty.builtin_index().unwrap_or_else(|| {
|
||||
PlaceTy::from_ty(
|
||||
base_ty.builtin_index().unwrap_or_else(|| {
|
||||
span_mirbug_and_err!(self, place, "index of non-array {:?}", base_ty)
|
||||
}),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
ProjectionElem::ConstantIndex { .. } => {
|
||||
// consider verifying in-bounds
|
||||
PlaceTy::Ty {
|
||||
ty: base_ty.builtin_index().unwrap_or_else(|| {
|
||||
PlaceTy::from_ty(
|
||||
base_ty.builtin_index().unwrap_or_else(|| {
|
||||
span_mirbug_and_err!(self, place, "index of non-array {:?}", base_ty)
|
||||
}),
|
||||
}
|
||||
)
|
||||
}
|
||||
ProjectionElem::Subslice { from, to } => PlaceTy::Ty {
|
||||
ty: match base_ty.sty {
|
||||
ProjectionElem::Subslice { from, to } => PlaceTy::from_ty(
|
||||
match base_ty.sty {
|
||||
ty::Array(inner, size) => {
|
||||
let size = size.unwrap_usize(tcx);
|
||||
let min_size = (from as u64) + (to as u64);
|
||||
@ -666,24 +663,23 @@ fn sanitize_projection(
|
||||
ty::Slice(..) => base_ty,
|
||||
_ => span_mirbug_and_err!(self, place, "slice of non-array {:?}", base_ty),
|
||||
},
|
||||
},
|
||||
),
|
||||
ProjectionElem::Downcast(maybe_name, index) => match base_ty.sty {
|
||||
ty::Adt(adt_def, substs) if adt_def.is_enum() => {
|
||||
ty::Adt(adt_def, _substs) if adt_def.is_enum() => {
|
||||
if index.as_usize() >= adt_def.variants.len() {
|
||||
PlaceTy::Ty {
|
||||
ty: span_mirbug_and_err!(
|
||||
PlaceTy::from_ty(
|
||||
span_mirbug_and_err!(
|
||||
self,
|
||||
place,
|
||||
"cast to variant #{:?} but enum only has {:?}",
|
||||
index,
|
||||
adt_def.variants.len()
|
||||
),
|
||||
}
|
||||
)
|
||||
} else {
|
||||
PlaceTy::Downcast {
|
||||
adt_def,
|
||||
substs,
|
||||
variant_index: index,
|
||||
PlaceTy {
|
||||
ty: base_ty,
|
||||
variant_index: Some(index),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -699,7 +695,7 @@ fn sanitize_projection(
|
||||
} else {
|
||||
span_mirbug_and_err!(self, place, "can't downcast {:?}", base_ty)
|
||||
};
|
||||
PlaceTy::Ty { ty }
|
||||
PlaceTy::from_ty(ty)
|
||||
},
|
||||
},
|
||||
ProjectionElem::Field(field, fty) => {
|
||||
@ -728,7 +724,7 @@ fn sanitize_projection(
|
||||
field_count
|
||||
),
|
||||
}
|
||||
PlaceTy::Ty { ty: fty }
|
||||
PlaceTy::from_ty(fty)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -748,12 +744,13 @@ fn field_ty(
|
||||
let tcx = self.tcx();
|
||||
|
||||
let (variant, substs) = match base_ty {
|
||||
PlaceTy::Downcast {
|
||||
adt_def,
|
||||
substs,
|
||||
variant_index,
|
||||
} => (&adt_def.variants[variant_index], substs),
|
||||
PlaceTy::Ty { ty } => match ty.sty {
|
||||
PlaceTy { ty, variant_index: Some(variant_index) } => {
|
||||
match ty.sty {
|
||||
ty::TyKind::Adt(adt_def, substs) => (&adt_def.variants[variant_index], substs),
|
||||
_ => bug!("can't have downcast of non-adt type"),
|
||||
}
|
||||
}
|
||||
PlaceTy { ty, variant_index: None } => match ty.sty {
|
||||
ty::Adt(adt_def, substs) if !adt_def.is_enum() =>
|
||||
(&adt_def.variants[VariantIdx::new(0)], substs),
|
||||
ty::Closure(def_id, substs) => {
|
||||
@ -1190,7 +1187,7 @@ fn relate_type_and_user_type(
|
||||
debug!("user_ty base: {:?} freshened: {:?} projs: {:?} yields: {:?}",
|
||||
user_ty.base, annotated_type, user_ty.projs, curr_projected_ty);
|
||||
|
||||
let ty = curr_projected_ty.to_ty(tcx);
|
||||
let ty = curr_projected_ty.ty;
|
||||
self.relate_types(a, v, ty, locations, category)?;
|
||||
|
||||
Ok(())
|
||||
@ -1338,7 +1335,7 @@ fn check_stmt(&mut self, mir: &Mir<'tcx>, stmt: &Statement<'tcx>, location: Loca
|
||||
_ => ConstraintCategory::Assignment,
|
||||
};
|
||||
|
||||
let place_ty = place.ty(mir, tcx).to_ty(tcx);
|
||||
let place_ty = place.ty(mir, tcx).ty;
|
||||
let rv_ty = rv.ty(mir, tcx);
|
||||
if let Err(terr) =
|
||||
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
|
||||
@ -1390,7 +1387,7 @@ fn check_stmt(&mut self, mir: &Mir<'tcx>, stmt: &Statement<'tcx>, location: Loca
|
||||
ref place,
|
||||
variant_index,
|
||||
} => {
|
||||
let place_type = place.ty(mir, tcx).to_ty(tcx);
|
||||
let place_type = place.ty(mir, tcx).ty;
|
||||
let adt = match place_type.sty {
|
||||
TyKind::Adt(adt, _) if adt.is_enum() => adt,
|
||||
_ => {
|
||||
@ -1412,7 +1409,7 @@ fn check_stmt(&mut self, mir: &Mir<'tcx>, stmt: &Statement<'tcx>, location: Loca
|
||||
};
|
||||
}
|
||||
StatementKind::AscribeUserType(ref place, variance, box ref projection) => {
|
||||
let place_ty = place.ty(mir, tcx).to_ty(tcx);
|
||||
let place_ty = place.ty(mir, tcx).ty;
|
||||
if let Err(terr) = self.relate_type_and_user_type(
|
||||
place_ty,
|
||||
variance,
|
||||
@ -1468,7 +1465,7 @@ fn check_terminator(
|
||||
target: _,
|
||||
unwind: _,
|
||||
} => {
|
||||
let place_ty = location.ty(mir, tcx).to_ty(tcx);
|
||||
let place_ty = location.ty(mir, tcx).ty;
|
||||
let rv_ty = value.ty(mir, tcx);
|
||||
|
||||
let locations = term_location.to_locations();
|
||||
@ -1616,7 +1613,7 @@ fn check_call_dest(
|
||||
let tcx = self.tcx();
|
||||
match *destination {
|
||||
Some((ref dest, _target_block)) => {
|
||||
let dest_ty = dest.ty(mir, tcx).to_ty(tcx);
|
||||
let dest_ty = dest.ty(mir, tcx).ty;
|
||||
let category = match *dest {
|
||||
Place::Base(PlaceBase::Local(RETURN_PLACE)) => {
|
||||
if let Some(BorrowCheckContext {
|
||||
@ -2375,7 +2372,7 @@ fn add_reborrow_constraint(
|
||||
match *elem {
|
||||
ProjectionElem::Deref => {
|
||||
let tcx = self.infcx.tcx;
|
||||
let base_ty = base.ty(mir, tcx).to_ty(tcx);
|
||||
let base_ty = base.ty(mir, tcx).ty;
|
||||
|
||||
debug!("add_reborrow_constraint - base_ty = {:?}", base_ty);
|
||||
match base_ty.sty {
|
||||
|
@ -63,7 +63,7 @@ fn ignore_borrow(
|
||||
tcx, mir, locals_state_at_exit),
|
||||
|
||||
ProjectionElem::Deref => {
|
||||
let ty = proj.base.ty(mir, tcx).to_ty(tcx);
|
||||
let ty = proj.base.ty(mir, tcx).ty;
|
||||
match ty.sty {
|
||||
// For both derefs of raw pointers and `&T`
|
||||
// references, the original path is `Copy` and
|
||||
|
@ -191,7 +191,7 @@ fn place_components_conflict<'gcx, 'tcx>(
|
||||
Place::Projection(box Projection { base, elem }) => (base, elem),
|
||||
_ => bug!("place has no base?"),
|
||||
};
|
||||
let base_ty = base.ty(mir, tcx).to_ty(tcx);
|
||||
let base_ty = base.ty(mir, tcx).ty;
|
||||
|
||||
match (elem, &base_ty.sty, access) {
|
||||
(_, _, Shallow(Some(ArtificialField::ArrayLength)))
|
||||
@ -427,7 +427,7 @@ fn place_element_conflict<'a, 'gcx: 'tcx, 'tcx>(
|
||||
debug!("place_element_conflict: DISJOINT-OR-EQ-FIELD");
|
||||
Overlap::EqualOrDisjoint
|
||||
} else {
|
||||
let ty = pi1.base.ty(mir, tcx).to_ty(tcx);
|
||||
let ty = pi1.base.ty(mir, tcx).ty;
|
||||
match ty.sty {
|
||||
ty::Adt(def, _) if def.is_union() => {
|
||||
// Different fields of a union, we are basically stuck.
|
||||
|
@ -139,7 +139,7 @@ fn next(&mut self) -> Option<Self::Item> {
|
||||
// derefs, except we stop at the deref of a shared
|
||||
// reference.
|
||||
|
||||
let ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
|
||||
let ty = proj.base.ty(self.mir, self.tcx).ty;
|
||||
match ty.sty {
|
||||
ty::RawPtr(_) |
|
||||
ty::Ref(
|
||||
|
@ -163,7 +163,7 @@ fn ast_block_stmts(&mut self,
|
||||
// Then, the block may have an optional trailing expression which is a “return” value
|
||||
// of the block, which is stored into `destination`.
|
||||
let tcx = this.hir.tcx();
|
||||
let destination_ty = destination.ty(&this.local_decls, tcx).to_ty(tcx);
|
||||
let destination_ty = destination.ty(&this.local_decls, tcx).ty;
|
||||
if let Some(expr) = expr {
|
||||
let tail_result_is_ignored = destination_ty.is_unit() ||
|
||||
this.block_context.currently_ignores_tail_results();
|
||||
|
@ -374,7 +374,7 @@ pub(super) fn expr_into_pattern(
|
||||
let ty_source_info = self.source_info(user_ty_span);
|
||||
let user_ty = box pat_ascription_ty.user_ty(
|
||||
&mut self.canonical_user_type_annotations,
|
||||
place.ty(&self.local_decls, self.hir.tcx()).to_ty(self.hir.tcx()),
|
||||
place.ty(&self.local_decls, self.hir.tcx()).ty,
|
||||
ty_source_info.span,
|
||||
);
|
||||
self.cfg.push(
|
||||
@ -1293,7 +1293,7 @@ fn calculate_fake_borrows<'b>(
|
||||
debug!("add_fake_borrows all_fake_borrows = {:?}", all_fake_borrows);
|
||||
|
||||
all_fake_borrows.into_iter().map(|matched_place| {
|
||||
let fake_borrow_deref_ty = matched_place.ty(&self.local_decls, tcx).to_ty(tcx);
|
||||
let fake_borrow_deref_ty = matched_place.ty(&self.local_decls, tcx).ty;
|
||||
let fake_borrow_ty = tcx.mk_imm_ref(tcx.types.re_erased, fake_borrow_deref_ty);
|
||||
let fake_borrow_temp = self.local_decls.push(
|
||||
LocalDecl::new_temp(fake_borrow_ty, temp_span)
|
||||
@ -1587,7 +1587,7 @@ fn ascribe_types<'pat>(
|
||||
|
||||
let user_ty = box ascription.user_ty.clone().user_ty(
|
||||
&mut self.canonical_user_type_annotations,
|
||||
ascription.source.ty(&self.local_decls, self.hir.tcx()).to_ty(self.hir.tcx()),
|
||||
ascription.source.ty(&self.local_decls, self.hir.tcx()).ty,
|
||||
source_info.span
|
||||
);
|
||||
self.cfg.push(
|
||||
|
@ -70,7 +70,7 @@ pub fn push_usize(&mut self,
|
||||
|
||||
pub fn consume_by_copy_or_move(&self, place: Place<'tcx>) -> Operand<'tcx> {
|
||||
let tcx = self.hir.tcx();
|
||||
let ty = place.ty(&self.local_decls, tcx).to_ty(tcx);
|
||||
let ty = place.ty(&self.local_decls, tcx).ty;
|
||||
if !self.hir.type_is_copy_modulo_regions(ty, DUMMY_SP) {
|
||||
Operand::Move(place)
|
||||
} else {
|
||||
|
@ -49,7 +49,7 @@ pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>,
|
||||
fn place_contents_drop_state_cannot_differ<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
mir: &Mir<'tcx>,
|
||||
place: &mir::Place<'tcx>) -> bool {
|
||||
let ty = place.ty(mir, tcx).to_ty(tcx);
|
||||
let ty = place.ty(mir, tcx).ty;
|
||||
match ty.sty {
|
||||
ty::Array(..) => {
|
||||
debug!("place_contents_drop_state_cannot_differ place: {:?} ty: {:?} => false",
|
||||
@ -141,7 +141,7 @@ pub(crate) fn on_all_drop_children_bits<'a, 'gcx, 'tcx, F>(
|
||||
{
|
||||
on_all_children_bits(tcx, mir, &ctxt.move_data, path, |child| {
|
||||
let place = &ctxt.move_data.move_paths[path].place;
|
||||
let ty = place.ty(mir, tcx).to_ty(tcx);
|
||||
let ty = place.ty(mir, tcx).ty;
|
||||
debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty);
|
||||
|
||||
let gcx = tcx.global_tcx();
|
||||
|
@ -120,7 +120,7 @@ fn move_path_for_projection(&mut self,
|
||||
let base = self.move_path_for(&proj.base)?;
|
||||
let mir = self.builder.mir;
|
||||
let tcx = self.builder.tcx;
|
||||
let place_ty = proj.base.ty(mir, tcx).to_ty(tcx);
|
||||
let place_ty = proj.base.ty(mir, tcx).ty;
|
||||
match place_ty.sty {
|
||||
ty::Ref(..) | ty::RawPtr(..) =>
|
||||
return Err(MoveError::cannot_move_out_of(
|
||||
@ -424,7 +424,7 @@ fn gather_init(&mut self, place: &Place<'tcx>, kind: InitKind) {
|
||||
Place::Projection(box Projection {
|
||||
base,
|
||||
elem: ProjectionElem::Field(_, _),
|
||||
}) if match base.ty(self.builder.mir, self.builder.tcx).to_ty(self.builder.tcx).sty {
|
||||
}) if match base.ty(self.builder.mir, self.builder.tcx).ty.sty {
|
||||
ty::TyKind::Adt(def, _) if def.is_union() => true,
|
||||
_ => false,
|
||||
} => base,
|
||||
|
@ -625,8 +625,7 @@ fn visit_terminator_kind(&mut self,
|
||||
}
|
||||
mir::TerminatorKind::Drop { ref location, .. } |
|
||||
mir::TerminatorKind::DropAndReplace { ref location, .. } => {
|
||||
let ty = location.ty(self.mir, self.tcx)
|
||||
.to_ty(self.tcx);
|
||||
let ty = location.ty(self.mir, self.tcx).ty;
|
||||
let ty = tcx.subst_and_normalize_erasing_regions(
|
||||
self.param_substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
|
@ -106,7 +106,7 @@ fn add_move_for_packed_drop<'a, 'tcx>(
|
||||
};
|
||||
|
||||
let source_info = terminator.source_info;
|
||||
let ty = location.ty(mir, tcx).to_ty(tcx);
|
||||
let ty = location.ty(mir, tcx).ty;
|
||||
let temp = patch.new_temp(ty, terminator.source_info.span);
|
||||
|
||||
let storage_dead_block = patch.new_block(BasicBlockData {
|
||||
|
@ -87,7 +87,7 @@ fn run_pass<'a, 'tcx>(&self,
|
||||
let needs_retag = |place: &Place<'tcx>| {
|
||||
// FIXME: Instead of giving up for unstable places, we should introduce
|
||||
// a temporary and retag on that.
|
||||
is_stable(place) && may_have_reference(place.ty(&*local_decls, tcx).to_ty(tcx), tcx)
|
||||
is_stable(place) && may_have_reference(place.ty(&*local_decls, tcx).ty, tcx)
|
||||
};
|
||||
|
||||
// PART 1
|
||||
|
@ -227,7 +227,7 @@ fn visit_place(&mut self,
|
||||
}
|
||||
let is_borrow_of_interior_mut = context.is_borrow() && !base
|
||||
.ty(self.mir, self.tcx)
|
||||
.to_ty(self.tcx)
|
||||
.ty
|
||||
.is_freeze(self.tcx, self.param_env, self.source_info.span);
|
||||
// prevent
|
||||
// * `&mut x.field`
|
||||
@ -249,7 +249,7 @@ fn visit_place(&mut self,
|
||||
self.source_info = self.mir.local_decls[local].source_info;
|
||||
}
|
||||
}
|
||||
let base_ty = base.ty(self.mir, self.tcx).to_ty(self.tcx);
|
||||
let base_ty = base.ty(self.mir, self.tcx).ty;
|
||||
match base_ty.sty {
|
||||
ty::RawPtr(..) => {
|
||||
self.require_unsafe("dereference of raw pointer",
|
||||
@ -420,7 +420,7 @@ fn check_mut_borrowing_layout_constrained_field(
|
||||
}) = place {
|
||||
match *elem {
|
||||
ProjectionElem::Field(..) => {
|
||||
let ty = base.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx);
|
||||
let ty = base.ty(&self.mir.local_decls, self.tcx).ty;
|
||||
match ty.sty {
|
||||
ty::Adt(def, _) => match self.tcx.layout_scalar_valid_range(def.did) {
|
||||
(Bound::Unbounded, Bound::Unbounded) => {},
|
||||
|
@ -556,7 +556,7 @@ fn visit_statement(
|
||||
if let StatementKind::Assign(ref place, ref rval) = statement.kind {
|
||||
let place_ty: ty::Ty<'tcx> = place
|
||||
.ty(&self.mir.local_decls, self.tcx)
|
||||
.to_ty(self.tcx);
|
||||
.ty;
|
||||
if let Ok(place_layout) = self.tcx.layout_of(self.param_env.and(place_ty)) {
|
||||
if let Some(value) = self.const_prop(rval, place_layout, statement.source_info) {
|
||||
if let Place::Base(PlaceBase::Local(local)) = *place {
|
||||
|
@ -319,8 +319,7 @@ fn should_inline(&self,
|
||||
work_list.push(target);
|
||||
// If the location doesn't actually need dropping, treat it like
|
||||
// a regular goto.
|
||||
let ty = location.ty(callee_mir, tcx).subst(tcx, callsite.substs);
|
||||
let ty = ty.to_ty(tcx);
|
||||
let ty = location.ty(callee_mir, tcx).subst(tcx, callsite.substs).ty;
|
||||
if ty.needs_drop(tcx, param_env) {
|
||||
cost += CALL_PENALTY;
|
||||
if let Some(unwind) = unwind {
|
||||
@ -563,7 +562,7 @@ fn make_call_args(
|
||||
assert!(args.next().is_none());
|
||||
|
||||
let tuple = Place::Base(PlaceBase::Local(tuple));
|
||||
let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_mir, tcx).to_ty(tcx).sty {
|
||||
let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_mir, tcx).ty.sty {
|
||||
s
|
||||
} else {
|
||||
bug!("Closure arguments are not passed as a tuple");
|
||||
|
@ -82,14 +82,14 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for OptimizationFinder<'b, 'a, 'tcx> {
|
||||
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
|
||||
if let Rvalue::Ref(_, _, Place::Projection(ref projection)) = *rvalue {
|
||||
if let ProjectionElem::Deref = projection.elem {
|
||||
if projection.base.ty(self.mir, self.tcx).to_ty(self.tcx).is_region_ptr() {
|
||||
if projection.base.ty(self.mir, self.tcx).ty.is_region_ptr() {
|
||||
self.optimizations.and_stars.insert(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Rvalue::Len(ref place) = *rvalue {
|
||||
let place_ty = place.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx);
|
||||
let place_ty = place.ty(&self.mir.local_decls, self.tcx).ty;
|
||||
if let TyKind::Array(_, len) = place_ty.sty {
|
||||
let span = self.mir.source_info(location).span;
|
||||
let ty = self.tcx.types.usize;
|
||||
|
@ -135,7 +135,7 @@ fn check_lang_item_type<'a, 'tcx, D>(
|
||||
let sig = poly_sig.no_bound_vars().unwrap();
|
||||
let lhs_ty = lhs.ty(local_decls, tcx);
|
||||
let rhs_ty = rhs.ty(local_decls, tcx);
|
||||
let place_ty = place.ty(local_decls, tcx).to_ty(tcx);
|
||||
let place_ty = place.ty(local_decls, tcx).ty;
|
||||
let expected = [lhs_ty, rhs_ty, place_ty];
|
||||
assert_eq!(sig.inputs_and_output[..], expected,
|
||||
"lang item `{}`", tcx.def_path_str(did));
|
||||
|
@ -310,7 +310,7 @@ fn promote_candidate(mut self, candidate: Candidate) {
|
||||
place = &mut proj.base;
|
||||
};
|
||||
|
||||
let ty = place.ty(local_decls, self.tcx).to_ty(self.tcx);
|
||||
let ty = place.ty(local_decls, self.tcx).ty;
|
||||
let span = statement.source_info.span;
|
||||
|
||||
Operand::Move(mem::replace(place, promoted_place(ty, span)))
|
||||
|
@ -168,7 +168,7 @@ fn in_projection_structurally(
|
||||
cx,
|
||||
proj.base.ty(cx.mir, cx.tcx)
|
||||
.projection_ty(cx.tcx, &proj.elem)
|
||||
.to_ty(cx.tcx),
|
||||
.ty,
|
||||
);
|
||||
match proj.elem {
|
||||
ProjectionElem::Deref |
|
||||
@ -245,7 +245,7 @@ fn in_rvalue_structurally(cx: &ConstCx<'_, 'tcx>, rvalue: &Rvalue<'tcx>) -> bool
|
||||
// Special-case reborrows to be more like a copy of the reference.
|
||||
if let Place::Projection(ref proj) = *place {
|
||||
if let ProjectionElem::Deref = proj.elem {
|
||||
let base_ty = proj.base.ty(cx.mir, cx.tcx).to_ty(cx.tcx);
|
||||
let base_ty = proj.base.ty(cx.mir, cx.tcx).ty;
|
||||
if let ty::Ref(..) = base_ty.sty {
|
||||
return Self::in_place(cx, &proj.base);
|
||||
}
|
||||
@ -301,7 +301,7 @@ fn in_rvalue(cx: &ConstCx<'_, 'tcx>, rvalue: &Rvalue<'tcx>) -> bool {
|
||||
// allowed in constants (and the `Checker` will error), and/or it
|
||||
// won't be promoted, due to `&mut ...` or interior mutability.
|
||||
Rvalue::Ref(_, kind, ref place) => {
|
||||
let ty = place.ty(cx.mir, cx.tcx).to_ty(cx.tcx);
|
||||
let ty = place.ty(cx.mir, cx.tcx).ty;
|
||||
|
||||
if let BorrowKind::Mut { .. } = kind {
|
||||
// In theory, any zero-sized value could be borrowed
|
||||
@ -398,7 +398,7 @@ fn in_projection(cx: &ConstCx<'_, 'tcx>, proj: &PlaceProjection<'tcx>) -> bool {
|
||||
|
||||
ProjectionElem::Field(..) => {
|
||||
if cx.mode == Mode::Fn {
|
||||
let base_ty = proj.base.ty(cx.mir, cx.tcx).to_ty(cx.tcx);
|
||||
let base_ty = proj.base.ty(cx.mir, cx.tcx).ty;
|
||||
if let Some(def) = base_ty.ty_adt_def() {
|
||||
if def.is_union() {
|
||||
return true;
|
||||
@ -985,7 +985,7 @@ fn visit_place(&mut self,
|
||||
// `not_const` errors out in const contexts
|
||||
self.not_const()
|
||||
}
|
||||
let base_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
|
||||
let base_ty = proj.base.ty(self.mir, self.tcx).ty;
|
||||
match self.mode {
|
||||
Mode::Fn => {},
|
||||
_ => {
|
||||
@ -1009,7 +1009,7 @@ fn visit_place(&mut self,
|
||||
ProjectionElem::Subslice {..} |
|
||||
ProjectionElem::Field(..) |
|
||||
ProjectionElem::Index(_) => {
|
||||
let base_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
|
||||
let base_ty = proj.base.ty(self.mir, self.tcx).ty;
|
||||
if let Some(def) = base_ty.ty_adt_def() {
|
||||
if def.is_union() {
|
||||
match self.mode {
|
||||
@ -1066,7 +1066,7 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
|
||||
let mut is_reborrow = false;
|
||||
if let Place::Projection(ref proj) = *place {
|
||||
if let ProjectionElem::Deref = proj.elem {
|
||||
let base_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
|
||||
let base_ty = proj.base.ty(self.mir, self.tcx).ty;
|
||||
if let ty::Ref(..) = base_ty.sty {
|
||||
is_reborrow = true;
|
||||
}
|
||||
@ -1190,7 +1190,7 @@ fn visit_terminator_kind(&mut self,
|
||||
self.assign(dest, ValueSource::Call {
|
||||
callee: func,
|
||||
args,
|
||||
return_ty: dest.ty(self.mir, self.tcx).to_ty(self.tcx),
|
||||
return_ty: dest.ty(self.mir, self.tcx).ty,
|
||||
}, location);
|
||||
}
|
||||
|
||||
@ -1364,7 +1364,7 @@ fn visit_terminator_kind(&mut self,
|
||||
|
||||
if let Some(span) = needs_drop {
|
||||
// Double-check the type being dropped, to minimize false positives.
|
||||
let ty = place.ty(self.mir, self.tcx).to_ty(self.tcx);
|
||||
let ty = place.ty(self.mir, self.tcx).ty;
|
||||
if ty.needs_drop(self.tcx, self.param_env) {
|
||||
struct_span_err!(self.tcx.sess, span, E0493,
|
||||
"destructors cannot be evaluated at compile-time")
|
||||
|
@ -69,7 +69,7 @@ fn visit_assign(&mut self,
|
||||
from_end: false} = proj.elem {
|
||||
// no need to transformation
|
||||
} else {
|
||||
let place_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
|
||||
let place_ty = proj.base.ty(self.mir, self.tcx).ty;
|
||||
if let ty::Array(item_ty, const_size) = place_ty.sty {
|
||||
if let Some(size) = const_size.assert_usize(self.tcx) {
|
||||
assert!(size <= u32::max_value() as u64,
|
||||
@ -195,7 +195,7 @@ fn run_pass<'a, 'tcx>(&self,
|
||||
|
||||
let opt_src_place = items.first().and_then(|x| *x).map(|x| x.2);
|
||||
let opt_size = opt_src_place.and_then(|src_place| {
|
||||
let src_ty = src_place.ty(mir, tcx).to_ty(tcx);
|
||||
let src_ty = src_place.ty(mir, tcx).ty;
|
||||
if let ty::Array(_, ref size_o) = src_ty.sty {
|
||||
size_o.assert_usize(tcx)
|
||||
} else {
|
||||
|
@ -17,7 +17,7 @@ pub fn is_disaligned<'a, 'tcx, L>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
return false
|
||||
}
|
||||
|
||||
let ty = place.ty(local_decls, tcx).to_ty(tcx);
|
||||
let ty = place.ty(local_decls, tcx).ty;
|
||||
match tcx.layout_raw(param_env.and(ty)) {
|
||||
Ok(layout) if layout.align.abi.bytes() == 1 => {
|
||||
// if the alignment is 1, the type can't be further
|
||||
@ -46,7 +46,7 @@ fn is_within_packed<'a, 'tcx, L>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
// encountered a Deref, which is ABI-aligned
|
||||
ProjectionElem::Deref => break,
|
||||
ProjectionElem::Field(..) => {
|
||||
let ty = base.ty(local_decls, tcx).to_ty(tcx);
|
||||
let ty = base.ty(local_decls, tcx).ty;
|
||||
match ty.sty {
|
||||
ty::Adt(def, _) if def.repr.packed() => {
|
||||
return true
|
||||
|
@ -122,7 +122,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
|
||||
where D: DropElaborator<'b, 'tcx>
|
||||
{
|
||||
fn place_ty(&self, place: &Place<'tcx>) -> Ty<'tcx> {
|
||||
place.ty(self.elaborator.mir(), self.tcx()).to_ty(self.tcx())
|
||||
place.ty(self.elaborator.mir(), self.tcx()).ty
|
||||
}
|
||||
|
||||
fn tcx(&self) -> TyCtxt<'b, 'tcx, 'tcx> {
|
||||
|
Loading…
Reference in New Issue
Block a user