gpui: Remove some unnecessary unsafe code (#40483)

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-10-17 14:20:13 +02:00
committed by GitHub
parent eb3f9b0ea3
commit b59a3bbd49
10 changed files with 76 additions and 92 deletions
+2 -7
View File
@@ -378,11 +378,9 @@ pub struct Entity<T> {
#[deref]
#[deref_mut]
pub(crate) any_entity: AnyEntity,
pub(crate) entity_type: PhantomData<T>,
pub(crate) entity_type: PhantomData<fn(T) -> T>,
}
unsafe impl<T> Send for Entity<T> {}
unsafe impl<T> Sync for Entity<T> {}
impl<T> Sealed for Entity<T> {}
impl<T: 'static> Entity<T> {
@@ -657,7 +655,7 @@ pub struct WeakEntity<T> {
#[deref]
#[deref_mut]
any_entity: AnyWeakEntity,
entity_type: PhantomData<T>,
entity_type: PhantomData<fn(T) -> T>,
}
impl<T> std::fmt::Debug for WeakEntity<T> {
@@ -669,9 +667,6 @@ impl<T> std::fmt::Debug for WeakEntity<T> {
}
}
unsafe impl<T> Send for WeakEntity<T> {}
unsafe impl<T> Sync for WeakEntity<T> {}
impl<T> Clone for WeakEntity<T> {
fn clone(&self) -> Self {
Self {
+3 -1
View File
@@ -888,7 +888,9 @@ impl VisualTestContext {
// safety: on_quit will be called after the test has finished.
// the executor will ensure that all tasks related to the test have stopped.
// so there is no way for cx to be accessed after on_quit is called.
let cx = Box::leak(unsafe { Box::from_raw(ptr) });
// todo: This is unsound under stacked borrows (also tree borrows probably?)
// the mutable reference invalidates `ptr` which is later used in the closure
let cx = unsafe { &mut *ptr };
cx.on_quit(move || unsafe {
drop(Box::from_raw(ptr));
});