From db24ef20ee02279aba441019482b506352b3af75 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 14 Jul 2019 09:19:18 +0200 Subject: [PATCH] explain let_base_ptr --- src/offset_of.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/offset_of.rs b/src/offset_of.rs index 98e7644..a1300af 100644 --- a/src/offset_of.rs +++ b/src/offset_of.rs @@ -26,6 +26,10 @@ macro_rules! let_base_ptr { ($name:ident, $type:tt) => { // No UB here, and the pointer does not dangle, either. + // But we have to make sure that `uninit` lives long enough, + // so it has to be in the same scope as `$name`. That's why + // `let_base_ptr` declares a variable (several, actually) + // instad of returning one. let uninit = $crate::mem::MaybeUninit::<$type>::uninit(); let $name = uninit.as_ptr(); };