Skip to content

Commit 6bacf37

Browse files
committed
Auto merge of #148151 - cjgillot:no-offset-of, r=scottmcm
Replace OffsetOf by an actual sum of calls to intrinsic. This PR changes the way we compute the value of the `offset_of!` macro in MIR. The current implementation uses a dedicated MIR rvalue. This PR proposes to replace it by an inline constant which sums calls to a new intrinsic `offset_of(variant index, field index)`. The desugaring is done at THIR building time, easier that doing it on MIR. The new intrinsic is only meant to be used by const-eval. LLVM codegen will refuse to generate code for it. We replace: ```rust a = offset_of!(T, Variant1.Field1.Variant2.Field2); ``` By: ```rust a = const {constant#n}; {constant#n}: usize = { _1 = offset_of::<T>(index of Variant1, index of Field1); _2 = offset_of::<U>(index of Variant2, index of Field2); // Where T::Variant1::Field1 has type U _0 = _1 + _2 } ``` The second commit modifies intrinsic const checking to take `allow_internal_unstable` into account. The new intrinsic should only be called from stable `offset_of!` macro. The intrinsic itself is unstable, const-unstable, but `rustc_intrinsic_const_stable_indirect`. Fixes rust-lang/rust#123959 Fixes rust-lang/rust#125680 Fixes rust-lang/rust#129425 Fixes rust-lang/rust#136175 r? `@ghost`
2 parents bf23d14 + 60b0c9c commit 6bacf37

File tree

0 file changed

+0
-0
lines changed

    0 file changed

    +0
    -0
    lines changed

    0 commit comments

    Comments
     (0)