diff options
| author | bors <bors@rust-lang.org> | 2023-06-21 16:40:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-21 16:40:54 +0000 |
| commit | 006a26c0b546abc0fbef59a773639582b641e500 (patch) | |
| tree | 53cb2b0131ebc998841f468e49f2262b7670965f /library/core/src | |
| parent | 536635c89b2b6ec7054473f85a9b7a01932bd7e7 (diff) | |
| parent | 592844cf88b586a87cddf877d8f45e6ffe2a2910 (diff) | |
| download | rust-006a26c0b546abc0fbef59a773639582b641e500.tar.gz rust-006a26c0b546abc0fbef59a773639582b641e500.zip | |
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.
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/mem/mod.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 39c9a04eea9..2fff3f0efd7 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1317,7 +1317,8 @@ impl<T> SizedTypeProperties for T {} /// assert_eq!(mem::offset_of!(NestedA, b.0), 0); /// ``` #[unstable(feature = "offset_of", issue = "106655")] -#[allow_internal_unstable(builtin_syntax)] +#[allow_internal_unstable(builtin_syntax, hint_must_use)] pub macro offset_of($Container:ty, $($fields:tt).+ $(,)?) { - builtin # offset_of($Container, $($fields).+) + // The `{}` is for better error messages + crate::hint::must_use({builtin # offset_of($Container, $($fields).+)}) } |
