1 //! See docs in build/expr/mod.rs
3 use crate::build::expr::category::Category;
4 use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
5 use crate::build::{BlockAnd, BlockAndExtension, Builder, Capture, CaptureMap};
6 use rustc_hir::def_id::LocalDefId;
7 use rustc_middle::hir::place::Projection as HirProjection;
8 use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
9 use rustc_middle::middle::region;
10 use rustc_middle::mir::tcx::PlaceTy;
11 use rustc_middle::mir::AssertKind::BoundsCheck;
12 use rustc_middle::mir::*;
13 use rustc_middle::thir::*;
14 use rustc_middle::ty::AdtDef;
15 use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, TyCtxt, Variance};
17 use rustc_target::abi::VariantIdx;
19 use rustc_index::vec::Idx;
21 use std::assert_matches::assert_matches;
24 /// The "outermost" place that holds this value.
25 #[derive(Copy, Clone, Debug, PartialEq)]
26 pub(crate) enum PlaceBase {
27 /// Denotes the start of a `Place`.
30 /// When building place for an expression within a closure, the place might start off a
31 /// captured path. When `capture_disjoint_fields` is enabled, we might not know the capture
32 /// index (within the desugared closure) of the captured path until most of the projections
33 /// are applied. We use `PlaceBase::Upvar` to keep track of the root variable off of which the
34 /// captured path starts, the closure the capture belongs to and the trait the closure
37 /// Once we have figured out the capture index, we can convert the place builder to start from
38 /// `PlaceBase::Local`.
40 /// Consider the following example
42 /// let t = (((10, 10), 10), 10);
45 /// println!("{}", t.0.0.0);
48 /// Here the THIR expression for `t.0.0.0` will be something like
50 /// ```ignore (illustrative)
57 /// When `capture_disjoint_fields` is enabled, `t.0.0.0` is captured and we won't be able to
58 /// figure out that it is captured until all the `Field` projections are applied.
60 /// HirId of the upvar
61 var_hir_id: LocalVarId,
62 /// DefId of the closure
63 closure_def_id: LocalDefId,
67 /// `PlaceBuilder` is used to create places during MIR construction. It allows you to "build up" a
68 /// place by pushing more and more projections onto the end, and then convert the final set into a
69 /// place using the `to_place` method.
71 /// This is used internally when building a place for an expression like `a.b.c`. The fields `b`
72 /// and `c` can be progressively pushed onto the place builder that is created when converting `a`.
73 #[derive(Clone, Debug, PartialEq)]
74 pub(in crate::build) struct PlaceBuilder<'tcx> {
76 projection: Vec<PlaceElem<'tcx>>,
79 /// Given a list of MIR projections, convert them to list of HIR ProjectionKind.
80 /// The projections are truncated to represent a path that might be captured by a
81 /// closure/generator. This implies the vector returned from this function doesn't contain
82 /// ProjectionElems `Downcast`, `ConstantIndex`, `Index`, or `Subslice` because those will never be
83 /// part of a path that is captured by a closure. We stop applying projections once we see the first
84 /// projection that isn't captured by a closure.
85 fn convert_to_hir_projections_and_truncate_for_capture<'tcx>(
86 mir_projections: &[PlaceElem<'tcx>],
87 ) -> Vec<HirProjectionKind> {
88 let mut hir_projections = Vec::new();
89 let mut variant = None;
91 for mir_projection in mir_projections {
92 let hir_projection = match mir_projection {
93 ProjectionElem::Deref => HirProjectionKind::Deref,
94 ProjectionElem::Field(field, _) => {
95 let variant = variant.unwrap_or(VariantIdx::new(0));
96 HirProjectionKind::Field(field.index() as u32, variant)
98 ProjectionElem::Downcast(.., idx) => {
99 // We don't expect to see multi-variant enums here, as earlier
100 // phases will have truncated them already. However, there can
101 // still be downcasts, thanks to single-variant enums.
102 // We keep track of VariantIdx so we can use this information
103 // if the next ProjectionElem is a Field.
104 variant = Some(*idx);
107 // These do not affect anything, they just make sure we know the right type.
108 ProjectionElem::OpaqueCast(_) => continue,
109 ProjectionElem::Index(..)
110 | ProjectionElem::ConstantIndex { .. }
111 | ProjectionElem::Subslice { .. } => {
112 // We don't capture array-access projections.
113 // We can stop here as arrays are captured completely.
118 hir_projections.push(hir_projection);
124 /// Return true if the `proj_possible_ancestor` represents an ancestor path
125 /// to `proj_capture` or `proj_possible_ancestor` is same as `proj_capture`,
126 /// assuming they both start off of the same root variable.
128 /// **Note:** It's the caller's responsibility to ensure that both lists of projections
129 /// start off of the same root variable.
131 /// Eg: 1. `foo.x` which is represented using `projections=[Field(x)]` is an ancestor of
132 /// `foo.x.y` which is represented using `projections=[Field(x), Field(y)]`.
133 /// Note both `foo.x` and `foo.x.y` start off of the same root variable `foo`.
134 /// 2. Since we only look at the projections here function will return `bar.x` as an a valid
135 /// ancestor of `foo.x.y`. It's the caller's responsibility to ensure that both projections
136 /// list are being applied to the same root variable.
137 fn is_ancestor_or_same_capture(
138 proj_possible_ancestor: &[HirProjectionKind],
139 proj_capture: &[HirProjectionKind],
141 // We want to make sure `is_ancestor_or_same_capture("x.0.0", "x.0")` to return false.
142 // Therefore we can't just check if all projections are same in the zipped iterator below.
143 if proj_possible_ancestor.len() > proj_capture.len() {
147 iter::zip(proj_possible_ancestor, proj_capture).all(|(a, b)| a == b)
150 /// Given a closure, returns the index of a capture within the desugared closure struct and the
151 /// `ty::CapturedPlace` which is the ancestor of the Place represented using the `var_hir_id`
152 /// and `projection`.
154 /// Note there will be at most one ancestor for any given Place.
156 /// Returns None, when the ancestor is not found.
157 fn find_capture_matching_projections<'a, 'tcx>(
158 upvars: &'a CaptureMap<'tcx>,
159 var_hir_id: LocalVarId,
160 projections: &[PlaceElem<'tcx>],
161 ) -> Option<(usize, &'a Capture<'tcx>)> {
162 let hir_projections = convert_to_hir_projections_and_truncate_for_capture(projections);
164 upvars.get_by_key_enumerated(var_hir_id.0).find(|(_, capture)| {
165 let possible_ancestor_proj_kinds: Vec<_> =
166 capture.captured_place.place.projections.iter().map(|proj| proj.kind).collect();
167 is_ancestor_or_same_capture(&possible_ancestor_proj_kinds, &hir_projections)
171 /// Takes an upvar place and tries to resolve it into a `PlaceBuilder`
172 /// with `PlaceBase::Local`
173 #[instrument(level = "trace", skip(cx), ret)]
174 fn to_upvars_resolved_place_builder<'tcx>(
175 cx: &Builder<'_, 'tcx>,
176 var_hir_id: LocalVarId,
177 closure_def_id: LocalDefId,
178 projection: &[PlaceElem<'tcx>],
179 ) -> Option<PlaceBuilder<'tcx>> {
180 let Some((capture_index, capture)) =
181 find_capture_matching_projections(
186 let closure_span = cx.tcx.def_span(closure_def_id);
187 if !enable_precise_capture(cx.tcx, closure_span) {
189 "No associated capture found for {:?}[{:#?}] even though \
190 capture_disjoint_fields isn't enabled",
196 "No associated capture found for {:?}[{:#?}]",
197 var_hir_id, projection,
203 // Access the capture by accessing the field within the Closure struct.
204 let capture_info = &cx.upvars[capture_index];
206 let mut upvar_resolved_place_builder = PlaceBuilder::from(capture_info.use_place);
208 // We used some of the projections to build the capture itself,
209 // now we apply the remaining to the upvar resolved place.
210 trace!(?capture.captured_place, ?projection);
211 let remaining_projections = strip_prefix(
212 capture.captured_place.place.base_ty,
214 &capture.captured_place.place.projections,
216 upvar_resolved_place_builder.projection.extend(remaining_projections);
218 Some(upvar_resolved_place_builder)
221 /// Returns projections remaining after stripping an initial prefix of HIR
224 /// Supports only HIR projection kinds that represent a path that might be
225 /// captured by a closure or a generator, i.e., an `Index` or a `Subslice`
226 /// projection kinds are unsupported.
227 fn strip_prefix<'a, 'tcx>(
228 mut base_ty: Ty<'tcx>,
229 projections: &'a [PlaceElem<'tcx>],
230 prefix_projections: &[HirProjection<'tcx>],
231 ) -> impl Iterator<Item = PlaceElem<'tcx>> + 'a {
232 let mut iter = projections
235 // Filter out opaque casts, they are unnecessary in the prefix.
236 .filter(|elem| !matches!(elem, ProjectionElem::OpaqueCast(..)));
237 for projection in prefix_projections {
238 match projection.kind {
239 HirProjectionKind::Deref => {
240 assert_matches!(iter.next(), Some(ProjectionElem::Deref));
242 HirProjectionKind::Field(..) => {
243 if base_ty.is_enum() {
244 assert_matches!(iter.next(), Some(ProjectionElem::Downcast(..)));
246 assert_matches!(iter.next(), Some(ProjectionElem::Field(..)));
248 HirProjectionKind::Index | HirProjectionKind::Subslice => {
249 bug!("unexpected projection kind: {:?}", projection);
252 base_ty = projection.ty;
257 impl<'tcx> PlaceBuilder<'tcx> {
258 pub(in crate::build) fn to_place(&self, cx: &Builder<'_, 'tcx>) -> Place<'tcx> {
259 self.try_to_place(cx).unwrap()
262 /// Creates a `Place` or returns `None` if an upvar cannot be resolved
263 pub(in crate::build) fn try_to_place(&self, cx: &Builder<'_, 'tcx>) -> Option<Place<'tcx>> {
264 let resolved = self.resolve_upvar(cx);
265 let builder = resolved.as_ref().unwrap_or(self);
266 let PlaceBase::Local(local) = builder.base else { return None };
267 let projection = cx.tcx.intern_place_elems(&builder.projection);
268 Some(Place { local, projection })
271 /// Attempts to resolve the `PlaceBuilder`.
272 /// Returns `None` if this is not an upvar.
274 /// Upvars resolve may fail for a `PlaceBuilder` when attempting to
275 /// resolve a disjoint field whose root variable is not captured
276 /// (destructured assignments) or when attempting to resolve a root
277 /// variable (discriminant matching with only wildcard arm) that is
278 /// not captured. This can happen because the final mir that will be
279 /// generated doesn't require a read for this place. Failures will only
280 /// happen inside closures.
281 pub(in crate::build) fn resolve_upvar(
283 cx: &Builder<'_, 'tcx>,
284 ) -> Option<PlaceBuilder<'tcx>> {
285 let PlaceBase::Upvar { var_hir_id, closure_def_id } = self.base else {
288 to_upvars_resolved_place_builder(cx, var_hir_id, closure_def_id, &self.projection)
291 pub(crate) fn base(&self) -> PlaceBase {
295 pub(crate) fn projection(&self) -> &[PlaceElem<'tcx>] {
299 pub(crate) fn field(self, f: Field, ty: Ty<'tcx>) -> Self {
300 self.project(PlaceElem::Field(f, ty))
303 pub(crate) fn deref(self) -> Self {
304 self.project(PlaceElem::Deref)
307 pub(crate) fn downcast(self, adt_def: AdtDef<'tcx>, variant_index: VariantIdx) -> Self {
308 self.project(PlaceElem::Downcast(Some(adt_def.variant(variant_index).name), variant_index))
311 fn index(self, index: Local) -> Self {
312 self.project(PlaceElem::Index(index))
315 pub(crate) fn project(mut self, elem: PlaceElem<'tcx>) -> Self {
316 self.projection.push(elem);
320 /// Same as `.clone().project(..)` but more efficient
321 pub(crate) fn clone_project(&self, elem: PlaceElem<'tcx>) -> Self {
324 projection: Vec::from_iter(self.projection.iter().copied().chain([elem])),
328 pub fn try_compute_ty<D>(
331 cx: &Builder<'_, 'tcx>,
332 ) -> Option<PlaceTy<'tcx>>
334 D: HasLocalDecls<'tcx>,
337 PlaceBase::Local(_) => Some(self.clone().into_place(cx).ty(local_decls, cx.tcx)),
338 PlaceBase::Upvar { .. } => {
339 match to_upvars_resolved_place_builder(self.clone(), cx) {
340 Ok(resolved_place_builder) => {
341 // `base` is guaranteed to be `PlaceBase::Local` now, so recursive call is ok
342 resolved_place_builder.try_compute_ty(local_decls, cx)
344 Err(place_builder) => {
345 match &place_builder.projection[..] {
346 &[ProjectionElem::OpaqueCast(base_ty), ref projections @ ..] => {
347 let place_ty = projections
349 .fold(PlaceTy::from_ty(base_ty), |place_ty, &elem| {
350 place_ty.projection_ty(cx.tcx, elem)
357 _ => None, // would need a base `Ty` for these
366 impl<'tcx> From<Local> for PlaceBuilder<'tcx> {
367 fn from(local: Local) -> Self {
368 Self { base: PlaceBase::Local(local), projection: Vec::new() }
372 impl<'tcx> From<PlaceBase> for PlaceBuilder<'tcx> {
373 fn from(base: PlaceBase) -> Self {
374 Self { base, projection: Vec::new() }
378 impl<'tcx> From<Place<'tcx>> for PlaceBuilder<'tcx> {
379 fn from(p: Place<'tcx>) -> Self {
380 Self { base: PlaceBase::Local(p.local), projection: p.projection.to_vec() }
384 impl<'a, 'tcx> Builder<'a, 'tcx> {
385 /// Compile `expr`, yielding a place that we can move from etc.
387 /// WARNING: Any user code might:
388 /// * Invalidate any slice bounds checks performed.
389 /// * Change the address that this `Place` refers to.
390 /// * Modify the memory that this place refers to.
391 /// * Invalidate the memory that this place refers to, this will be caught
392 /// by borrow checking.
394 /// Extra care is needed if any user code is allowed to run between calling
395 /// this method and using it, as is the case for `match` and index
397 pub(crate) fn as_place(
399 mut block: BasicBlock,
401 ) -> BlockAnd<Place<'tcx>> {
402 let place_builder = unpack!(block = self.as_place_builder(block, expr));
403 block.and(place_builder.to_place(self))
406 /// This is used when constructing a compound `Place`, so that we can avoid creating
407 /// intermediate `Place` values until we know the full set of projections.
408 pub(crate) fn as_place_builder(
412 ) -> BlockAnd<PlaceBuilder<'tcx>> {
413 self.expr_as_place(block, expr, Mutability::Mut, None)
416 /// Compile `expr`, yielding a place that we can move from etc.
417 /// Mutability note: The caller of this method promises only to read from the resulting
418 /// place. The place itself may or may not be mutable:
419 /// * If this expr is a place expr like a.b, then we will return that place.
420 /// * Otherwise, a temporary is created: in that event, it will be an immutable temporary.
421 pub(crate) fn as_read_only_place(
423 mut block: BasicBlock,
425 ) -> BlockAnd<Place<'tcx>> {
426 let place_builder = unpack!(block = self.as_read_only_place_builder(block, expr));
427 block.and(place_builder.to_place(self))
430 /// This is used when constructing a compound `Place`, so that we can avoid creating
431 /// intermediate `Place` values until we know the full set of projections.
432 /// Mutability note: The caller of this method promises only to read from the resulting
433 /// place. The place itself may or may not be mutable:
434 /// * If this expr is a place expr like a.b, then we will return that place.
435 /// * Otherwise, a temporary is created: in that event, it will be an immutable temporary.
436 fn as_read_only_place_builder(
440 ) -> BlockAnd<PlaceBuilder<'tcx>> {
441 self.expr_as_place(block, expr, Mutability::Not, None)
446 mut block: BasicBlock,
448 mutability: Mutability,
449 fake_borrow_temps: Option<&mut Vec<Local>>,
450 ) -> BlockAnd<PlaceBuilder<'tcx>> {
451 debug!("expr_as_place(block={:?}, expr={:?}, mutability={:?})", block, expr, mutability);
454 let expr_span = expr.span;
455 let source_info = this.source_info(expr_span);
457 ExprKind::Scope { region_scope, lint_level, value } => {
458 this.in_scope((region_scope, source_info), lint_level, |this| {
459 this.expr_as_place(block, &this.thir[value], mutability, fake_borrow_temps)
462 ExprKind::Field { lhs, variant_index, name } => {
463 let lhs = &this.thir[lhs];
464 let mut place_builder =
465 unpack!(block = this.expr_as_place(block, lhs, mutability, fake_borrow_temps,));
466 if let ty::Adt(adt_def, _) = lhs.ty.kind() {
467 if adt_def.is_enum() {
468 place_builder = place_builder.downcast(*adt_def, variant_index);
471 block.and(place_builder.field(name, expr.ty))
473 ExprKind::Deref { arg } => {
474 let place_builder = unpack!(
476 this.expr_as_place(block, &this.thir[arg], mutability, fake_borrow_temps,)
478 block.and(place_builder.deref())
480 ExprKind::Index { lhs, index } => this.lower_index_expression(
490 ExprKind::UpvarRef { closure_def_id, var_hir_id } => {
491 this.lower_captured_upvar(block, closure_def_id.expect_local(), var_hir_id)
494 ExprKind::VarRef { id } => {
495 let place_builder = if this.is_bound_var_in_guard(id) {
496 let index = this.var_local_id(id, RefWithinGuard);
497 PlaceBuilder::from(index).deref()
499 let index = this.var_local_id(id, OutsideGuard);
500 PlaceBuilder::from(index)
502 block.and(place_builder)
505 ExprKind::PlaceTypeAscription { source, ref user_ty } => {
506 let place_builder = unpack!(
507 block = this.expr_as_place(
514 if let Some(user_ty) = user_ty {
515 let annotation_index =
516 this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
517 span: source_info.span,
518 user_ty: user_ty.clone(),
519 inferred_ty: expr.ty,
522 let place = place_builder.to_place(this);
527 kind: StatementKind::AscribeUserType(
530 UserTypeProjection { base: annotation_index, projs: vec![] },
537 block.and(place_builder)
539 ExprKind::ValueTypeAscription { source, ref user_ty } => {
540 let source = &this.thir[source];
542 unpack!(block = this.as_temp(block, source.temp_lifetime, source, mutability));
543 if let Some(user_ty) = user_ty {
544 let annotation_index =
545 this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
546 span: source_info.span,
547 user_ty: user_ty.clone(),
548 inferred_ty: expr.ty,
554 kind: StatementKind::AscribeUserType(
557 UserTypeProjection { base: annotation_index, projs: vec![] },
564 block.and(PlaceBuilder::from(temp))
567 ExprKind::Array { .. }
568 | ExprKind::Tuple { .. }
569 | ExprKind::Adt { .. }
570 | ExprKind::Closure { .. }
571 | ExprKind::Unary { .. }
572 | ExprKind::Binary { .. }
573 | ExprKind::LogicalOp { .. }
574 | ExprKind::Box { .. }
575 | ExprKind::Cast { .. }
576 | ExprKind::Use { .. }
577 | ExprKind::NeverToAny { .. }
578 | ExprKind::Pointer { .. }
579 | ExprKind::Repeat { .. }
580 | ExprKind::Borrow { .. }
581 | ExprKind::AddressOf { .. }
582 | ExprKind::Match { .. }
583 | ExprKind::If { .. }
584 | ExprKind::Loop { .. }
585 | ExprKind::Block { .. }
586 | ExprKind::Let { .. }
587 | ExprKind::Assign { .. }
588 | ExprKind::AssignOp { .. }
589 | ExprKind::Break { .. }
590 | ExprKind::Continue { .. }
591 | ExprKind::Return { .. }
592 | ExprKind::Literal { .. }
593 | ExprKind::NamedConst { .. }
594 | ExprKind::NonHirLiteral { .. }
595 | ExprKind::ZstLiteral { .. }
596 | ExprKind::ConstParam { .. }
597 | ExprKind::ConstBlock { .. }
598 | ExprKind::StaticRef { .. }
599 | ExprKind::InlineAsm { .. }
600 | ExprKind::Yield { .. }
601 | ExprKind::ThreadLocalRef(_)
602 | ExprKind::Call { .. } => {
603 // these are not places, so we need to make a temporary.
604 debug_assert!(!matches!(Category::of(&expr.kind), Some(Category::Place)));
606 unpack!(block = this.as_temp(block, expr.temp_lifetime, expr, mutability));
607 block.and(PlaceBuilder::from(temp))
612 /// Lower a captured upvar. Note we might not know the actual capture index,
613 /// so we create a place starting from `PlaceBase::Upvar`, which will be resolved
614 /// once all projections that allow us to identify a capture have been applied.
615 fn lower_captured_upvar(
618 closure_def_id: LocalDefId,
619 var_hir_id: LocalVarId,
620 ) -> BlockAnd<PlaceBuilder<'tcx>> {
621 block.and(PlaceBuilder::from(PlaceBase::Upvar { var_hir_id, closure_def_id }))
624 /// Lower an index expression
626 /// This has two complications;
628 /// * We need to do a bounds check.
629 /// * We need to ensure that the bounds check can't be invalidated using an
630 /// expression like `x[1][{x = y; 2}]`. We use fake borrows here to ensure
631 /// that this is the case.
632 fn lower_index_expression(
634 mut block: BasicBlock,
637 mutability: Mutability,
638 fake_borrow_temps: Option<&mut Vec<Local>>,
639 temp_lifetime: Option<region::Scope>,
641 source_info: SourceInfo,
642 ) -> BlockAnd<PlaceBuilder<'tcx>> {
643 let base_fake_borrow_temps = &mut Vec::new();
644 let is_outermost_index = fake_borrow_temps.is_none();
645 let fake_borrow_temps = fake_borrow_temps.unwrap_or(base_fake_borrow_temps);
648 unpack!(block = self.expr_as_place(block, base, mutability, Some(fake_borrow_temps),));
650 // Making this a *fresh* temporary means we do not have to worry about
651 // the index changing later: Nothing will ever change this temporary.
652 // The "retagging" transformation (for Stacked Borrows) relies on this.
653 let idx = unpack!(block = self.as_temp(block, temp_lifetime, index, Mutability::Not,));
655 block = self.bounds_check(block, &base_place, idx, expr_span, source_info);
657 if is_outermost_index {
658 self.read_fake_borrows(block, fake_borrow_temps, source_info)
660 self.add_fake_borrows_of_base(
661 base_place.to_place(self),
669 block.and(base_place.index(idx))
675 slice: &PlaceBuilder<'tcx>,
678 source_info: SourceInfo,
680 let usize_ty = self.tcx.types.usize;
681 let bool_ty = self.tcx.types.bool;
683 let len = self.temp(usize_ty, expr_span);
684 let lt = self.temp(bool_ty, expr_span);
687 self.cfg.push_assign(block, source_info, len, Rvalue::Len(slice.to_place(self)));
689 self.cfg.push_assign(
695 Box::new((Operand::Copy(Place::from(index)), Operand::Copy(len))),
698 let msg = BoundsCheck { len: Operand::Move(len), index: Operand::Copy(Place::from(index)) };
699 // assert!(lt, "...")
700 self.assert(block, Operand::Move(lt), true, msg, expr_span)
703 fn add_fake_borrows_of_base(
705 base_place: Place<'tcx>,
707 fake_borrow_temps: &mut Vec<Local>,
709 source_info: SourceInfo,
713 let place_ty = base_place.ty(&self.local_decls, tcx);
714 if let ty::Slice(_) = place_ty.ty.kind() {
715 // We need to create fake borrows to ensure that the bounds
716 // check that we just did stays valid. Since we can't assign to
717 // unsized values, we only need to ensure that none of the
718 // pointers in the base place are modified.
719 for (idx, elem) in base_place.projection.iter().enumerate().rev() {
721 ProjectionElem::Deref => {
722 let fake_borrow_deref_ty = Place::ty_from(
724 &base_place.projection[..idx],
730 tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty);
731 let fake_borrow_temp =
732 self.local_decls.push(LocalDecl::new(fake_borrow_ty, expr_span));
733 let projection = tcx.intern_place_elems(&base_place.projection[..idx]);
734 self.cfg.push_assign(
737 fake_borrow_temp.into(),
739 tcx.lifetimes.re_erased,
741 Place { local: base_place.local, projection },
744 fake_borrow_temps.push(fake_borrow_temp);
746 ProjectionElem::Index(_) => {
747 let index_ty = Place::ty_from(
749 &base_place.projection[..idx],
753 match index_ty.ty.kind() {
754 // The previous index expression has already
755 // done any index expressions needed here.
756 ty::Slice(_) => break,
758 _ => bug!("unexpected index base"),
761 ProjectionElem::Field(..)
762 | ProjectionElem::Downcast(..)
763 | ProjectionElem::OpaqueCast(..)
764 | ProjectionElem::ConstantIndex { .. }
765 | ProjectionElem::Subslice { .. } => (),
771 fn read_fake_borrows(
774 fake_borrow_temps: &mut Vec<Local>,
775 source_info: SourceInfo,
777 // All indexes have been evaluated now, read all of the
778 // fake borrows so that they are live across those index
780 for temp in fake_borrow_temps {
781 self.cfg.push_fake_read(bb, source_info, FakeReadCause::ForIndex, Place::from(*temp));
786 /// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if
787 /// user is using Rust Edition 2021 or higher.
788 fn enable_precise_capture(tcx: TyCtxt<'_>, closure_span: Span) -> bool {
789 tcx.features().capture_disjoint_fields || closure_span.rust_2021()