Give up on entities being `Send` and `Sync`

Antonio Scandurra and Nathan Sobo created

Co-Authored-By: Nathan Sobo <nathan@zed.dev>

Change summary

gpui/src/app.rs       | 9 ++++++---
zed/src/chat_panel.rs | 3 ++-
zed/src/test.rs       | 2 +-
zed/src/workspace.rs  | 4 ++--
4 files changed, 11 insertions(+), 7 deletions(-)

Detailed changes

gpui/src/app.rs 🔗

@@ -29,7 +29,7 @@ use std::{
     time::Duration,
 };
 
-pub trait Entity: 'static + Send + Sync {
+pub trait Entity: 'static {
     type Event;
 
     fn release(&mut self, _: &mut MutableAppContext) {}
@@ -1738,7 +1738,7 @@ impl Debug for Effect {
     }
 }
 
-pub trait AnyModel: Send + Sync {
+pub trait AnyModel {
     fn as_any(&self) -> &dyn Any;
     fn as_any_mut(&mut self) -> &mut dyn Any;
     fn release(&mut self, cx: &mut MutableAppContext);
@@ -1761,7 +1761,7 @@ where
     }
 }
 
-pub trait AnyView: Send + Sync {
+pub trait AnyView {
     fn as_any(&self) -> &dyn Any;
     fn as_any_mut(&mut self) -> &mut dyn Any;
     fn release(&mut self, cx: &mut MutableAppContext);
@@ -2515,6 +2515,9 @@ pub struct WeakModelHandle<T> {
     model_type: PhantomData<T>,
 }
 
+unsafe impl<T> Send for WeakModelHandle<T> {}
+unsafe impl<T> Sync for WeakModelHandle<T> {}
+
 impl<T: Entity> WeakModelHandle<T> {
     fn new(model_id: usize) -> Self {
         Self {

zed/src/chat_panel.rs 🔗

@@ -1,9 +1,10 @@
 use super::channel::{Channel, ChannelList};
-use gpui::{Entity, ModelHandle, View};
+use gpui::{elements::*, Entity, ModelHandle, View};
 
 pub struct ChatPanel {
     channel_list: ModelHandle<ChannelList>,
     active_channel: Option<ModelHandle<Channel>>,
+    messages: ListState,
 }
 
 pub enum Event {}

zed/src/test.rs 🔗

@@ -169,7 +169,7 @@ pub fn build_app_state(cx: &AppContext) -> Arc<AppState> {
 
 pub struct Observer<T>(PhantomData<T>);
 
-impl<T: 'static + Send + Sync> Entity for Observer<T> {
+impl<T: 'static> Entity for Observer<T> {
     type Event = ();
 }
 

zed/src/workspace.rs 🔗

@@ -192,7 +192,7 @@ pub trait ItemHandle: Send + Sync {
     fn downgrade(&self) -> Box<dyn WeakItemHandle>;
 }
 
-pub trait WeakItemHandle: Send + Sync {
+pub trait WeakItemHandle {
     fn file<'a>(&'a self, cx: &'a AppContext) -> Option<&'a File>;
     fn add_view(
         &self,
@@ -203,7 +203,7 @@ pub trait WeakItemHandle: Send + Sync {
     fn alive(&self, cx: &AppContext) -> bool;
 }
 
-pub trait ItemViewHandle: Send + Sync {
+pub trait ItemViewHandle {
     fn title(&self, cx: &AppContext) -> String;
     fn entry_id(&self, cx: &AppContext) -> Option<(usize, Arc<Path>)>;
     fn boxed_clone(&self) -> Box<dyn ItemViewHandle>;