Merge pull request #19657 from ChayimFriedman2/better-offset-of

feat: Better support `offset_of!()`
This commit is contained in:
Lukas Wirth 2025-04-22 13:28:34 +00:00 committed by GitHub
commit 1c68d83569
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 230 additions and 3 deletions

View file

@ -70,6 +70,7 @@
//! unimplemented: panic
//! column:
//! addr_of:
//! offset_of:
#![rustc_coherence_is_core]
@ -414,6 +415,13 @@ pub mod mem {
use crate::marker::DiscriminantKind;
pub struct Discriminant<T>(<T as DiscriminantKind>::Discriminant);
// endregion:discriminant
// region:offset_of
pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) {
// The `{}` is for better error messages
{builtin # offset_of($Container, $($fields)+)}
}
// endregion:offset_of
}
pub mod ptr {