Skip to content

Commit a57aea8

Browse files
committed
rustc: expose the mir::Body reference lifetime from mir::ReadOnlyBodyCache (rust-lang#64736 fallout).
1 parent 4810cf1 commit a57aea8

File tree

16 files changed

+62
-70
lines changed

16 files changed

+62
-70
lines changed

src/librustc/mir/cache.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,10 @@ impl<'a, 'b, 'tcx> graph::GraphSuccessors<'b> for ReadOnlyBodyCache<'a, 'tcx> {
279279

280280

281281
impl Deref for ReadOnlyBodyCache<'a, 'tcx> {
282-
type Target = Body<'tcx>;
282+
type Target = &'a Body<'tcx>;
283283

284284
fn deref(&self) -> &Self::Target {
285-
self.body
286-
}
287-
}
288-
289-
impl Index<BasicBlock> for ReadOnlyBodyCache<'a, 'tcx> {
290-
type Output = BasicBlockData<'tcx>;
291-
292-
fn index(&self, index: BasicBlock) -> &BasicBlockData<'tcx> {
293-
&self.body[index]
285+
&self.body
294286
}
295287
}
296288

src/librustc_codegen_ssa/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
131131
};
132132
if is_consume {
133133
let base_ty =
134-
mir::Place::ty_from(place_ref.base, proj_base, &*self.fx.mir, cx.tcx());
134+
mir::Place::ty_from(place_ref.base, proj_base, *self.fx.mir, cx.tcx());
135135
let base_ty = self.fx.monomorphize(&base_ty);
136136

137137
// ZSTs don't require any actual memory access.

src/librustc_codegen_ssa/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
324324
target: mir::BasicBlock,
325325
unwind: Option<mir::BasicBlock>,
326326
) {
327-
let ty = location.ty(&*self.mir, bx.tcx()).ty;
327+
let ty = location.ty(*self.mir, bx.tcx()).ty;
328328
let ty = self.monomorphize(&ty);
329329
let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
330330

@@ -510,7 +510,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
510510

511511
let extra_args = &args[sig.inputs().len()..];
512512
let extra_args = extra_args.iter().map(|op_arg| {
513-
let op_ty = op_arg.ty(&*self.mir, bx.tcx());
513+
let op_ty = op_arg.ty(*self.mir, bx.tcx());
514514
self.monomorphize(&op_ty)
515515
}).collect::<Vec<_>>();
516516

src/librustc_codegen_ssa/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
594594
let place_ty = mir::Place::ty_from(
595595
place_ref.base,
596596
place_ref.projection,
597-
&*self.mir,
597+
*self.mir,
598598
tcx,
599599
);
600600
self.monomorphize(&place_ty.ty)

src/librustc_codegen_ssa/mir/rvalue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
460460
}
461461

