Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Fix `update_window` to `borrow_mut` will crash on Windows (#24545)
Jason Lee0fa9f053131c
diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rsindex b95e3d27510..5a152100f6b 100644--- a/crates/gpui/src/app.rs+++ b/crates/gpui/src/app.rs@@ -1,6 +1,6 @@use std::{any::{TypeId, type_name},- cell::{Ref, RefCell, RefMut},+ cell::{BorrowMutError, Ref, RefCell, RefMut},marker::PhantomData,mem,ops::{Deref, DerefMut},@@ -79,6 +79,16 @@ impl AppCell {}AppRefMut(self.app.borrow_mut())}++ #[doc(hidden)]+ #[track_caller]+ pub fn try_borrow_mut(&self) -> Result<AppRefMut, BorrowMutError> {+ if option_env!("TRACK_THREAD_BORROWS").is_some() {+ let thread_id = std::thread::current().id();+ eprintln!("borrowed {thread_id:?}");+ }+ Ok(AppRefMut(self.app.try_borrow_mut()?))+ }}#[doc(hidden)]diff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rsindex 02cc8f33b8f..aa9cf4e572a 100644--- a/crates/gpui/src/app/async_context.rs+++ b/crates/gpui/src/app/async_context.rs@@ -88,7 +88,7 @@ impl AppContext for AsyncApp {F: FnOnce(AnyView, &mut Window, &mut App) -> T,{let app = self.app.upgrade().context("app was released")?;- let mut lock = app.borrow_mut();+ let mut lock = app.try_borrow_mut()?;lock.update_window(window, f)}