Generating custom MIR(`std::intrinsics::mir`) from MIR

Is it possible to generate custom MIR(hand-writing MIR from std::intrinsics::mir) based on the MIR provided below?

// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn main() -> () {
    let mut _0: ();                      // return place in scope 0 at 000.rs:9:11: 9:11

    bb0: {
        _0 = const ();                   // scope 0 at 000.rs:9:11: 11:2
        return;                          // scope 0 at 000.rs:11:2: 11:2
    }
}

const BAR_OFFSET: usize = {
    let mut _0: usize;                   // return place in scope 0 at 000.rs:10:23: 10:28

    bb0: {
        _0 = OffsetOf(Foo<'_>, [0]);     // scope 0 at /rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/core/src/mem/mod.rs:1322:5: 1322:50
        return;                          // scope 0 at 000.rs:10:5: 10:61
    }
}

The original Rust code is as follows:

#![feature(offset_of)]
extern crate core;
use core::mem::offset_of;

struct Foo<'a> {
    bar: &'a (),
}

fn main() {
    const BAR_OFFSET: usize = offset_of!(Foo<'static>, bar);
}

I was wondering if it's possible to represent OffsetOf with custom_mir grammar.

Looks like it just hasn't been implemented yet, but I don't think there is any other reason you couldn't.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.