Skip to content

Commit 8ccfe39

Browse files
committed
Auto merge of #111684 - ChayimFriedman2:unused-offset-of, r=WaffleLapkin
Warn on unused `offset_of!()` result The usage of `core::hint::must_use()` means that we don't get a specialized message. I figured out that since there are plenty of other methods that just have `#[must_use]` with no message it'll be fine, but it is a bit unfortunate that the error mentions `must_use` and not `offset_of!`. Fixes #111669.
2 parents 24a54ba + 7258c89 commit 8ccfe39

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

core/src/mem/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,8 @@ impl<T> SizedTypeProperties for T {}
13171317
/// assert_eq!(mem::offset_of!(NestedA, b.0), 0);
13181318
/// ```
13191319
#[unstable(feature = "offset_of", issue = "106655")]
1320-
#[allow_internal_unstable(builtin_syntax)]
1320+
#[allow_internal_unstable(builtin_syntax, hint_must_use)]
13211321
pub macro offset_of($Container:ty, $($fields:tt).+ $(,)?) {
1322-
builtin # offset_of($Container, $($fields).+)
1322+
// The `{}` is for better error messages
1323+
crate::hint::must_use({builtin # offset_of($Container, $($fields).+)})
13231324
}

0 commit comments

Comments
 (0)