Enum rustc_mir_build::build::expr::as_place::PlaceBuilder
source · pub(in build) enum PlaceBuilder<'tcx> {
Local {
local: Local,
projection: Vec<PlaceElem<'tcx>>,
},
Upvar {
upvar: Upvar,
projection: Vec<UpvarProjectionElem<'tcx>>,
},
}
Expand description
PlaceBuilder
is used to create places during MIR construction. It allows you to “build up” a
place by pushing more and more projections onto the end, and then convert the final set into a
place using the into_place
method.
This is used internally when building a place for an expression like a.b.c
. The fields b
and c
can be progressively pushed onto the place builder that is created when converting a
.
Variants§
Local
Denotes the start of a Place
.
We use PlaceElem
since this has all Field
types available.
Upvar
When building place for an expression within a closure, the place might start off a
captured path. When capture_disjoint_fields
is enabled, we might not know the capture
index (within the desugared closure) of the captured path until most of the projections
are applied. We use PlaceBuilder::Upvar
to keep track of the root variable off of which the
captured path starts, the closure the capture belongs to and the trait the closure
implements.
Once we have figured out the capture index, we can convert the place builder to
PlaceBuilder::Local
.
Consider the following example
let t = (((10, 10), 10), 10);
let c = || {
println!("{}", t.0.0.0);
};
Here the THIR expression for t.0.0.0
will be something like
* Field(0)
* Field(0)
* Field(0)
* UpvarRef(t)
When capture_disjoint_fields
is enabled, t.0.0.0
is captured and we won’t be able to
figure out that it is captured until all the Field
projections are applied.
Note: in contrast to PlaceBuilder::Local
we have not yet determined all Field
types
and will only do so once converting to PlaceBuilder::Local
.
Implementations§
source§impl<'tcx> PlaceBuilder<'tcx>
impl<'tcx> PlaceBuilder<'tcx>
pub(in build) fn to_place(
&self,
cx: &Builder<'_, 'tcx>
) -> Place<'tcx>
sourcepub(in build) fn try_to_place(
&self,
cx: &Builder<'_, 'tcx>
) -> Option<Place<'tcx>>
pub(in build) fn try_to_place(
&self,
cx: &Builder<'_, 'tcx>
) -> Option<Place<'tcx>>
Creates a Place
or returns None
if an upvar cannot be resolved
sourcepub(in build) fn resolve_upvar(
&self,
cx: &Builder<'_, 'tcx>
) -> Option<PlaceBuilder<'tcx>>
pub(in build) fn resolve_upvar(
&self,
cx: &Builder<'_, 'tcx>
) -> Option<PlaceBuilder<'tcx>>
Attempts to resolve the PlaceBuilder
.
Returns None
if this is not an upvar.
Upvars resolve may fail for a PlaceBuilder
when attempting to
resolve a disjoint field whose root variable is not captured
(destructured assignments) or when attempting to resolve a root
variable (discriminant matching with only wildcard arm) that is
not captured. This can happen because the final mir that will be
generated doesn’t require a read for this place. Failures will only
happen inside closures.
pub(crate) fn field(self, cx: &Builder<'_, 'tcx>, f: Field) -> Self
pub(crate) fn deref(self) -> Self
pub(crate) fn downcast(
self,
adt_def: AdtDef<'tcx>,
variant_index: VariantIdx
) -> Self
fn index(self, index: Local) -> Self
pub(crate) fn project(self, elem: PlaceElem<'tcx>) -> Self
sourcepub(crate) fn clone_project(&self, elem: PlaceElem<'tcx>) -> Self
pub(crate) fn clone_project(&self, elem: PlaceElem<'tcx>) -> Self
Same as .clone().project(..)
but more efficient
sourcefn compute_field_ty(
cx: &Builder<'_, 'tcx>,
field: Field,
base_ty: Ty<'tcx>,
variant_index: Option<VariantIdx>
) -> Ty<'tcx>
fn compute_field_ty(
cx: &Builder<'_, 'tcx>,
field: Field,
base_ty: Ty<'tcx>,
variant_index: Option<VariantIdx>
) -> Ty<'tcx>
Similar to Place::ty
but needed during mir building.
Applies the projections in the PlaceBuilder
to the base
type.
Fallible as the root of this place may be an upvar for which no base type can be determined.
sourcefn construct_local_place_builder(
cx: &Builder<'_, 'tcx>,
local: Local,
local_projection: &[PlaceElem<'tcx>],
upvar_projection: impl Iterator<Item = UpvarProjectionElem<'tcx>>
) -> Self
fn construct_local_place_builder(
cx: &Builder<'_, 'tcx>,
local: Local,
local_projection: &[PlaceElem<'tcx>],
upvar_projection: impl Iterator<Item = UpvarProjectionElem<'tcx>>
) -> Self
Creates a PlaceBuilder::Local
from a PlaceBuilder::Upvar
whose upvars
are resolved. This function takes two kinds of projections: local_projection
contains the projections of the captured upvar and upvar_projection
the
projections that are applied to the captured upvar. The main purpose of this
function is to figure out the Ty
s of the field projections in upvar_projection
.
Trait Implementations§
source§impl<'tcx> Clone for PlaceBuilder<'tcx>
impl<'tcx> Clone for PlaceBuilder<'tcx>
source§fn clone(&self) -> PlaceBuilder<'tcx>
fn clone(&self) -> PlaceBuilder<'tcx>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'tcx> Debug for PlaceBuilder<'tcx>
impl<'tcx> Debug for PlaceBuilder<'tcx>
source§impl<'tcx> From<Local> for PlaceBuilder<'tcx>
impl<'tcx> From<Local> for PlaceBuilder<'tcx>
source§impl<'tcx> From<Place<'tcx>> for PlaceBuilder<'tcx>
impl<'tcx> From<Place<'tcx>> for PlaceBuilder<'tcx>
source§impl<'tcx> PartialEq<PlaceBuilder<'tcx>> for PlaceBuilder<'tcx>
impl<'tcx> PartialEq<PlaceBuilder<'tcx>> for PlaceBuilder<'tcx>
source§fn eq(&self, other: &PlaceBuilder<'tcx>) -> bool
fn eq(&self, other: &PlaceBuilder<'tcx>) -> bool
impl<'tcx> StructuralPartialEq for PlaceBuilder<'tcx>
Auto Trait Implementations§
impl<'tcx> !RefUnwindSafe for PlaceBuilder<'tcx>
impl<'tcx> !Send for PlaceBuilder<'tcx>
impl<'tcx> !Sync for PlaceBuilder<'tcx>
impl<'tcx> Unpin for PlaceBuilder<'tcx>
impl<'tcx> !UnwindSafe for PlaceBuilder<'tcx>
Blanket Implementations§
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 40 bytes
Size for each variant:
Local
: 28 bytesUpvar
: 36 bytes