explain let_base_ptr

This commit is contained in:
Ralf Jung
2019-07-14 09:19:18 +02:00
parent fc033fda9c
commit db24ef20ee
+4
View File
@@ -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();
};