Skip to content

Commit 22a4827

Browse files
committed
Place::ty_from takes local by value
1 parent b5b6be0 commit 22a4827

File tree

20 files changed

+47
-47
lines changed

20 files changed

+47
-47
lines changed

src/librustc/mir/tcx.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'tcx> PlaceTy<'tcx> {
114114

115115
impl<'tcx> Place<'tcx> {
116116
pub fn ty_from<D>(
117-
local: &Local,
117+
local: Local,
118118
projection: &[PlaceElem<'tcx>],
119119
local_decls: &D,
120120
tcx: TyCtxt<'tcx>,
@@ -124,7 +124,7 @@ impl<'tcx> Place<'tcx> {
124124
{
125125
projection
126126
.iter()
127-
.fold(PlaceTy::from_ty(local_decls.local_decls()[*local].ty), |place_ty, elem| {
127+
.fold(PlaceTy::from_ty(local_decls.local_decls()[local].ty), |place_ty, elem| {
128128
place_ty.projection_ty(tcx, elem)
129129
})
130130
}
@@ -133,7 +133,7 @@ impl<'tcx> Place<'tcx> {
133133
where
134134
D: HasLocalDecls<'tcx>,
135135
{
136-
Place::ty_from(&self.local, &self.projection, local_decls, tcx)
136+
Place::ty_from(self.local, &self.projection, local_decls, tcx)
137137
}
138138
}
139139

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
128128
};
129129
if is_consume {
130130
let base_ty =
131-
mir::Place::ty_from(&place_ref.local, proj_base, *self.fx.mir, cx.tcx());
131+
mir::Place::ty_from(place_ref.local, proj_base, *self.fx.mir, cx.tcx());
132132
let base_ty = self.fx.monomorphize(&base_ty);
133133

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

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
499499

500500
pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'_, 'tcx>) -> Ty<'tcx> {
501501
let tcx = self.cx.tcx();
502-
let place_ty = mir::Place::ty_from(&place_ref.local, place_ref.projection, *self.mir, tcx);
502+
let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, *self.mir, tcx);
503503
self.monomorphize(&place_ty.ty)
504504
}
505505
}

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
186186
}
187187

188188
let ty =
189-
Place::ty_from(&used_place.local, used_place.projection, *self.body, self.infcx.tcx)
189+
Place::ty_from(used_place.local, used_place.projection, *self.body, self.infcx.tcx)
190190
.ty;
191191
let needs_note = match ty.kind {
192192
ty::Closure(id, _) => {
@@ -604,7 +604,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
604604
cursor = proj_base;
605605

606606
match elem {
607-
ProjectionElem::Field(field, _) if union_ty(local, proj_base).is_some() => {
607+
ProjectionElem::Field(field, _) if union_ty(*local, proj_base).is_some() => {
608608
return Some((PlaceRef { local: *local, projection: proj_base }, field));
609609
}
610610
_ => {}
@@ -622,7 +622,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
622622
cursor = proj_base;
623623

624624
if let ProjectionElem::Field(field, _) = elem {
625-
if let Some(union_ty) = union_ty(local, proj_base) {
625+
if let Some(union_ty) = union_ty(*local, proj_base) {
626626
if field != target_field
627627
&& *local == target_base.local
628628
&& proj_base == target_base.projection
@@ -1513,7 +1513,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15131513
StorageDeadOrDrop::LocalStorageDead
15141514
| StorageDeadOrDrop::BoxedStorageDead => {
15151515
assert!(
1516-
Place::ty_from(&place.local, proj_base, *self.body, tcx)
1516+
Place::ty_from(place.local, proj_base, *self.body, tcx)
15171517
.ty
15181518
.is_box(),
15191519
"Drop of value behind a reference or raw pointer"
@@ -1523,7 +1523,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15231523
StorageDeadOrDrop::Destructor(_) => base_access,
15241524
},
15251525
ProjectionElem::Field(..) | ProjectionElem::Downcast(..) => {
1526-
let base_ty = Place::ty_from(&place.local, proj_base, *self.body, tcx).ty;
1526+
let base_ty = Place::ty_from(place.local, proj_base, *self.body, tcx).ty;
15271527
match base_ty.kind {
15281528
ty::Adt(def, _) if def.has_dtor(tcx) => {
15291529
// Report the outermost adt with a destructor

src/librustc_mir/borrow_check/diagnostics/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
316316
}
317317
ProjectionElem::Downcast(_, variant_index) => {
318318
let base_ty =
319-
Place::ty_from(&place.local, place.projection, *self.body, self.infcx.tcx)
319+
Place::ty_from(place.local, place.projection, *self.body, self.infcx.tcx)
320320
.ty;
321321
self.describe_field_from_ty(&base_ty, field, Some(*variant_index))
322322
}
@@ -447,7 +447,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
447447

448448
// If we didn't find an overloaded deref or index, then assume it's a
449449
// built in deref and check the type of the base.
450-
let base_ty = Place::ty_from(&deref_base.local, deref_base.projection, *self.body, tcx).ty;
450+
let base_ty = Place::ty_from(deref_base.local, deref_base.projection, *self.body, tcx).ty;
451451
if base_ty.is_unsafe_ptr() {
452452
BorrowedContentSource::DerefRawPointer
453453
} else if base_ty.is_mutable_ptr() {

src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
5757
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
5858
} => {
5959
debug_assert!(is_closure_or_generator(
60-
Place::ty_from(&local, proj_base, *self.body, self.infcx.tcx).ty
60+
Place::ty_from(local, proj_base, *self.body, self.infcx.tcx).ty
6161
));
6262

6363
item_msg = format!("`{}`", access_place_desc.unwrap());
@@ -101,7 +101,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
101101
debug_assert!(self.body.local_decls[Local::new(1)].ty.is_region_ptr());
102102
debug_assert!(is_closure_or_generator(
103103
Place::ty_from(
104-
&the_place_err.local,
104+
the_place_err.local,
105105
the_place_err.projection,
106106
*self.body,
107107
self.infcx.tcx
@@ -195,7 +195,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
195195

196196
if let Some((span, message)) = annotate_struct_field(
197197
self.infcx.tcx,
198-
Place::ty_from(&local, proj_base, *self.body, self.infcx.tcx).ty,
198+
Place::ty_from(local, proj_base, *self.body, self.infcx.tcx).ty,
199199
field,
200200
) {
201201
err.span_suggestion(
@@ -271,7 +271,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
271271
projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)],
272272
} => {
273273
debug_assert!(is_closure_or_generator(
274-
Place::ty_from(&local, proj_base, *self.body, self.infcx.tcx).ty
274+
Place::ty_from(local, proj_base, *self.body, self.infcx.tcx).ty
275275
));
276276

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

src/librustc_mir/borrow_check/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16231623
place_span.0.projection
16241624
{
16251625
let place_ty =
1626-
Place::ty_from(&place_span.0.local, base_proj, self.body(), self.infcx.tcx);
1626+
Place::ty_from(place_span.0.local, base_proj, self.body(), self.infcx.tcx);
16271627
if let ty::Array(..) = place_ty.ty.kind {
16281628
let array_place = PlaceRef { local: place_span.0.local, projection: base_proj };
16291629
self.check_if_subslice_element_is_moved(
@@ -1740,7 +1740,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17401740
// assigning to `P.f` requires `P` itself
17411741
// be already initialized
17421742
let tcx = self.infcx.tcx;
1743-
let base_ty = Place::ty_from(&place.local, proj_base, self.body(), tcx).ty;
1743+
let base_ty = Place::ty_from(place.local, proj_base, self.body(), tcx).ty;
17441744
match base_ty.kind {
17451745
ty::Adt(def, _) if def.has_dtor(tcx) => {
17461746
self.check_if_path_or_subpath_is_moved(
@@ -1844,7 +1844,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18441844
// of the union - we should error in that case.
18451845
let tcx = this.infcx.tcx;
18461846
if let ty::Adt(def, _) =
1847-
Place::ty_from(&base.local, base.projection, this.body(), tcx).ty.kind
1847+
Place::ty_from(base.local, base.projection, this.body(), tcx).ty.kind
18481848
{
18491849
if def.is_union() {
18501850
if this.move_data.path_map[mpi].iter().any(|moi| {
@@ -2058,7 +2058,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20582058
match elem {
20592059
ProjectionElem::Deref => {
20602060
let base_ty =
2061-
Place::ty_from(&place.local, proj_base, self.body(), self.infcx.tcx).ty;
2061+
Place::ty_from(place.local, proj_base, self.body(), self.infcx.tcx).ty;
20622062

20632063
// Check the kind of deref to decide
20642064
match base_ty.kind {
@@ -2192,7 +2192,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21922192
match place_projection {
21932193
[base @ .., ProjectionElem::Field(field, _ty)] => {
21942194
let tcx = self.infcx.tcx;
2195-
let base_ty = Place::ty_from(&place_ref.local, base, self.body(), tcx).ty;
2195+
let base_ty = Place::ty_from(place_ref.local, base, self.body(), tcx).ty;
21962196

21972197
if (base_ty.is_closure() || base_ty.is_generator())
21982198
&& (!by_ref || self.upvars[field.index()].by_ref)

src/librustc_mir/borrow_check/place_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
4848
let proj_base = &self.projection[..i];
4949

5050
if *elem == ProjectionElem::Deref {
51-
let ty = Place::ty_from(&self.local, proj_base, body, tcx).ty;
51+
let ty = Place::ty_from(self.local, proj_base, body, tcx).ty;
5252
match ty.kind {
5353
ty::Ref(_, _, hir::Mutability::Not) if i == 0 => {
5454
// For references to thread-local statics, we do need

src/librustc_mir/borrow_check/places_conflict.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn place_components_conflict<'tcx>(
208208
// access cares about.
209209

210210
let proj_base = &borrow_place.projection[..access_place.projection.len() + i];
211-
let base_ty = Place::ty_from(&borrow_local, proj_base, body, tcx).ty;
211+
let base_ty = Place::ty_from(borrow_local, proj_base, body, tcx).ty;
212212

213213
match (elem, &base_ty.kind, access) {
214214
(_, _, Shallow(Some(ArtificialField::ArrayLength)))
@@ -329,7 +329,7 @@ fn place_projection_conflict<'tcx>(
329329
debug!("place_element_conflict: DISJOINT-OR-EQ-FIELD");
330330
Overlap::EqualOrDisjoint
331331
} else {
332-
let ty = Place::ty_from(&pi1_local, pi1_proj_base, body, tcx).ty;
332+
let ty = Place::ty_from(pi1_local, pi1_proj_base, body, tcx).ty;
333333
match ty.kind {
334334
ty::Adt(def, _) if def.is_union() => {
335335
// Different fields of a union, we are basically stuck.

src/librustc_mir/borrow_check/prefixes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
120120
// derefs, except we stop at the deref of a shared
121121
// reference.
122122

123-
let ty = Place::ty_from(&cursor.local, proj_base, *self.body, self.tcx).ty;
123+
let ty = Place::ty_from(cursor.local, proj_base, *self.body, self.tcx).ty;
124124
match ty.kind {
125125
ty::RawPtr(_) | ty::Ref(_ /*rgn*/, _ /*ty*/, hir::Mutability::Not) => {
126126
// don't continue traversing over derefs of raw pointers or shared

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23902390
match elem {
23912391
ProjectionElem::Deref => {
23922392
let tcx = self.infcx.tcx;
2393-
let base_ty = Place::ty_from(&borrowed_place.local, proj_base, body, tcx).ty;
2393+
let base_ty = Place::ty_from(borrowed_place.local, proj_base, body, tcx).ty;
23942394

23952395
debug!("add_reborrow_constraint - base_ty = {:?}", base_ty);
23962396
match base_ty.kind {

src/librustc_mir/dataflow/move_paths/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
109109
let proj_base = &place.projection[..i];
110110
let body = self.builder.body;
111111
let tcx = self.builder.tcx;
112-
let place_ty = Place::ty_from(&place.local, proj_base, body, tcx).ty;
112+
let place_ty = Place::ty_from(place.local, proj_base, body, tcx).ty;
113113
match place_ty.kind {
114114
ty::Ref(..) | ty::RawPtr(..) => {
115115
let proj = &place.projection[..i + 1];
@@ -490,7 +490,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
490490
// of the union so it is marked as initialized again.
491491
if let [proj_base @ .., ProjectionElem::Field(_, _)] = place.projection {
492492
if let ty::Adt(def, _) =
493-
Place::ty_from(&place.local, proj_base, self.builder.body, self.builder.tcx).ty.kind
493+
Place::ty_from(place.local, proj_base, self.builder.body, self.builder.tcx).ty.kind
494494
{
495495
if def.is_union() {
496496
place = PlaceRef { local: place.local, projection: proj_base }

src/librustc_mir/transform/check_consts/qualifs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub trait Qualif {
4646
let qualif = base_qualif
4747
&& Self::in_any_value_of_ty(
4848
cx,
49-
Place::ty_from(&place.local, proj_base, *cx.body, cx.tcx)
49+
Place::ty_from(place.local, proj_base, *cx.body, cx.tcx)
5050
.projection_ty(cx.tcx, elem)
5151
.ty,
5252
);
@@ -149,7 +149,7 @@ pub trait Qualif {
149149
Rvalue::Ref(_, _, ref place) | Rvalue::AddressOf(_, ref place) => {
150150
// Special-case reborrows to be more like a copy of the reference.
151151
if let [proj_base @ .., ProjectionElem::Deref] = place.projection.as_ref() {
152-
let base_ty = Place::ty_from(&place.local, proj_base, *cx.body, cx.tcx).ty;
152+
let base_ty = Place::ty_from(place.local, proj_base, *cx.body, cx.tcx).ty;
153153
if let ty::Ref(..) = base_ty.kind {
154154
return Self::in_place(
155155
cx,

src/librustc_mir/transform/check_consts/validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
448448

449449
match elem {
450450
ProjectionElem::Deref => {
451-
let base_ty = Place::ty_from(place_local, proj_base, *self.body, self.tcx).ty;
451+
let base_ty = Place::ty_from(*place_local, proj_base, *self.body, self.tcx).ty;
452452
if let ty::RawPtr(_) = base_ty.kind {
453453
if proj_base.is_empty() {
454454
if let (local, []) = (place_local, proj_base) {
@@ -472,7 +472,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
472472
| ProjectionElem::Subslice { .. }
473473
| ProjectionElem::Field(..)
474474
| ProjectionElem::Index(_) => {
475-
let base_ty = Place::ty_from(place_local, proj_base, *self.body, self.tcx).ty;
475+
let base_ty = Place::ty_from(*place_local, proj_base, *self.body, self.tcx).ty;
476476
match base_ty.ty_adt_def() {
477477
Some(def) if def.is_union() => {
478478
self.check_op(ops::UnionAccess);
@@ -664,7 +664,7 @@ fn place_as_reborrow(
664664
//
665665
// This is sufficient to prevent an access to a `static mut` from being marked as a
666666
// reborrow, even if the check above were to disappear.
667-
let inner_ty = Place::ty_from(&place.local, inner, body, tcx).ty;
667+
let inner_ty = Place::ty_from(place.local, inner, body, tcx).ty;
668668
match inner_ty.kind {
669669
ty::Ref(..) => Some(inner),
670670
_ => None,

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
215215
}
216216
}
217217
let is_borrow_of_interior_mut = context.is_borrow()
218-
&& !Place::ty_from(&place.local, proj_base, self.body, self.tcx).ty.is_freeze(
218+
&& !Place::ty_from(place.local, proj_base, self.body, self.tcx).ty.is_freeze(
219219
self.tcx,
220220
self.param_env,
221221
self.source_info.span,
@@ -260,7 +260,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
260260
}
261261
}
262262
}
263-
let base_ty = Place::ty_from(&place.local, proj_base, self.body, self.tcx).ty;
263+
let base_ty = Place::ty_from(place.local, proj_base, self.body, self.tcx).ty;
264264
match base_ty.kind {
265265
ty::RawPtr(..) => self.require_unsafe(
266266
"dereference of raw pointer",
@@ -414,7 +414,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
414414
match elem {
415415
ProjectionElem::Field(..) => {
416416
let ty =
417-
Place::ty_from(&place.local, proj_base, &self.body.local_decls, self.tcx)
417+
Place::ty_from(place.local, proj_base, &self.body.local_decls, self.tcx)
418418
.ty;
419419
match ty.kind {
420420
ty::Adt(def, _) => match self.tcx.layout_scalar_valid_range(def.did) {

src/librustc_mir/transform/instcombine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
9595
if let PlaceRef { local, projection: &[ref proj_base @ .., ProjectionElem::Deref] } =
9696
place.as_ref()
9797
{
98-
if Place::ty_from(&local, proj_base, self.body, self.tcx).ty.is_region_ptr() {
98+
if Place::ty_from(local, proj_base, self.body, self.tcx).ty.is_region_ptr() {
9999
self.optimizations.and_stars.insert(location);
100100
}
101101
}

0 commit comments

Comments
 (0)