Function Field

fn Field<F>(place: (), field: u32) -> F

Access the field with the given index of some place.

This only makes sense to use in conjunction with Variant. If the type you are looking to access the field of does not have variants, you can use normal field projection syntax.

There is no proper way to do a place projection to a variant in Rust, and so these two functions are a workaround. You can access a field of a variant via Field(Variant(place, var_idx), field_idx), where var_idx and field_idx are appropriate literals. Some caveats:

Examples

#![allow(internal_features)]
#![feature(custom_mir, core_intrinsics)]

use core::intrinsics::mir::*;

#[custom_mir(dialect = "built")]
fn unwrap_deref(opt: Option<&i32>) -> i32 {
    mir! {
        {
            RET = *Field::<&i32>(Variant(opt, 1), 0);
            Return()
        }
    }
}

#[custom_mir(dialect = "built")]
fn set(opt: &mut Option<i32>) {
    mir! {
        {
            place!(Field(Variant(*opt, 1), 0)) = 5;
            Return()
        }
    }
}