Skip to content

Commit

Permalink
Fix rebasing errors, convert some BodyCache::body() calls to reborrows
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashenas88 committed Dec 2, 2019
1 parent 64654ce commit 9978574
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mutability_errors.rs
Expand Up @@ -365,7 +365,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
PlaceRef {
base: PlaceBase::Local(local),
projection: [ProjectionElem::Deref],
} if self.body_cache.local_decls[*local].is_user_variable.is_some() =>
} if self.body.local_decls[*local].is_user_variable() =>
{
let local_decl = &self.body.local_decls[*local];
let suggestion = match local_decl.local_info {
Expand Down
28 changes: 14 additions & 14 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Expand Up @@ -1406,9 +1406,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
_ => ConstraintCategory::Assignment,
};

let place_ty = place.ty(body.body(), tcx).ty;
let place_ty = place.ty(&*body, tcx).ty;
let place_ty = self.normalize(place_ty, location);
let rv_ty = rv.ty(body.body(), tcx);
let rv_ty = rv.ty(&*body, tcx);
let rv_ty = self.normalize(rv_ty, location);
if let Err(terr) =
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
Expand Down Expand Up @@ -1460,7 +1460,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
ref place,
variant_index,
} => {
let place_type = place.ty(body.body(), tcx).ty;
let place_type = place.ty(&*body, tcx).ty;
let adt = match place_type.kind {
ty::Adt(adt, _) if adt.is_enum() => adt,
_ => {
Expand All @@ -1482,7 +1482,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
};
}
StatementKind::AscribeUserType(box(ref place, ref projection), variance) => {
let place_ty = place.ty(body.body(), tcx).ty;
let place_ty = place.ty(&*body, tcx).ty;
if let Err(terr) = self.relate_type_and_user_type(
place_ty,
variance,
Expand Down Expand Up @@ -1998,7 +1998,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// While this is located in `nll::typeck` this error is not an NLL error, it's
// a required check to make sure that repeated elements implement `Copy`.
let span = body.source_info(location).span;
let ty = operand.ty(body.body(), tcx);
let ty = operand.ty(&*body, tcx);
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
// To determine if `const_in_array_repeat_expressions` feature gate should
// be mentioned, need to check if the rvalue is promotable.
Expand Down Expand Up @@ -2052,7 +2052,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Rvalue::Cast(cast_kind, op, ty) => {
match cast_kind {
CastKind::Pointer(PointerCast::ReifyFnPointer) => {
let fn_sig = op.ty(body.body(), tcx).fn_sig(tcx);
let fn_sig = op.ty(&*body, tcx).fn_sig(tcx);

// The type that we see in the fcx is like
// `foo::<'a, 'b>`, where `foo` is the path to a
Expand Down Expand Up @@ -2081,7 +2081,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

CastKind::Pointer(PointerCast::ClosureFnPointer(unsafety)) => {
let sig = match op.ty(body.body(), tcx).kind {
let sig = match op.ty(&*body, tcx).kind {
ty::Closure(def_id, substs) => {
substs.as_closure().sig_ty(def_id, tcx).fn_sig(tcx)
}
Expand All @@ -2107,7 +2107,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

CastKind::Pointer(PointerCast::UnsafeFnPointer) => {
let fn_sig = op.ty(body.body(), tcx).fn_sig(tcx);
let fn_sig = op.ty(&*body, tcx).fn_sig(tcx);

// The type that we see in the fcx is like
// `foo::<'a, 'b>`, where `foo` is the path to a
Expand Down Expand Up @@ -2139,7 +2139,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let &ty = ty;
let trait_ref = ty::TraitRef {
def_id: tcx.lang_items().coerce_unsized_trait().unwrap(),
substs: tcx.mk_substs_trait(op.ty(body.body(), tcx), &[ty.into()]),
substs: tcx.mk_substs_trait(op.ty(&*body, tcx), &[ty.into()]),
};

self.prove_trait_ref(
Expand All @@ -2150,7 +2150,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

CastKind::Pointer(PointerCast::MutToConstPointer) => {
let ty_from = match op.ty(body.body(), tcx).kind {
let ty_from = match op.ty(&*body, tcx).kind {
ty::RawPtr(ty::TypeAndMut {
ty: ty_from,
mutbl: hir::Mutability::Mutable,
Expand Down Expand Up @@ -2198,7 +2198,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

CastKind::Pointer(PointerCast::ArrayToPointer) => {
let ty_from = op.ty(body.body(), tcx);
let ty_from = op.ty(&*body, tcx);

let opt_ty_elem = match ty_from.kind {
ty::RawPtr(
Expand Down Expand Up @@ -2260,7 +2260,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

CastKind::Misc => {
let ty_from = op.ty(body.body(), tcx);
let ty_from = op.ty(&*body, tcx);
let cast_ty_from = CastTy::from_ty(ty_from);
let cast_ty_to = CastTy::from_ty(ty);
match (cast_ty_from, cast_ty_to) {
Expand Down Expand Up @@ -2327,9 +2327,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
| Rvalue::BinaryOp(BinOp::Le, left, right)
| Rvalue::BinaryOp(BinOp::Gt, left, right)
| Rvalue::BinaryOp(BinOp::Ge, left, right) => {
let ty_left = left.ty(body.body(), tcx);
let ty_left = left.ty(&*body, tcx);
if let ty::RawPtr(_) | ty::FnPtr(_) = ty_left.kind {
let ty_right = right.ty(body.body(), tcx);
let ty_right = right.ty(&*body, tcx);
let common_ty = self.infcx.next_ty_var(
TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/transform/check_consts/qualifs.rs
Expand Up @@ -51,7 +51,7 @@ pub trait Qualif {
});
let qualif = base_qualif && Self::in_any_value_of_ty(
cx,
Place::ty_from(place.base, proj_base, cx.body.body(), cx.tcx)
Place::ty_from(place.base, proj_base, &*cx.body, cx.tcx)
.projection_ty(cx.tcx, elem)
.ty,
);
Expand Down Expand Up @@ -155,7 +155,7 @@ pub trait Qualif {
// Special-case reborrows to be more like a copy of the reference.
if let &[ref proj_base @ .., elem] = place.projection.as_ref() {
if ProjectionElem::Deref == elem {
let base_ty = Place::ty_from(&place.base, proj_base, cx.body.body(), cx.tcx).ty;
let base_ty = Place::ty_from(&place.base, proj_base, &*cx.body, cx.tcx).ty;
if let ty::Ref(..) = base_ty.kind {
return Self::in_place(cx, per_local, PlaceRef {
base: &place.base,
Expand Down Expand Up @@ -221,7 +221,7 @@ impl Qualif for HasMutInterior {
Rvalue::Aggregate(ref kind, _) => {
if let AggregateKind::Adt(def, ..) = **kind {
if Some(def.did) == cx.tcx.lang_items().unsafe_cell_type() {
let ty = rvalue.ty(cx.body.body(), cx.tcx);
let ty = rvalue.ty(&*cx.body, cx.tcx);
assert_eq!(Self::in_any_value_of_ty(cx, ty), true);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_consts/resolver.rs
Expand Up @@ -77,7 +77,7 @@ where
args: &[mir::Operand<'tcx>],
return_place: &mir::Place<'tcx>,
) {
let return_ty = return_place.ty(self.item.body.body(), self.item.tcx).ty;
let return_ty = return_place.ty(&*self.item.body, self.item.tcx).ty;
let qualif = Q::in_call(
self.item,
&|l| self.qualifs_per_local.contains(l),
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_mir/transform/check_consts/validation.rs
Expand Up @@ -172,7 +172,7 @@ impl Validator<'a, 'mir, 'tcx> {

let indirectly_mutable = old_dataflow::do_dataflow(
item.tcx,
item.body.body(),
&*item.body,
item.def_id,
&item.tcx.get_attrs(item.def_id),
&dead_unwinds,
Expand Down Expand Up @@ -304,7 +304,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {

// Special-case reborrows to be more like a copy of a reference.
if let Rvalue::Ref(_, kind, ref place) = *rvalue {
if let Some(reborrowed_proj) = place_as_reborrow(self.tcx, self.body.body(), place) {
if let Some(reborrowed_proj) = place_as_reborrow(self.tcx, &*self.body, place) {
let ctx = match kind {
BorrowKind::Shared => PlaceContext::NonMutatingUse(
NonMutatingUseContext::SharedBorrow,
Expand Down Expand Up @@ -390,7 +390,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
}

Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) => {
let operand_ty = operand.ty(self.body.body(), self.tcx);
let operand_ty = operand.ty(&*self.body, self.tcx);
let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast");
let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");

Expand All @@ -401,7 +401,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
}

Rvalue::BinaryOp(op, ref lhs, _) => {
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body.body(), self.tcx).kind {
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(&*self.body, self.tcx).kind {
assert!(op == BinOp::Eq || op == BinOp::Ne ||
op == BinOp::Le || op == BinOp::Lt ||
op == BinOp::Ge || op == BinOp::Gt ||
Expand Down Expand Up @@ -475,7 +475,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {

match elem {
ProjectionElem::Deref => {
let base_ty = Place::ty_from(place_base, proj_base, self.body.body(), self.tcx).ty;
let base_ty = Place::ty_from(place_base, proj_base, &*self.body, self.tcx).ty;
if let ty::RawPtr(_) = base_ty.kind {
if proj_base.is_empty() {
if let (PlaceBase::Local(local), []) = (place_base, proj_base) {
Expand All @@ -499,7 +499,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
ProjectionElem::Subslice {..} |
ProjectionElem::Field(..) |
ProjectionElem::Index(_) => {
let base_ty = Place::ty_from(place_base, proj_base, self.body.body(), self.tcx).ty;
let base_ty = Place::ty_from(place_base, proj_base, &*self.body, self.tcx).ty;
match base_ty.ty_adt_def() {
Some(def) if def.is_union() => {
self.check_op(ops::UnionAccess);
Expand Down Expand Up @@ -548,7 +548,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {

match kind {
TerminatorKind::Call { func, .. } => {
let fn_ty = func.ty(self.body.body(), self.tcx);
let fn_ty = func.ty(&*self.body, self.tcx);

let def_id = match fn_ty.kind {
ty::FnDef(def_id, _) => def_id,
Expand Down Expand Up @@ -609,7 +609,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
// Check to see if the type of this place can ever have a drop impl. If not, this
// `Drop` terminator is frivolous.
let ty_needs_drop = dropped_place
.ty(self.body.body(), self.tcx)
.ty(&*self.body, self.tcx)
.ty
.needs_drop(self.tcx, self.param_env);

Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/transform/mod.rs
Expand Up @@ -231,6 +231,7 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<BodyCache<'_>> {
&rustc_peek::SanityCheck,
&uniform_array_move_out::UniformArrayMoveOut,
]);
body.ensure_predecessors();
tcx.alloc_steal_mir(body)
}

Expand Down
18 changes: 9 additions & 9 deletions src/librustc_mir/transform/promote_consts.rs
Expand Up @@ -349,7 +349,7 @@ impl<'tcx> Validator<'_, 'tcx> {
let ty = Place::ty_from(
&place.base,
proj_base,
self.body.body(),
&*self.body,
self.tcx
)
.projection_ty(self.tcx, elem)
Expand All @@ -372,7 +372,7 @@ impl<'tcx> Validator<'_, 'tcx> {
}

if let BorrowKind::Mut { .. } = kind {
let ty = place.ty(self.body.body(), self.tcx).ty;
let ty = place.ty(&*self.body, self.tcx).ty;

// In theory, any zero-sized value could be borrowed
// mutably without consequences. However, only &mut []
Expand Down Expand Up @@ -521,7 +521,7 @@ impl<'tcx> Validator<'_, 'tcx> {
ProjectionElem::Field(..) => {
if self.const_kind.is_none() {
let base_ty =
Place::ty_from(place.base, proj_base, self.body.body(), self.tcx).ty;
Place::ty_from(place.base, proj_base, &*self.body, self.tcx).ty;
if let Some(def) = base_ty.ty_adt_def() {
// No promotion of union field accesses.
if def.is_union() {
Expand Down Expand Up @@ -570,7 +570,7 @@ impl<'tcx> Validator<'_, 'tcx> {
fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> {
match *rvalue {
Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) if self.const_kind.is_none() => {
let operand_ty = operand.ty(self.body.body(), self.tcx);
let operand_ty = operand.ty(&*self.body, self.tcx);
let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast");
let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
match (cast_in, cast_out) {
Expand All @@ -584,7 +584,7 @@ impl<'tcx> Validator<'_, 'tcx> {
}

Rvalue::BinaryOp(op, ref lhs, _) if self.const_kind.is_none() => {
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body.body(), self.tcx).kind {
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(&*self.body, self.tcx).kind {
assert!(op == BinOp::Eq || op == BinOp::Ne ||
op == BinOp::Le || op == BinOp::Lt ||
op == BinOp::Ge || op == BinOp::Gt ||
Expand Down Expand Up @@ -619,7 +619,7 @@ impl<'tcx> Validator<'_, 'tcx> {

Rvalue::Ref(_, kind, place) => {
if let BorrowKind::Mut { .. } = kind {
let ty = place.ty(self.body.body(), self.tcx).ty;
let ty = place.ty(&*self.body, self.tcx).ty;

// In theory, any zero-sized value could be borrowed
// mutably without consequences. However, only &mut []
Expand All @@ -646,7 +646,7 @@ impl<'tcx> Validator<'_, 'tcx> {
let mut place = place.as_ref();
if let [proj_base @ .., ProjectionElem::Deref] = &place.projection {
let base_ty =
Place::ty_from(&place.base, proj_base, self.body.body(), self.tcx).ty;
Place::ty_from(&place.base, proj_base, &*self.body, self.tcx).ty;
if let ty::Ref(..) = base_ty.kind {
place = PlaceRef {
base: &place.base,
Expand All @@ -672,7 +672,7 @@ impl<'tcx> Validator<'_, 'tcx> {
while let [proj_base @ .., elem] = place_projection {
// FIXME(eddyb) this is probably excessive, with
// the exception of `union` member accesses.
let ty = Place::ty_from(place.base, proj_base, self.body.body(), self.tcx)
let ty = Place::ty_from(place.base, proj_base, &*self.body, self.tcx)
.projection_ty(self.tcx, elem)
.ty;
if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
Expand Down Expand Up @@ -705,7 +705,7 @@ impl<'tcx> Validator<'_, 'tcx> {
callee: &Operand<'tcx>,
args: &[Operand<'tcx>],
) -> Result<(), Unpromotable> {
let fn_ty = callee.ty(self.body.body(), self.tcx);
let fn_ty = callee.ty(&*self.body, self.tcx);

if !self.explicit && self.const_kind.is_none() {
if let ty::FnDef(def_id, _) = fn_ty.kind {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/simplify_try.rs
Expand Up @@ -33,7 +33,7 @@ use itertools::Itertools as _;
pub struct SimplifyArmIdentity;

impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity {
fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyCache<'tcx>) {
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
for bb in basic_blocks {
// Need 3 statements:
Expand Down Expand Up @@ -151,7 +151,7 @@ fn match_variant_field_place<'tcx>(place: &Place<'tcx>) -> Option<(Local, VarFie
pub struct SimplifyBranchSame;

impl<'tcx> MirPass<'tcx> for SimplifyBranchSame {
fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyCache<'tcx>) {
let mut did_remove_blocks = false;
let bbs = body.basic_blocks_mut();
for bb_idx in bbs.indices() {
Expand Down

0 comments on commit 9978574

Please sign in to comment.