Skip to content

The offset_of! macro may need to be a compiler intrinsic #48956

Closed
@alexcrichton

Description

@alexcrichton

This came up a few weeks ago in libs triage specifically related to #48493 where we were wondering if there were other locations in the standard library that needed to be adjusted to handle uninhabited enums being handled in generic locations. While not many locations in the standard library leapt to mind one thing we thought of was the offset_of! macro.

For example if we've got something like:

struct Foo<T> { a: T, b: usize }

do existing offset_of! macros handle this?

offset_of!(Foo<Void>, b)

or is there "technical UB that rustc may paper over today" somewhere in there?

cc @dtolnay, I think you had better ideas about examples here than I!

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions