-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-offset_of_enum`#![feature(offset_of_enum)]``#![feature(offset_of_enum)]`I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
Feature gate: #![feature(offset_of_enum)]
This is a tracking issue for using enum variants in offset_of. Enum variants themselves do not have an offset within their type, so the macro will not give an offset for them, but their fields do. For example, the standard library uses the offset of the content of the Some
variant of Option
to implement Option::as_slice
. The original RFC for offset_of was rust-lang/rfcs#3308.
Public API
pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) { ... }
const OFFSET: usize = offset_of!(Option<u32>, Some.0);
Steps / History
- Implementation: Support enum variants in offset_of! #114208
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Should the syntax for enum variants differ from the syntax for field names in offset_of? https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/.60offset_of!.60.20Syntax/
Footnotes
nazar-pc, LeonChambers and tyilojoseluis
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-offset_of_enum`#![feature(offset_of_enum)]``#![feature(offset_of_enum)]`I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.