Skip to content

Commit 64654ce

Browse files
committed
Fix type errors created during rebasing
1 parent 598797c commit 64654ce

File tree

8 files changed

+67
-70
lines changed

8 files changed

+67
-70
lines changed

src/librustc/mir/cache.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl Cache {
114114
}
115115
}
116116

117-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
117+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, TypeFoldable)]
118118
pub struct BodyCache<'tcx> {
119119
cache: Cache,
120120
body: Body<'tcx>,
@@ -302,10 +302,3 @@ impl_stable_hash_for!(struct BodyCache<'tcx> {
302302
cache,
303303
body,
304304
});
305-
306-
BraceStructTypeFoldableImpl! {
307-
impl<'tcx> TypeFoldable<'tcx> for BodyCache<'tcx> {
308-
cache,
309-
body
310-
}
311-
}

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn type_check_internal<'a, 'tcx, R>(
220220

221221
if !errors_reported {
222222
// if verifier failed, don't do further checks to avoid ICEs
223-
checker.typeck_mir(&body);
223+
checker.typeck_mir(body);
224224
}
225225

226226
extra(&mut checker)
@@ -588,7 +588,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
588588

589589
if !self.errors_reported {
590590
// if verifier failed, don't do further checks to avoid ICEs
591-
self.cx.typeck_mir(&promoted_body);
591+
self.cx.typeck_mir(promoted_body);
592592
}
593593

594594
self.body = parent_body;
@@ -1374,7 +1374,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13741374
self.infcx.tcx
13751375
}
13761376

1377-
fn check_stmt(&mut self, body: &Body<'tcx>, stmt: &Statement<'tcx>, location: Location) {
1377+
fn check_stmt(&mut self, body: ReadOnlyBodyCache<'_, 'tcx>, stmt: &Statement<'tcx>, location: Location) {
13781378
debug!("check_stmt: {:?}", stmt);
13791379
let tcx = self.tcx();
13801380
match stmt.kind {
@@ -1406,9 +1406,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14061406
_ => ConstraintCategory::Assignment,
14071407
};
14081408

1409-
let place_ty = place.ty(body, tcx).ty;
1409+
let place_ty = place.ty(body.body(), tcx).ty;
14101410
let place_ty = self.normalize(place_ty, location);
1411-
let rv_ty = rv.ty(body, tcx);
1411+
let rv_ty = rv.ty(body.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, tcx).ty;
1463+
let place_type = place.ty(body.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, tcx).ty;
1485+
let place_ty = place.ty(body.body(), tcx).ty;
14861486
if let Err(terr) = self.relate_type_and_user_type(
14871487
place_ty,
14881488
variance,
@@ -1985,20 +1985,20 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19851985
}
19861986
}
19871987

1988-
fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
1988+
fn check_rvalue(&mut self, body: ReadOnlyBodyCache<'_, 'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
19891989
let tcx = self.tcx();
19901990

19911991
match rvalue {
19921992
Rvalue::Aggregate(ak, ops) => {
1993-
self.check_aggregate_rvalue(body, rvalue, ak, ops, location)
1993+
self.check_aggregate_rvalue(&body, rvalue, ak, ops, location)
19941994
}
19951995

19961996
Rvalue::Repeat(operand, len) => if *len > 1 {
19971997
if let Operand::Move(_) = operand {
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, tcx);
2001+
let ty = operand.ty(body.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, tcx).fn_sig(tcx);
2055+
let fn_sig = op.ty(body.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, tcx).kind {
2084+
let sig = match op.ty(body.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, tcx).fn_sig(tcx);
2110+
let fn_sig = op.ty(body.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, tcx), &[ty.into()]),
2142+
substs: tcx.mk_substs_trait(op.ty(body.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, tcx).kind {
2153+
let ty_from = match op.ty(body.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, tcx);
2201+
let ty_from = op.ty(body.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, tcx);
2263+
let ty_from = op.ty(body.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) {
@@ -2318,7 +2318,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23182318
}
23192319

23202320
Rvalue::Ref(region, _borrow_kind, borrowed_place) => {
2321-
self.add_reborrow_constraint(body, location, region, borrowed_place);
2321+
self.add_reborrow_constraint(&body, location, region, borrowed_place);
23222322
}
23232323

23242324
Rvalue::BinaryOp(BinOp::Eq, left, right)
@@ -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, tcx);
2330+
let ty_left = left.ty(body.body(), tcx);
23312331
if let ty::RawPtr(_) | ty::FnPtr(_) = ty_left.kind {
2332-
let ty_right = right.ty(body, tcx);
2332+
let ty_right = right.ty(body.body(), tcx);
23332333
let common_ty = self.infcx.next_ty_var(
23342334
TypeVariableOrigin {
23352335
kind: TypeVariableOriginKind::MiscVariable,
@@ -2754,12 +2754,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
27542754
})
27552755
}
27562756

2757-
fn typeck_mir(&mut self, body: &Body<'tcx>) {
2757+
fn typeck_mir(&mut self, body: ReadOnlyBodyCache<'_, 'tcx>) {
27582758
self.last_span = body.span;
27592759
debug!("run_on_mir: {:?}", body.span);
27602760

27612761
for (local, local_decl) in body.local_decls.iter_enumerated() {
2762-
self.check_local(body, local, local_decl);
2762+
self.check_local(&body, local, local_decl);
27632763
}
27642764

27652765
for (block, block_data) in body.basic_blocks().iter_enumerated() {
@@ -2775,8 +2775,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
27752775
location.statement_index += 1;
27762776
}
27772777

2778-
self.check_terminator(body, block_data.terminator(), location);
2779-
self.check_iscleanup(body, block_data);
2778+
self.check_terminator(&body, block_data.terminator(), location);
2779+
self.check_iscleanup(&body, block_data);
27802780
}
27812781
}
27822782

src/librustc_mir/transform/check_consts/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub mod validation;
2020
/// Information about the item currently being const-checked, as well as a reference to the global
2121
/// context.
2222
pub struct Item<'mir, 'tcx> {
23-
pub body: &'mir mir::Body<'tcx>,
23+
pub body: mir::ReadOnlyBodyCache<'mir, 'tcx>,
2424
pub tcx: TyCtxt<'tcx>,
2525
pub def_id: DefId,
2626
pub param_env: ty::ParamEnv<'tcx>,
@@ -31,7 +31,7 @@ impl Item<'mir, 'tcx> {
3131
pub fn new(
3232
tcx: TyCtxt<'tcx>,
3333
def_id: DefId,
34-
body: &'mir mir::Body<'tcx>,
34+
body: mir::ReadOnlyBodyCache<'mir, 'tcx>,
3535
) -> Self {
3636
let param_env = tcx.param_env(def_id);
3737
let const_kind = ConstKind::for_item(tcx, def_id);

src/librustc_mir/transform/check_consts/qualifs.rs

Lines changed: 3 additions & 3 deletions
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, cx.tcx)
54+
Place::ty_from(place.base, proj_base, cx.body.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, cx.tcx).ty;
158+
let base_ty = Place::ty_from(&place.base, proj_base, cx.body.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, cx.tcx);
224+
let ty = rvalue.ty(cx.body.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

Lines changed: 1 addition & 1 deletion
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, self.item.tcx).ty;
80+
let return_ty = return_place.ty(self.item.body.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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ impl<Q: Qualif> QualifCursor<'a, 'mir, 'tcx, Q> {
3939
) -> Self {
4040
let analysis = FlowSensitiveAnalysis::new(q, item);
4141
let results =
42-
dataflow::Engine::new(item.tcx, item.body, item.def_id, dead_unwinds, analysis)
42+
dataflow::Engine::new(item.tcx, &item.body, item.def_id, dead_unwinds, analysis)
4343
.iterate_to_fixpoint();
44-
let cursor = dataflow::ResultsCursor::new(item.body, results);
44+
let cursor = dataflow::ResultsCursor::new(item.body.body(), results);
4545

4646
let mut in_any_value_of_ty = BitSet::new_empty(item.body.local_decls.len());
4747
for (local, decl) in item.body.local_decls.iter_enumerated() {
@@ -172,17 +172,17 @@ impl Validator<'a, 'mir, 'tcx> {
172172

173173
let indirectly_mutable = old_dataflow::do_dataflow(
174174
item.tcx,
175-
item.body,
175+
item.body.body(),
176176
item.def_id,
177177
&item.tcx.get_attrs(item.def_id),
178178
&dead_unwinds,
179-
old_dataflow::IndirectlyMutableLocals::new(item.tcx, item.body, item.param_env),
179+
old_dataflow::IndirectlyMutableLocals::new(item.tcx, item.body.body(), item.param_env),
180180
|_, local| old_dataflow::DebugFormatted::new(&local),
181181
);
182182

183183
let indirectly_mutable = old_dataflow::DataflowResultsCursor::new(
184184
indirectly_mutable,
185-
item.body,
185+
item.body.body(),
186186
);
187187

188188
let qualifs = Qualifs {
@@ -208,7 +208,7 @@ impl Validator<'a, 'mir, 'tcx> {
208208
if use_min_const_fn_checks {
209209
// Enforce `min_const_fn` for stable `const fn`s.
210210
use crate::transform::qualify_min_const_fn::is_min_const_fn;
211-
if let Err((span, err)) = is_min_const_fn(tcx, def_id, body) {
211+
if let Err((span, err)) = is_min_const_fn(tcx, def_id, &body) {
212212
error_min_const_fn_violation(tcx, span, err);
213213
return;
214214
}
@@ -230,7 +230,7 @@ impl Validator<'a, 'mir, 'tcx> {
230230

231231
if should_check_for_sync {
232232
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
233-
check_return_ty_is_sync(tcx, body, hir_id);
233+
check_return_ty_is_sync(tcx, &body, hir_id);
234234
}
235235
}
236236

@@ -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, place) {
307+
if let Some(reborrowed_proj) = place_as_reborrow(self.tcx, self.body.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, self.tcx);
393+
let operand_ty = operand.ty(self.body.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, self.tcx).kind {
404+
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body.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, self.tcx).ty;
478+
let base_ty = Place::ty_from(place_base, proj_base, self.body.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, self.tcx).ty;
502+
let base_ty = Place::ty_from(place_base, proj_base, self.body.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, self.tcx);
551+
let fn_ty = func.ty(self.body.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, self.tcx)
612+
.ty(self.body.body(), self.tcx)
613613
.ty
614614
.needs_drop(self.tcx, self.param_env);
615615

src/librustc_mir/transform/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
205205
}
206206

207207
let item = check_consts::Item {
208-
body,
208+
body: body.unwrap_read_only(),
209209
tcx,
210210
def_id,
211211
const_kind,

0 commit comments

Comments
 (0)