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

Fields

§local: Local
§projection: Vec<PlaceElem<'tcx>>

Denotes the start of a Place.

We use PlaceElem since this has all Field types available.

§

Upvar

Fields

§upvar: Upvar
§projection: Vec<UpvarProjectionElem<'tcx>>

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§

Creates a Place or returns None if an upvar cannot be resolved

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.

Same as .clone().project(..) but more efficient

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.

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 Tys of the field projections in upvar_projection.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

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 bytes
  • Upvar: 36 bytes