Skip to content

Commit 9221894

Browse files
authored
Rollup merge of rust-lang#119532 - GKFX:offset-of-parse-expr, r=est31
Make offset_of field parsing use metavariable which handles any spacing As discussed at and around comments rust-lang#106655 (comment) and rust-lang#106655 (comment), the current arguments to offset_of do not accept all the whitespace combinations: `0. 1.1.1` and `0.1.1. 1` are currently treated specially in `tests/ui/offset-of/offset-of-tuple-nested.rs`. They also do not allow [forwarding individual fields as in](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=444cdf0ec02b99e8fd5fd8d8ecb312ca) ```rust macro_rules! off { ($a:expr) => { offset_of!(m::S, 0. $a) } } ``` This PR replaces the macro arguments with `($Container:ty, $($fields:expr)+ $(,)?)` which does allow any arrangement of whitespace that I could come up with and the forwarding of fields example above. This also allows for array indexing in the future, which I think is the last future extension to the syntax suggested in the offset_of RFC. Tracking issue for offset_of: rust-lang#106655 ``@rustbot`` label F-offset_of ``@est31``
2 parents 8e07973 + e8ee49d commit 9221894

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core/src/mem/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,8 +1395,18 @@ impl<T> SizedTypeProperties for T {}
13951395
///
13961396
/// assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
13971397
/// ```
1398+
#[cfg(not(bootstrap))]
13981399
#[unstable(feature = "offset_of", issue = "106655")]
13991400
#[allow_internal_unstable(builtin_syntax, hint_must_use)]
1401+
pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) {
1402+
// The `{}` is for better error messages
1403+
crate::hint::must_use({builtin # offset_of($Container, $($fields)+)})
1404+
}
1405+
1406+
#[cfg(bootstrap)]
1407+
#[unstable(feature = "offset_of", issue = "106655")]
1408+
#[allow_internal_unstable(builtin_syntax, hint_must_use)]
1409+
#[allow(missing_docs)]
14001410
pub macro offset_of($Container:ty, $($fields:tt).+ $(,)?) {
14011411
// The `{}` is for better error messages
14021412
crate::hint::must_use({builtin # offset_of($Container, $($fields).+)})

0 commit comments

Comments
 (0)