Skip to content
Permalink
Browse files

rustc: expose the mir::Body reference lifetime from mir::ReadOnlyBody…

…Cache (#64736 fallout).
  • Loading branch information
eddyb committed Dec 3, 2019
1 parent 4810cf1 commit a57aea88d4620008ff06ed8e23f093a2e88b33f9
@@ -279,18 +279,10 @@ impl<'a, 'b, 'tcx> graph::GraphSuccessors<'b> for ReadOnlyBodyCache<'a, 'tcx> {


impl Deref for ReadOnlyBodyCache<'a, 'tcx> {
type Target = Body<'tcx>;
type Target = &'a Body<'tcx>;

fn deref(&self) -> &Self::Target {
self.body
}
}

impl Index<BasicBlock> for ReadOnlyBodyCache<'a, 'tcx> {
type Output = BasicBlockData<'tcx>;

fn index(&self, index: BasicBlock) -> &BasicBlockData<'tcx> {
&self.body[index]
&self.body
}
}

@@ -131,7 +131,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
};
if is_consume {
let base_ty =
mir::Place::ty_from(place_ref.base, proj_base, &*self.fx.mir, cx.tcx());
mir::Place::ty_from(place_ref.base, proj_base, *self.fx.mir, cx.tcx());
let base_ty = self.fx.monomorphize(&base_ty);

// ZSTs don't require any actual memory access.
@@ -324,7 +324,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
target: mir::BasicBlock,
unwind: Option<mir::BasicBlock>,
) {
let ty = location.ty(&*self.mir, bx.tcx()).ty;
let ty = location.ty(*self.mir, bx.tcx()).ty;
let ty = self.monomorphize(&ty);
let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);

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

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

@@ -594,7 +594,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let place_ty = mir::Place::ty_from(
place_ref.base,
place_ref.projection,
&*self.mir,
*self.mir,
tcx,
);
self.monomorphize(&place_ty.ty)
@@ -460,7 +460,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}

