Skip to content

Commit 9978574

Browse files
committed
Fix rebasing errors, convert some BodyCache::body() calls to reborrows
1 parent 64654ce commit 9978574

File tree

8 files changed

+39
-38
lines changed

8 files changed

+39
-38
lines changed

src/librustc_mir/borrow_check/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
365365
PlaceRef {
366366
base: PlaceBase::Local(local),
367367
projection: [ProjectionElem::Deref],
368-
} if self.body_cache.local_decls[*local].is_user_variable.is_some() =>
368+
} if self.body.local_decls[*local].is_user_variable() =>
369369
{
370370
let local_decl = &self.body.local_decls[*local];
371371
let suggestion = match local_decl.local_info {

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1406,9 +1406,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14061406
_ => ConstraintCategory::Assignment,
14071407
};
14081408

1409-
let place_ty = place.ty(body.body(), tcx).ty;
1409+
let place_ty = place.ty(&*body, tcx).ty;
14101410
let place_ty = self.normalize(place_ty, location);
1411-
let rv_ty = rv.ty(body.body(), tcx);
1411+
let rv_ty = rv.ty(&*body, tcx);
14121412
let rv_ty = self.normalize(rv_ty, location);
14131413
if let Err(terr) =
14141414
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
@@ -1460,7 +1460,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14601460
ref place,
14611461
variant_index,
14621462
} => {
1463-
let place_type = place.ty(body.body(), tcx).ty;
1463+
let place_type = place.ty(&*body, tcx).ty;
14641464
let adt = match place_type.kind {
14651465
ty::Adt(adt, _) if adt.is_enum() => adt,
14661466
_ => {
@@ -1482,7 +1482,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14821482
};
14831483
}
14841484
StatementKind::AscribeUserType(box(ref place, ref projection), variance) => {
1485-
let place_ty = place.ty(body.body(), tcx).ty;
1485+
let place_ty = place.ty(&*body, tcx).ty;
14861486
if let Err(terr) = self.relate_type_and_user_type(
14871487
place_ty,
14881488
variance,
@@ -1998,7 +1998,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19981998
// While this is located in `nll::typeck` this error is not an NLL error, it's
19991999
// a required check to make sure that repeated elements implement `Copy`.
20002000
let span = body.source_info(location).span;
2001-
let ty = operand.ty(body.body(), tcx);
2001+
let ty = operand.ty(&*body, tcx);
20022002
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
20032003
// To determine if `const_in_array_repeat_expressions` feature gate should
20042004
// be mentioned, need to check if the rvalue is promotable.
@@ -2052,7 +2052,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20522052
Rvalue::Cast(cast_kind, op, ty) => {
20532053
match cast_kind {
20542054
CastKind::Pointer(PointerCast::ReifyFnPointer) => {
2055-
let fn_sig = op.ty(body.body(), tcx).fn_sig(tcx);
2055+
let fn_sig = op.ty(&*body, tcx).fn_sig(tcx);
20562056

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

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

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

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

21452145
self.prove_trait_ref(
@@ -2150,7 +2150,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21502150
}
21512151

21522152
CastKind::Pointer(PointerCast::MutToConstPointer) => {
2153-
let ty_from = match op.ty(body.body(), tcx).kind {
2153+
let ty_from = match op.ty(&*body, tcx).kind {
21542154
ty::RawPtr(ty::TypeAndMut {
21552155
ty: ty_from,
21562156
mutbl: hir::Mutability::Mutable,
@@ -2198,7 +2198,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21982198
}
21992199

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

22032203
let opt_ty_elem = match ty_from.kind {
22042204
ty::RawPtr(
@@ -2260,7 +2260,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22602260
}
22612261

22622262
CastKind::Misc => {
2263-
let ty_from = op.ty(body.body(), tcx);
2263+
let ty_from = op.ty(&*body, tcx);
22642264
let cast_ty_from = CastTy::from_ty(ty_from);
22652265
let cast_ty_to = CastTy::from_ty(ty);
22662266
match (cast_ty_from, cast_ty_to) {
@@ -2327,9 +2327,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23272327
| Rvalue::BinaryOp(BinOp::Le, left, right)
23282328
| Rvalue::BinaryOp(BinOp::Gt, left, right)
23292329
| Rvalue::BinaryOp(BinOp::Ge, left, right) => {
2330-
let ty_left = left.ty(body.body(), tcx);
2330+
let ty_left = left.ty(&*body, tcx);
23312331
if let ty::RawPtr(_) | ty::FnPtr(_) = ty_left.kind {
2332-
let ty_right = right.ty(body.body(), tcx);
2332+
let ty_right = right.ty(&*body, tcx);
23332333
let common_ty = self.infcx.next_ty_var(
23342334
TypeVariableOrigin {
23352335
kind: TypeVariableOriginKind::MiscVariable,

src/librustc_mir/transform/check_consts/qualifs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub trait Qualif {
5151
});
5252
let qualif = base_qualif && Self::in_any_value_of_ty(
5353
cx,
54-
Place::ty_from(place.base, proj_base, cx.body.body(), cx.tcx)
54+
Place::ty_from(place.base, proj_base, &*cx.body, cx.tcx)
5555
.projection_ty(cx.tcx, elem)
5656
.ty,
5757
);
@@ -155,7 +155,7 @@ pub trait Qualif {
155155
// Special-case reborrows to be more like a copy of the reference.
156156
if let &[ref proj_base @ .., elem] = place.projection.as_ref() {
157157
if ProjectionElem::Deref == elem {
158-
let base_ty = Place::ty_from(&place.base, proj_base, cx.body.body(), cx.tcx).ty;
158+
let base_ty = Place::ty_from(&place.base, proj_base, &*cx.body, cx.tcx).ty;
159159
if let ty::Ref(..) = base_ty.kind {
160160
return Self::in_place(cx, per_local, PlaceRef {
161161
base: &place.base,
@@ -221,7 +221,7 @@ impl Qualif for HasMutInterior {
221221
Rvalue::Aggregate(ref kind, _) => {
222222
if let AggregateKind::Adt(def, ..) = **kind {
223223
if Some(def.did) == cx.tcx.lang_items().unsafe_cell_type() {
224-
let ty = rvalue.ty(cx.body.body(), cx.tcx);
224+
let ty = rvalue.ty(&*cx.body, cx.tcx);
225225
assert_eq!(Self::in_any_value_of_ty(cx, ty), true);
226226
return true;
227227
}

src/librustc_mir/transform/check_consts/resolver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ where
7777
args: &[mir::Operand<'tcx>],
7878
return_place: &mir::Place<'tcx>,
7979
) {
80-
let return_ty = return_place.ty(self.item.body.body(), self.item.tcx).ty;
80+
let return_ty = return_place.ty(&*self.item.body, self.item.tcx).ty;
8181
let qualif = Q::in_call(
8282
self.item,
8383
&|l| self.qualifs_per_local.contains(l),

src/librustc_mir/transform/check_consts/validation.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl Validator<'a, 'mir, 'tcx> {
172172

173173
let indirectly_mutable = old_dataflow::do_dataflow(
174174
item.tcx,
175-
item.body.body(),
175+
&*item.body,
176176
item.def_id,
177177
&item.tcx.get_attrs(item.def_id),
178178
&dead_unwinds,
@@ -304,7 +304,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
304304

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

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

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

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

476476
match elem {
477477
ProjectionElem::Deref => {
478-
let base_ty = Place::ty_from(place_base, proj_base, self.body.body(), self.tcx).ty;
478+
let base_ty = Place::ty_from(place_base, proj_base, &*self.body, self.tcx).ty;
479479
if let ty::RawPtr(_) = base_ty.kind {
480480
if proj_base.is_empty() {
481481
if let (PlaceBase::Local(local), []) = (place_base, proj_base) {
@@ -499,7 +499,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
499499
ProjectionElem::Subslice {..} |
500500
ProjectionElem::Field(..) |
501501
ProjectionElem::Index(_) => {
502-
let base_ty = Place::ty_from(place_base, proj_base, self.body.body(), self.tcx).ty;
502+
let base_ty = Place::ty_from(place_base, proj_base, &*self.body, self.tcx).ty;
503503
match base_ty.ty_adt_def() {
504504
Some(def) if def.is_union() => {
505505
self.check_op(ops::UnionAccess);
@@ -548,7 +548,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
548548

549549
match kind {
550550
TerminatorKind::Call { func, .. } => {
551-
let fn_ty = func.ty(self.body.body(), self.tcx);
551+
let fn_ty = func.ty(&*self.body, self.tcx);
552552

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

src/librustc_mir/transform/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<BodyCache<'_>> {
231231
&rustc_peek::SanityCheck,
232232
&uniform_array_move_out::UniformArrayMoveOut,
233233
]);
234+
body.ensure_predecessors();
234235
tcx.alloc_steal_mir(body)
235236
}
236237

src/librustc_mir/transform/promote_consts.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl<'tcx> Validator<'_, 'tcx> {
349349
let ty = Place::ty_from(
350350
&place.base,
351351
proj_base,
352-
self.body.body(),
352+
&*self.body,
353353
self.tcx
354354
)
355355
.projection_ty(self.tcx, elem)
@@ -372,7 +372,7 @@ impl<'tcx> Validator<'_, 'tcx> {
372372
}
373373

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

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

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

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

624624
// In theory, any zero-sized value could be borrowed
625625
// mutably without consequences. However, only &mut []
@@ -646,7 +646,7 @@ impl<'tcx> Validator<'_, 'tcx> {
646646
let mut place = place.as_ref();
647647
if let [proj_base @ .., ProjectionElem::Deref] = &place.projection {
648648
let base_ty =
649-
Place::ty_from(&place.base, proj_base, self.body.body(), self.tcx).ty;
649+
Place::ty_from(&place.base, proj_base, &*self.body, self.tcx).ty;
650650
if let ty::Ref(..) = base_ty.kind {
651651
place = PlaceRef {
652652
base: &place.base,
@@ -672,7 +672,7 @@ impl<'tcx> Validator<'_, 'tcx> {
672672
while let [proj_base @ .., elem] = place_projection {
673673
// FIXME(eddyb) this is probably excessive, with
674674
// the exception of `union` member accesses.
675-
let ty = Place::ty_from(place.base, proj_base, self.body.body(), self.tcx)
675+
let ty = Place::ty_from(place.base, proj_base, &*self.body, self.tcx)
676676
.projection_ty(self.tcx, elem)
677677
.ty;
678678
if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
@@ -705,7 +705,7 @@ impl<'tcx> Validator<'_, 'tcx> {
705705
callee: &Operand<'tcx>,
706706
args: &[Operand<'tcx>],
707707
) -> Result<(), Unpromotable> {
708-
let fn_ty = callee.ty(self.body.body(), self.tcx);
708+
let fn_ty = callee.ty(&*self.body, self.tcx);
709709

710710
if !self.explicit && self.const_kind.is_none() {
711711
if let ty::FnDef(def_id, _) = fn_ty.kind {

src/librustc_mir/transform/simplify_try.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use itertools::Itertools as _;
3333
pub struct SimplifyArmIdentity;
3434

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

153153
impl<'tcx> MirPass<'tcx> for SimplifyBranchSame {
154-
fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
154+
fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut BodyCache<'tcx>) {
155155
let mut did_remove_blocks = false;
156156
let bbs = body.basic_blocks_mut();
157157
for bb_idx in bbs.indices() {

0 commit comments

Comments
 (0)