462462
mir::Rvalue::Discriminant(ref place) => {
463-
let discr_ty = rvalue.ty(&*self.mir, bx.tcx());
463+
let discr_ty = rvalue.ty(*self.mir, bx.tcx());
464464
let discr = self.codegen_place(&mut bx, &place.as_ref())
465465
.codegen_get_discr(&mut bx, discr_ty);
466466
(bx, OperandRef {
@@ -513,7 +513,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
513513
mir::Rvalue::Aggregate(..) => {
514514
// According to `rvalue_creates_operand`, only ZST
515515
// aggregate rvalues are allowed to be operands.
516-
let ty = rvalue.ty(&*self.mir, self.cx.tcx());
516+
let ty = rvalue.ty(*self.mir, self.cx.tcx());
517517
let operand = OperandRef::new_zst(
518518
&mut bx,
519519
self.cx.layout_of(self.monomorphize(&ty)),
@@ -710,7 +710,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
710710
true,
711711
mir::Rvalue::Repeat(..) |
712712
mir::Rvalue::Aggregate(..) => {
713-
let ty = rvalue.ty(&*self.mir, self.cx.tcx());
713+
let ty = rvalue.ty(*self.mir, self.cx.tcx());
714714
let ty = self.monomorphize(&ty);
715715
self.cx.spanned_layout_of(ty, span).is_zst()
716716
}

src/librustc_mir/borrow_check/conflict_errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
208208
let ty = Place::ty_from(
209209
used_place.base,
210210
used_place.projection,
211-
&*self.body,
211+
*self.body,
212212
self.infcx.tcx
213213
).ty;
214214
let needs_note = match ty.kind {
@@ -225,7 +225,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
225225
let mpi = self.move_data.moves[move_out_indices[0]].path;
226226
let place = &self.move_data.move_paths[mpi].place;
227227

228-
let ty = place.ty(&*self.body, self.infcx.tcx).ty;
228+
let ty = place.ty(*self.body, self.infcx.tcx).ty;
229229
let opt_name =
230230
self.describe_place_with_options(place.as_ref(), IncludingDowncast(true));
231231
let note_msg = match opt_name {
@@ -625,7 +625,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
625625
let ty = Place::ty_from(
626626
place_base,
627627
place_projection,
628-
&*self.body,
628+
*self.body,
629629
self.infcx.tcx
630630
).ty;
631631
ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
@@ -1635,7 +1635,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16351635
Place::ty_from(
16361636
&place.base,
16371637
proj_base,
1638-
&*self.body,
1638+
*self.body,
16391639
tcx
16401640
).ty.is_box(),
16411641
"Drop of value behind a reference or raw pointer"
@@ -1648,7 +1648,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16481648
let base_ty = Place::ty_from(
16491649
&place.base,
16501650
proj_base,
1651-
&*self.body,
1651+
*self.body,
16521652
tcx
16531653
).ty;
16541654
match base_ty.kind {

src/librustc_mir/borrow_check/error_reporting.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
372372
let base_ty = Place::ty_from(
373373
place.base,
374374
place.projection,
375-
&*self.body,
375+
*self.body,
376376
self.infcx.tcx).ty;
377377
self.describe_field_from_ty(&base_ty, field, Some(*variant_index))
378378
}
@@ -502,7 +502,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
502502
..
503503
}) = bbd.terminator {
504504
if let Some(source) = BorrowedContentSource::from_call(
505-
func.ty(&*self.body, tcx),
505+
func.ty(*self.body, tcx),
506506
tcx
507507
) {
508508
return source;
@@ -519,7 +519,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
519519
let base_ty = Place::ty_from(
520520
deref_base.base,
521521
deref_base.projection,
522-
&*self.body,
522+
*self.body,
523523
tcx
524524
).ty;
525525
if base_ty.is_unsafe_ptr() {

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
646646
let tcx = self.infcx.tcx;
647647

648648
// Compute the type with accurate region information.
649-
let drop_place_ty = drop_place.ty(&*self.body, self.infcx.tcx);
649+
let drop_place_ty = drop_place.ty(*self.body, self.infcx.tcx);
650650

651651
// Erase the regions.
652652
let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty;

src/librustc_mir/borrow_check/move_errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
300300
// Inspect the type of the content behind the
301301
// borrow to provide feedback about why this
302302
// was a move rather than a copy.
303-
let ty = deref_target_place.ty(&*self.body, self.infcx.tcx).ty;
303+
let ty = deref_target_place.ty(*self.body, self.infcx.tcx).ty;
304304
let upvar_field = self.prefixes(move_place.as_ref(), PrefixSet::All)
305305
.find_map(|p| self.is_upvar_field_projection(p));
306306

@@ -411,7 +411,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
411411
};
412412
let move_ty = format!(
413413
"{:?}",
414-
move_place.ty(&*self.body, self.infcx.tcx).ty,
414+
move_place.ty(*self.body, self.infcx.tcx).ty,
415415
);
416416
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
417417
let is_option = move_ty.starts_with("std::option::Option");
@@ -454,7 +454,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
454454
}
455455

456456
if binds_to.is_empty() {
457-
let place_ty = move_from.ty(&*self.body, self.infcx.tcx).ty;
457+
let place_ty = move_from.ty(*self.body, self.infcx.tcx).ty;
458458
let place_desc = match self.describe_place(move_from.as_ref()) {
459459
Some(desc) => format!("`{}`", desc),
460460
None => format!("value"),
@@ -482,7 +482,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
482482
// No binding. Nothing to suggest.
483483
GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => {
484484
let span = use_spans.var_or_use();
485-
let place_ty = original_path.ty(&*self.body, self.infcx.tcx).ty;
485+
let place_ty = original_path.ty(*self.body, self.infcx.tcx).ty;
486486
let place_desc = match self.describe_place(original_path.as_ref()) {
487487
Some(desc) => format!("`{}`", desc),
488488
None => format!("value"),

src/librustc_mir/borrow_check/mutability_errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
6464
Place::ty_from(
6565
&the_place_err.base,
6666
proj_base,
67-
&*self.body,
67+
*self.body,
6868
self.infcx.tcx
6969
).ty));
7070

@@ -115,7 +115,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
115115
Place::ty_from(
116116
the_place_err.base,
117117
the_place_err.projection,
118-
&*self.body,
118+
*self.body,
119119
self.infcx.tcx
120120
)
121121
.ty
@@ -229,7 +229,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
229229

230230
if let Some((span, message)) = annotate_struct_field(
231231
self.infcx.tcx,
232-
Place::ty_from(base, proj_base, &*self.body, self.infcx.tcx).ty,
232+
Place::ty_from(base, proj_base, *self.body, self.infcx.tcx).ty,
233233
field,
234234
) {
235235
err.span_suggestion(
@@ -304,7 +304,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
304304
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
305305
} => {
306306
debug_assert!(is_closure_or_generator(
307-
Place::ty_from(base, proj_base, &*self.body, self.infcx.tcx).ty
307+
Place::ty_from(base, proj_base, *self.body, self.infcx.tcx).ty
308308
));
309309

310310
err.span_label(span, format!("cannot {ACT}", ACT = act));

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

+14-14
Original file line numberDiff line numberDiff line change
@@ -1413,9 +1413,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14131413
_ => ConstraintCategory::Assignment,
14141414
};
14151415

1416-
let place_ty = place.ty(&*body, tcx).ty;
1416+
let place_ty = place.ty(*body, tcx).ty;
14171417
let place_ty = self.normalize(place_ty, location);
1418-
let rv_ty = rv.ty(&*body, tcx);
1418+
let rv_ty = rv.ty(*body, tcx);
14191419
let rv_ty = self.normalize(rv_ty, location);
14201420
if let Err(terr) =
14211421
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
@@ -1467,7 +1467,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14671467
ref place,
14681468
variant_index,
14691469
} => {
1470-
let place_type = place.ty(&*body, tcx).ty;
1470+
let place_type = place.ty(*body, tcx).ty;
14711471
let adt = match place_type.kind {
14721472
ty::Adt(adt, _) if adt.is_enum() => adt,
14731473
_ => {
@@ -1489,7 +1489,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14891489
};
14901490
}
14911491
StatementKind::AscribeUserType(box(ref place, ref projection), variance) => {
1492-
let place_ty = place.ty(&*body, tcx).ty;
1492+
let place_ty = place.ty(*body, tcx).ty;
14931493
if let Err(terr) = self.relate_type_and_user_type(
14941494
place_ty,
14951495
variance,
@@ -2010,7 +2010,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20102010
// While this is located in `nll::typeck` this error is not an NLL error, it's
20112011
// a required check to make sure that repeated elements implement `Copy`.
20122012
let span = body.source_info(location).span;
2013-
let ty = operand.ty(&*body, tcx);
2013+
let ty = operand.ty(*body, tcx);
20142014
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
20152015
// To determine if `const_in_array_repeat_expressions` feature gate should
20162016
// be mentioned, need to check if the rvalue is promotable.
@@ -2064,7 +2064,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20642064
Rvalue::Cast(cast_kind, op, ty) => {
20652065
match cast_kind {
20662066
CastKind::Pointer(PointerCast::ReifyFnPointer) => {
2067-
let fn_sig = op.ty(&*body, tcx).fn_sig(tcx);
2067+
let fn_sig = op.ty(*body, tcx).fn_sig(tcx);
20682068

20692069
// The type that we see in the fcx is like
20702070
// `foo::<'a, 'b>`, where `foo` is the path to a
@@ -2093,7 +2093,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20932093
}
20942094

20952095
CastKind::Pointer(PointerCast::ClosureFnPointer(unsafety)) => {
2096-
let sig = match op.ty(&*body, tcx).kind {
2096+
let sig = match op.ty(*body, tcx).kind {
20972097
ty::Closure(def_id, substs) => {
20982098
substs.as_closure().sig_ty(def_id, tcx).fn_sig(tcx)
20992099
}
@@ -2119,7 +2119,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21192119
}
21202120

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

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

21572157
self.prove_trait_ref(
@@ -2162,7 +2162,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21622162
}
21632163

21642164
CastKind::Pointer(PointerCast::MutToConstPointer) => {
2165-
let ty_from = match op.ty(&*body, tcx).kind {
2165+
let ty_from = match op.ty(*body, tcx).kind {
21662166
ty::RawPtr(ty::TypeAndMut {
21672167
ty: ty_from,
21682168
mutbl: hir::Mutability::Mutable,
@@ -2210,7 +2210,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22102210
}
22112211

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

22152215
let opt_ty_elem = match ty_from.kind {
22162216
ty::RawPtr(
@@ -2272,7 +2272,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22722272
}
22732273

22742274
CastKind::Misc => {
2275-
let ty_from = op.ty(&*body, tcx);
2275+
let ty_from = op.ty(*body, tcx);
22762276
let cast_ty_from = CastTy::from_ty(ty_from);
22772277
let cast_ty_to = CastTy::from_ty(ty);
22782278
match (cast_ty_from, cast_ty_to) {
@@ -2339,9 +2339,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23392339
| Rvalue::BinaryOp(BinOp::Le, left, right)
23402340
| Rvalue::BinaryOp(BinOp::Gt, left, right)
23412341
| Rvalue::BinaryOp(BinOp::Ge, left, right) => {
2342-
let ty_left = left.ty(&*body, tcx);
2342+
let ty_left = left.ty(*body, tcx);
23432343
if let ty::RawPtr(_) | ty::FnPtr(_) = ty_left.kind {
2344-
let ty_right = right.ty(&*body, tcx);
2344+
let ty_right = right.ty(*body, tcx);
23452345
let common_ty = self.infcx.next_ty_var(
23462346
TypeVariableOrigin {
23472347
kind: TypeVariableOriginKind::MiscVariable,

src/librustc_mir/borrow_check/prefixes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
143143
// derefs, except we stop at the deref of a shared
144144
// reference.
145145

146-
let ty = Place::ty_from(cursor.base, proj_base, &*self.body, self.tcx).ty;
146+
let ty = Place::ty_from(cursor.base, proj_base, *self.body, self.tcx).ty;
147147
match ty.kind {
148148
ty::RawPtr(_) |
149149
ty::Ref(

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, 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, 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, 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, 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),

0 commit comments

Comments
 (0)