Skip to content

Commit 42479d3

Browse files
committed
Remove Place::ty and use NeoPlace::ty instead
1 parent 98a95b8 commit 42479d3

28 files changed

+149
-122
lines changed

src/librustc/mir/tcx.rs

+8-54
Original file line numberDiff line numberDiff line change
@@ -155,57 +155,6 @@ EnumTypeFoldableImpl! {
155155
}
156156
}
157157

158-
impl<'tcx> Place<'tcx> {
159-
pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> PlaceTy<'tcx>
160-
where D: HasLocalDecls<'tcx>
161-
{
162-
match *self {
163-
Place::Local(index) =>
164-
PlaceTy::Ty { ty: local_decls.local_decls()[index].ty },
165-
Place::Promoted(ref data) => PlaceTy::Ty { ty: data.1 },
166-
Place::Static(ref data) =>
167-
PlaceTy::Ty { ty: data.ty },
168-
Place::Projection(ref proj) =>
169-
proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem),
170-
}
171-
}
172-
173-
// If this is a field projection, and the field is being projected from a closure type,
174-
// then returns the index of the field being projected. Note that this closure will always
175-
// be `self` in the current MIR, because that is the only time we directly access the fields
176-
// of a closure type.
177-
//pub fn is_upvar_field_projection<'cx, 'gcx>(&self, mir: &'cx Mir<'tcx>,
178-
// tcx: &TyCtxt<'cx, 'gcx, 'tcx>) -> Option<Field> {
179-
// let (place, by_ref) = if let Place::Projection(ref proj) = self {
180-
// if let ProjectionElem::Deref = proj.elem {
181-
// (&proj.base, true)
182-
// } else {
183-
// (self, false)
184-
// }
185-
// } else {
186-
// (self, false)
187-
// };
188-
189-
// match place {
190-
// Place::Projection(ref proj) => match proj.elem {
191-
// ProjectionElem::Field(field, _ty) => {
192-
// let base_ty = proj.base.ty(mir, *tcx).to_ty(*tcx);
193-
194-
// if (base_ty.is_closure() || base_ty.is_generator()) &&
195-
// (!by_ref || mir.upvar_decls[field.index()].by_ref)
196-
// {
197-
// Some(field)
198-
// } else {
199-
// None
200-
// }
201-
// },
202-
// _ => None,
203-
// }
204-
// _ => None,
205-
// }
206-
//}
207-
}
208-
209158
impl<'tcx> PlaceBase<'tcx> {
210159
pub fn ty(&self, local_decls: &impl HasLocalDecls<'tcx>) -> Ty<'tcx> {
211160
match self {
@@ -376,7 +325,8 @@ impl<'tcx> Rvalue<'tcx> {
376325
tcx.mk_array(operand.ty(local_decls, tcx), count)
377326
}
378327
Rvalue::Ref(reg, bk, ref place) => {
379-
let place_ty = place.ty(local_decls, tcx).to_ty(tcx);
328+
let neo_place = tcx.as_new_place(place);
329+
let place_ty = neo_place.ty(local_decls, tcx).to_ty(tcx);
380330
tcx.mk_ref(reg,
381331
ty::TypeAndMut {
382332
ty: place_ty,
@@ -402,7 +352,8 @@ impl<'tcx> Rvalue<'tcx> {
402352
operand.ty(local_decls, tcx)
403353
}
404354
Rvalue::Discriminant(ref place) => {
405-
let ty = place.ty(local_decls, tcx).to_ty(tcx);
355+
let neo_place = tcx.as_new_place(place);
356+
let ty = neo_place.ty(local_decls, tcx).to_ty(tcx);
406357
if let ty::Adt(adt_def, _) = ty.sty {
407358
adt_def.repr.discr_type().to_ty(tcx)
408359
} else {
@@ -451,7 +402,10 @@ impl<'tcx> Operand<'tcx> {
451402
{
452403
match self {
453404
&Operand::Copy(ref l) |
454-
&Operand::Move(ref l) => l.ty(local_decls, tcx).to_ty(tcx),
405+
&Operand::Move(ref l) => {
406+
let neo_place = tcx.as_new_place(l);
407+
neo_place.ty(local_decls, tcx).to_ty(tcx)
408+
}
455409
&Operand::Constant(ref c) => c.ty,
456410
}
457411
}

src/librustc_codegen_ssa/mir/analyze.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
166166
_ => false
167167
};
168168
if is_consume {
169-
let base_ty = proj.base.ty(self.fx.mir, cx.tcx());
169+
let neo_base = cx.tcx().as_new_place(&proj.base);
170+
let base_ty = neo_base.ty(self.fx.mir, cx.tcx());
170171
let base_ty = self.fx.monomorphize(&base_ty);
171172

172173
// ZSTs don't require any actual memory access.
@@ -245,7 +246,8 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
245246
}
246247

247248
PlaceContext::MutatingUse(MutatingUseContext::Drop) => {
248-
let ty = mir::Place::Local(local).ty(self.fx.mir, self.fx.cx.tcx());
249+
let neo_place = self.fx.cx.tcx().as_new_place(&mir::Place::Local(local));
250+
let ty = neo_place.ty(self.fx.mir, self.fx.cx.tcx());
249251
let ty = self.fx.monomorphize(&ty.to_ty(self.fx.cx.tcx()));
250252

251253
// Only need the place if we're actually dropping it.

src/librustc_codegen_ssa/mir/block.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
287287
}
288288

289289
mir::TerminatorKind::Drop { ref location, target, unwind } => {
290-
let ty = location.ty(self.mir, bx.tcx()).to_ty(bx.tcx());
290+
let neo_location = bx.tcx().as_new_place(location);
291+
let ty = neo_location.ty(self.mir, bx.tcx()).to_ty(bx.tcx());
291292
let ty = self.monomorphize(&ty);
292293
let drop_fn = monomorphize::resolve_drop_in_place(bx.tcx(), ty);
293294

src/librustc_codegen_ssa/mir/place.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
490490

491491
pub fn monomorphized_place_ty(&self, place: &mir::Place<'tcx>) -> Ty<'tcx> {
492492
let tcx = self.cx.tcx();
493-
let place_ty = place.ty(self.mir, tcx);
493+
let neo_place = tcx.as_new_place(place);
494+
let place_ty = neo_place.ty(self.mir, tcx);
494495
self.monomorphize(&place_ty.to_ty(tcx))
495496
}
496497
}

src/librustc_mir/borrow_check/error_reporting.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
182182
);
183183
}
184184

185-
let ty = used_place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
185+
let neo_place = self.infcx.tcx.as_new_place(used_place);
186+
let ty = neo_place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
186187
let needs_note = match ty.sty {
187188
ty::Closure(id, _) => {
188189
let tables = self.infcx.tcx.typeck_tables_of(id);
@@ -197,11 +198,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
197198
if needs_note {
198199
let mpi = self.move_data.moves[move_out_indices[0]].path;
199200
let place = &self.move_data.move_paths[mpi].place;
201+
let neo_place = self.infcx.tcx.as_new_place(place);
200202

201-
let ty = place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
202-
let opt_name = self.describe_place_with_options(place, IncludingDowncast(true));
203-
let note_msg = match opt_name {
204-
Some(ref name) => format!("`{}`", name),
203+
let ty = neo_place.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
204+
let note_msg = match self.describe_place_with_options(
205+
place,
206+
IncludingDowncast(true),
207+
) {
208+
Some(name) => format!("`{}`", name),
205209
None => "value".to_owned(),
206210
};
207211
if let ty::TyKind::Param(param_ty) = ty.sty {
@@ -574,7 +578,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
574578
// Define a small closure that we can use to check if the type of a place
575579
// is a union.
576580
let is_union = |place: &Place<'tcx>| -> bool {
577-
place.ty(self.mir, self.infcx.tcx)
581+
let neo_place = self.infcx.tcx.as_new_place(place);
582+
neo_place.ty(self.mir, self.infcx.tcx)
578583
.to_ty(self.infcx.tcx)
579584
.ty_adt_def()
580585
.map(|adt| adt.is_union())
@@ -624,7 +629,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
624629

625630
// Also compute the name of the union type, eg. `Foo` so we
626631
// can add a helpful note with it.
627-
let ty = base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
632+
let neo_base = self.infcx.tcx.as_new_place(base);
633+
let ty = neo_base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
628634

629635
return Some((desc_base, desc_first, desc_second, ty.to_string()));
630636
},

src/librustc_mir/borrow_check/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
629629
let gcx = self.infcx.tcx.global_tcx();
630630

631631
// Compute the type with accurate region information.
632-
let drop_place_ty = drop_place.ty(self.mir, self.infcx.tcx);
632+
let neo_drop_place = self.infcx.tcx.as_new_place(drop_place);
633+
let drop_place_ty = neo_drop_place.ty(self.mir, self.infcx.tcx);
633634

634635
// Erase the regions.
635636
let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty)
@@ -1661,7 +1662,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16611662
// assigning to `P.f` requires `P` itself
16621663
// be already initialized
16631664
let tcx = self.infcx.tcx;
1664-
match base.ty(self.mir, tcx).to_ty(tcx).sty {
1665+
let neo_base = tcx.as_new_place(base);
1666+
match neo_base.ty(self.mir, tcx).to_ty(tcx).sty {
16651667
ty::Adt(def, _) if def.has_dtor(tcx) => {
16661668
self.check_if_path_or_subpath_is_moved(
16671669
context, InitializationRequiringAction::Assignment,
@@ -1766,7 +1768,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17661768
// no move out from an earlier location) then this is an attempt at initialization
17671769
// of the union - we should error in that case.
17681770
let tcx = this.infcx.tcx;
1769-
if let ty::TyKind::Adt(def, _) = base.ty(this.mir, tcx).to_ty(tcx).sty {
1771+
let neo_base = tcx.as_new_place(base);
1772+
if let ty::TyKind::Adt(def, _) = neo_base.ty(this.mir, tcx).to_ty(tcx).sty {
17701773
if def.is_union() {
17711774
if this.move_data.path_map[mpi].iter().any(|moi| {
17721775
this.move_data.moves[*moi].source.is_predecessor_of(
@@ -2032,7 +2035,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
20322035
Place::Projection(ref proj) => {
20332036
match proj.elem {
20342037
ProjectionElem::Deref => {
2035-
let base_ty = proj.base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
2038+
let neo_base = self.infcx.tcx.as_new_place(&proj.base);
2039+
let base_ty = neo_base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx);
20362040

20372041
// Check the kind of deref to decide
20382042
match base_ty.sty {

src/librustc_mir/borrow_check/mutability_errors.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
6161
base,
6262
elem: ProjectionElem::Field(upvar_index, _),
6363
}) => {
64+
let neo_base = self.infcx.tcx.as_new_place(base);
6465
debug_assert!(is_closure_or_generator(
65-
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx)
66+
neo_base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx)
6667
));
6768

6869
item_msg = format!("`{}`", access_place_desc.unwrap());
@@ -82,8 +83,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
8283
if *base == Place::Local(Local::new(1)) && !self.mir.upvar_decls.is_empty() {
8384
item_msg = format!("`{}`", access_place_desc.unwrap());
8485
debug_assert!(self.mir.local_decls[Local::new(1)].ty.is_region_ptr());
86+
let neo_the_place_err = self.infcx.tcx.as_new_place(the_place_err);
8587
debug_assert!(is_closure_or_generator(
86-
the_place_err.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx)
88+
neo_the_place_err.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx)
8789
));
8890
let neo_place = self.infcx.tcx.as_new_place(access_place);
8991
reason = if neo_place.is_upvar_field_projection(self.mir,
@@ -107,12 +109,16 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
107109
item_msg = format!("`{}`", access_place_desc.unwrap());
108110
reason = ", as it is immutable for the pattern guard".to_string();
109111
} else {
110-
let pointer_type =
111-
if base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx).is_region_ptr() {
112-
"`&` reference"
113-
} else {
114-
"`*const` pointer"
115-
};
112+
let neo_base = self.infcx.tcx.as_new_place(base);
113+
let pointer_type = if neo_base
114+
.ty(self.mir, self.infcx.tcx)
115+
.to_ty(self.infcx.tcx)
116+
.is_region_ptr()
117+
{
118+
"`&` reference"
119+
} else {
120+
"`*const` pointer"
121+
};
116122
if let Some(desc) = access_place_desc {
117123
item_msg = format!("`{}`", desc);
118124
reason = match error_access {
@@ -227,9 +233,10 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
227233
}) => {
228234
err.span_label(span, format!("cannot {ACT}", ACT = act));
229235

236+
let neo_base = self.infcx.tcx.as_new_place(base);
230237
if let Some((span, message)) = annotate_struct_field(
231238
self.infcx.tcx,
232-
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx),
239+
neo_base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx),
233240
field,
234241
) {
235242
err.span_suggestion(
@@ -299,8 +306,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
299306
base,
300307
elem: ProjectionElem::Field(upvar_index, _),
301308
}) => {
309+
let neo_base = self.infcx.tcx.as_new_place(base);
302310
debug_assert!(is_closure_or_generator(
303-
base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx)
311+
neo_base.ty(self.mir, self.infcx.tcx).to_ty(self.infcx.tcx)
304312
));
305313

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

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

+14-7
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,8 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
553553
}
554554
}
555555
ProjectionElem::Index(i) => {
556-
let index_ty = Place::Local(i).ty(self.mir, tcx).to_ty(tcx);
556+
let neo_place = tcx.as_new_place(&Place::Local(i));
557+
let index_ty = neo_place.ty(self.mir, tcx).to_ty(tcx);
557558
if index_ty != tcx.types.usize {
558559
PlaceTy::Ty {
559560
ty: span_mirbug_and_err!(self, i, "index by non-usize {:?}", i),
@@ -1257,7 +1258,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12571258
_ => ConstraintCategory::Assignment,
12581259
};
12591260

1260-
let place_ty = place.ty(mir, tcx).to_ty(tcx);
1261+
let neo_place = tcx.as_new_place(place);
1262+
let place_ty = neo_place.ty(mir, tcx).to_ty(tcx);
12611263
let rv_ty = rv.ty(mir, tcx);
12621264
if let Err(terr) =
12631265
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
@@ -1309,7 +1311,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13091311
ref place,
13101312
variant_index,
13111313
} => {
1312-
let place_type = place.ty(mir, tcx).to_ty(tcx);
1314+
let neo_place = tcx.as_new_place(place);
1315+
let place_type = neo_place.ty(mir, tcx).to_ty(tcx);
13131316
let adt = match place_type.sty {
13141317
TyKind::Adt(adt, _) if adt.is_enum() => adt,
13151318
_ => {
@@ -1331,7 +1334,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13311334
};
13321335
}
13331336
StatementKind::AscribeUserType(ref place, variance, box ref projection) => {
1334-
let place_ty = place.ty(mir, tcx).to_ty(tcx);
1337+
let neo_place = tcx.as_new_place(place);
1338+
let place_ty = neo_place.ty(mir, tcx).to_ty(tcx);
13351339
if let Err(terr) = self.relate_type_and_user_type(
13361340
place_ty,
13371341
variance,
@@ -1387,7 +1391,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13871391
target: _,
13881392
unwind: _,
13891393
} => {
1390-
let place_ty = location.ty(mir, tcx).to_ty(tcx);
1394+
let neo_place = tcx.as_new_place(location);
1395+
let place_ty = neo_place.ty(mir, tcx).to_ty(tcx);
13911396
let rv_ty = value.ty(mir, tcx);
13921397

13931398
let locations = term_location.to_locations();
@@ -1535,7 +1540,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
15351540
let tcx = self.tcx();
15361541
match *destination {
15371542
Some((ref dest, _target_block)) => {
1538-
let dest_ty = dest.ty(mir, tcx).to_ty(tcx);
1543+
let neo_place = tcx.as_new_place(dest);
1544+
let dest_ty = neo_place.ty(mir, tcx).to_ty(tcx);
15391545
let category = match *dest {
15401546
Place::Local(RETURN_PLACE) => {
15411547
if let Some(BorrowCheckContext {
@@ -2137,7 +2143,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
21372143
match *elem {
21382144
ProjectionElem::Deref => {
21392145
let tcx = self.infcx.tcx;
2140-
let base_ty = base.ty(self.mir, tcx).to_ty(tcx);
2146+
let neo_base = tcx.as_new_place(base);
2147+
let base_ty = neo_base.ty(self.mir, tcx).to_ty(tcx);
21412148

21422149
debug!("add_reborrow_constraint - base_ty = {:?}", base_ty);
21432150
match base_ty.sty {

src/librustc_mir/borrow_check/prefixes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ impl<'cx, 'gcx, 'tcx> Iterator for Prefixes<'cx, 'gcx, 'tcx> {
132132
// derefs, except we stop at the deref of a shared
133133
// reference.
134134

135-
let ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
135+
let neo_base = self.tcx.as_new_place(&proj.base);
136+
let ty = neo_base.ty(self.mir, self.tcx).to_ty(self.tcx);
136137
match ty.sty {
137138
ty::RawPtr(_) |
138139
ty::Ref(

src/librustc_mir/build/block.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
165165
// Then, the block may have an optional trailing expression which is a “return” value
166166
// of the block, which is stored into `destination`.
167167
let tcx = this.hir.tcx();
168-
let destination_ty = destination.ty(&this.local_decls, tcx).to_ty(tcx);
168+
let neo_place = tcx.as_new_place(destination);
169+
let destination_ty = neo_place.ty(&this.local_decls, tcx).to_ty(tcx);
169170
if let Some(expr) = expr {
170171
let tail_result_is_ignored = destination_ty.is_unit() ||
171172
this.block_context.currently_ignores_tail_results();

0 commit comments

Comments
 (0)