Skip to content

Commit 3382771

Browse files
Rollup merge of #81072 - RalfJung:place-ref-ty, r=oli-obk
PlaceRef::ty: use method call syntax
2 parents 7635462 + 1b09dc2 commit 3382771

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
119119
)
120120
);
121121
if is_consume {
122-
let base_ty = mir::PlaceRef::ty(&place_base, self.fx.mir, cx.tcx());
122+
let base_ty = place_base.ty(self.fx.mir, cx.tcx());
123123
let base_ty = self.fx.monomorphize(base_ty);
124124

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

compiler/rustc_codegen_ssa/src/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
506506

507507
pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'tcx>) -> Ty<'tcx> {
508508
let tcx = self.cx.tcx();
509-
let place_ty = mir::PlaceRef::ty(&place_ref, self.mir, tcx);
509+
let place_ty = place_ref.ty(self.mir, tcx);
510510
self.monomorphize(place_ty.ty)
511511
}
512512
}

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
289289
);
290290
}
291291

292-
let ty = PlaceRef::ty(&used_place, self.body, self.infcx.tcx).ty;
292+
let ty = used_place.ty(self.body, self.infcx.tcx).ty;
293293
let needs_note = match ty.kind() {
294294
ty::Closure(id, _) => {
295295
let tables = self.infcx.tcx.typeck(id.expect_local());
@@ -728,6 +728,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
728728
// Define a small closure that we can use to check if the type of a place
729729
// is a union.
730730
let union_ty = |place_base| {
731+
// Need to use fn call syntax `PlaceRef::ty` to determine the type of `place_base`;
732+
// using a type annotation in the closure argument instead leads to a lifetime error.
731733
let ty = PlaceRef::ty(&place_base, self.body, self.infcx.tcx).ty;
732734
ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
733735
};

compiler/rustc_mir/src/borrow_check/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17431743
if let Some((place_base, ProjectionElem::Subslice { from, to, from_end: false })) =
17441744
place_span.0.last_projection()
17451745
{
1746-
let place_ty = PlaceRef::ty(&place_base, self.body(), self.infcx.tcx);
1746+
let place_ty = place_base.ty(self.body(), self.infcx.tcx);
17471747
if let ty::Array(..) = place_ty.ty.kind() {
17481748
self.check_if_subslice_element_is_moved(
17491749
location,
@@ -1854,7 +1854,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18541854
// assigning to `P.f` requires `P` itself
18551855
// be already initialized
18561856
let tcx = self.infcx.tcx;
1857-
let base_ty = PlaceRef::ty(&place_base, self.body(), tcx).ty;
1857+
let base_ty = place_base.ty(self.body(), tcx).ty;
18581858
match base_ty.kind() {
18591859
ty::Adt(def, _) if def.has_dtor(tcx) => {
18601860
self.check_if_path_or_subpath_is_moved(
@@ -1951,7 +1951,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19511951
// no move out from an earlier location) then this is an attempt at initialization
19521952
// of the union - we should error in that case.
19531953
let tcx = this.infcx.tcx;
1954-
if let ty::Adt(def, _) = PlaceRef::ty(&base, this.body(), tcx).ty.kind() {
1954+
if let ty::Adt(def, _) = base.ty(this.body(), tcx).ty.kind() {
19551955
if def.is_union() {
19561956
if this.move_data.path_map[mpi].iter().any(|moi| {
19571957
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
@@ -2173,7 +2173,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21732173
Some((place_base, elem)) => {
21742174
match elem {
21752175
ProjectionElem::Deref => {
2176-
let base_ty = PlaceRef::ty(&place_base, self.body(), self.infcx.tcx).ty;
2176+
let base_ty = place_base.ty(self.body(), self.infcx.tcx).ty;
21772177

21782178
// Check the kind of deref to decide
21792179
match base_ty.kind() {

compiler/rustc_mir/src/borrow_check/prefixes.rs

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

120-
let ty = PlaceRef::ty(&cursor_base, self.body, self.tcx).ty;
120+
let ty = cursor_base.ty(self.body, self.tcx).ty;
121121
match ty.kind() {
122122
ty::RawPtr(_) | ty::Ref(_ /*rgn*/, _ /*ty*/, hir::Mutability::Not) => {
123123
// don't continue traversing over derefs of raw pointers or shared

0 commit comments

Comments
 (0)