about summary refs log tree commit diff
path: root/library/alloc
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2025-07-08 00:20:57 +0800
committerDeadbeef <ent3rm4n@gmail.com>2025-07-16 00:32:12 +0800
commit3f2dc2bd1a2e0120b868911497ddbd8e43f3a9fa (patch)
tree1b7d0258d17ef7734220a679c8280d366bea8052 /library/alloc
parent9c3064e131f4939cc95a29bb11413c49bbda1491 (diff)
downloadrust-3f2dc2bd1a2e0120b868911497ddbd8e43f3a9fa.tar.gz
rust-3f2dc2bd1a2e0120b868911497ddbd8e43f3a9fa.zip
add `const_make_global`; err for `const_allocate` ptrs if didn't call
Co-Authored-By: Ralf Jung <post@ralfj.de>
Co-Authored-By: Oli Scherer <github333195615777966@oli-obk.de>
Diffstat (limited to 'library/alloc')
-rw-r--r--library/alloc/src/boxed/thin.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/library/alloc/src/boxed/thin.rs b/library/alloc/src/boxed/thin.rs
index 21425b9846e..1cce36606d2 100644
--- a/library/alloc/src/boxed/thin.rs
+++ b/library/alloc/src/boxed/thin.rs
@@ -5,7 +5,7 @@
 use core::error::Error;
 use core::fmt::{self, Debug, Display, Formatter};
 #[cfg(not(no_global_oom_handling))]
-use core::intrinsics::const_allocate;
+use core::intrinsics::{const_allocate, const_make_global};
 use core::marker::PhantomData;
 #[cfg(not(no_global_oom_handling))]
 use core::marker::Unsize;
@@ -340,9 +340,10 @@ impl<H> WithHeader<H> {
                     alloc.add(metadata_offset).cast();
                 // SAFETY: `*metadata_ptr` is within the allocation.
                 metadata_ptr.write(ptr::metadata::<Dyn>(ptr::dangling::<T>() as *const Dyn));
-
+                // SAFETY: valid heap allocation
+                const_make_global(alloc);
                 // SAFETY: we have just written the metadata.
-                &*(metadata_ptr)
+                &*metadata_ptr
             }
         };