mir::Rvalue::Discriminant(ref place) => {
let discr_ty = rvalue.ty(&*self.mir, bx.tcx());
let discr_ty = rvalue.ty(*self.mir, bx.tcx());
let discr = self.codegen_place(&mut bx, &place.as_ref())
.codegen_get_discr(&mut bx, discr_ty);
(bx, OperandRef {
@@ -513,7 +513,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Rvalue::Aggregate(..) => {
// According to `rvalue_creates_operand`, only ZST
// aggregate rvalues are allowed to be operands.
let ty = rvalue.ty(&*self.mir, self.cx.tcx());
let ty = rvalue.ty(*self.mir, self.cx.tcx());
let operand = OperandRef::new_zst(
&mut bx,
self.cx.layout_of(self.monomorphize(&ty)),
@@ -710,7 +710,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
true,
mir::Rvalue::Repeat(..) |
mir::Rvalue::Aggregate(..) => {
let ty = rvalue.ty(&*self.mir, self.cx.tcx());
let ty = rvalue.ty(*self.mir, self.cx.tcx());
let ty = self.monomorphize(&ty);
self.cx.spanned_layout_of(ty, span).is_zst()
}
@@ -208,7 +208,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let ty = Place::ty_from(
used_place.base,
used_place.projection,
&*self.body,
*self.body,
self.infcx.tcx
).ty;
let needs_note = match ty.kind {
@@ -225,7 +225,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
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.body, self.infcx.tcx).ty;
let ty = place.ty(*self.body, self.infcx.tcx).ty;
let opt_name =
self.describe_place_with_options(place.as_ref(), IncludingDowncast(true));
let note_msg = match opt_name {
@@ -625,7 +625,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let ty = Place::ty_from(
place_base,
place_projection,
&*self.body,
*self.body,
self.infcx.tcx
).ty;
ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
@@ -1635,7 +1635,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Place::ty_from(
&place.base,
proj_base,
&*self.body,
*self.body,
tcx
).ty.is_box(),
"Drop of value behind a reference or raw pointer"
@@ -1648,7 +1648,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let base_ty = Place::ty_from(
&place.base,
proj_base,
&*self.body,
*self.body,
tcx
).ty;
match base_ty.kind {
@@ -372,7 +372,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let base_ty = Place::ty_from(
place.base,
place.projection,
&*self.body,
*self.body,
self.infcx.tcx).ty;
self.describe_field_from_ty(&base_ty, field, Some(*variant_index))
}
@@ -502,7 +502,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
..
}) = bbd.terminator {
if let Some(source) = BorrowedContentSource::from_call(
func.ty(&*self.body, tcx),
func.ty(*self.body, tcx),
tcx
) {
return source;
@@ -519,7 +519,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let base_ty = Place::ty_from(
deref_base.base,
deref_base.projection,
&*self.body,
*self.body,
tcx
).ty;
if base_ty.is_unsafe_ptr() {
@@ -646,7 +646,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
let tcx = self.infcx.tcx;

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

// Erase the regions.
let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty;
@@ -300,7 +300,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '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 = deref_target_place.ty(&*self.body, self.infcx.tcx).ty;
let ty = deref_target_place.ty(*self.body, self.infcx.tcx).ty;
let upvar_field = self.prefixes(move_place.as_ref(), PrefixSet::All)
.find_map(|p| self.is_upvar_field_projection(p));

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

if binds_to.is_empty() {
let place_ty = move_from.ty(&*self.body, self.infcx.tcx).ty;
let place_ty = move_from.ty(*self.body, self.infcx.tcx).ty;
let place_desc = match self.describe_place(move_from.as_ref()) {
Some(desc) => format!("`{}`", desc),
None => format!("value"),
@@ -482,7 +482,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// No binding. Nothing to suggest.
GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => {
let span = use_spans.var_or_use();
let place_ty = original_path.ty(&*self.body, self.infcx.tcx).ty;
let place_ty = original_path.ty(*self.body, self.infcx.tcx).ty;
let place_desc = match self.describe_place(original_path.as_ref()) {
Some(desc) => format!("`{}`", desc),
None => format!("value"),
@@ -64,7 +64,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Place::ty_from(
&the_place_err.base,
proj_base,
&*self.body,
*self.body,
self.infcx.tcx
).ty));

@@ -115,7 +115,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Place::ty_from(
the_place_err.base,
the_place_err.projection,
&*self.body,
*self.body,
self.infcx.tcx
)
.ty
@@ -229,7 +229,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

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

err.span_label(span, format!("cannot {ACT}", ACT = act));
@@ -1413,9 +1413,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
_ => ConstraintCategory::Assignment,
};

let place_ty = place.ty(&*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, 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)
@@ -1467,7 +1467,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
ref place,
variant_index,
} => {
let place_type = place.ty(&*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,
_ => {
@@ -1489,7 +1489,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
};
}
StatementKind::AscribeUserType(box(ref place, ref projection), variance) => {
let place_ty = place.ty(&*body, tcx).ty;
let place_ty = place.ty(*body, tcx).ty;
if let Err(terr) = self.relate_type_and_user_type(
place_ty,
variance,
@@ -2010,7 +2010,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, 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.
@@ -2064,7 +2064,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, 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
@@ -2093,7 +2093,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

CastKind::Pointer(PointerCast::ClosureFnPointer(unsafety)) => {
let sig = match op.ty(&*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)
}
@@ -2119,7 +2119,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}

CastKind::Pointer(PointerCast::UnsafeFnPointer) => {
let fn_sig = op.ty(&*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
@@ -2151,7 +2151,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, tcx), &[ty.into()]),
substs: tcx.mk_substs_trait(op.ty(*body, tcx), &[ty.into()]),
};

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

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

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

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

CastKind::Misc => {
let ty_from = op.ty(&*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) {
@@ -2339,9 +2339,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, tcx);
let ty_left = left.ty(*body, tcx);
if let ty::RawPtr(_) | ty::FnPtr(_) = ty_left.kind {
let ty_right = right.ty(&*body, tcx);
let ty_right = right.ty(*body, tcx);
let common_ty = self.infcx.next_ty_var(
TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable,
@@ -143,7 +143,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
// derefs, except we stop at the deref of a shared
// reference.

let ty = Place::ty_from(cursor.base, proj_base, &*self.body, self.tcx).ty;
let ty = Place::ty_from(cursor.base, proj_base, *self.body, self.tcx).ty;
match ty.kind {
ty::RawPtr(_) |
ty::Ref(
@@ -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, cx.tcx)
Place::ty_from(place.base, proj_base, *cx.body, cx.tcx)
.projection_ty(cx.tcx, elem)
.ty,
);
@@ -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, 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,
@@ -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, cx.tcx);
let ty = rvalue.ty(*cx.body, cx.tcx);
assert_eq!(Self::in_any_value_of_ty(cx, ty), true);
return true;
}
@@ -77,7 +77,7 @@ where
args: &[mir::Operand<'tcx>],
return_place: &mir::Place<'tcx>,
) {
let return_ty = return_place.ty(&*self.item.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),

0 comments on commit a57aea8

Please sign in to comment.
You can’t perform that action at this time.