From 1864d37d2e972ac853b28e29a5e890ea760ed3cd Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 8 Nov 2023 11:23:35 -0800 Subject: [PATCH] Fix double borrow in synchronous tests --- crates/gpui2/src/app.rs | 18 ++++++++++++++++++ crates/gpui2_macros/src/test.rs | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index 7b77f68398cbf6221053df05c5f31fd107b4f96c..b7e4cc0c6007b8b2df1352b3cf1eb280b39e8842 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -68,9 +68,27 @@ impl AppCell { #[derive(Deref, DerefMut)] pub struct AppRef<'a>(Ref<'a, AppContext>); +impl<'a> Drop for AppRef<'a> { + fn drop(&mut self) { + if let Some(_) = option_env!("TRACK_THREAD_BORROWS") { + let thread_id = std::thread::current().id(); + eprintln!("dropped borrow from {thread_id:?}"); + } + } +} + #[derive(Deref, DerefMut)] pub struct AppRefMut<'a>(RefMut<'a, AppContext>); +impl<'a> Drop for AppRefMut<'a> { + fn drop(&mut self) { + if let Some(_) = option_env!("TRACK_THREAD_BORROWS") { + let thread_id = std::thread::current().id(); + eprintln!("dropped {thread_id:?}"); + } + } +} + pub struct App(Rc); /// Represents an application before it is fully launched. Once your app is diff --git a/crates/gpui2_macros/src/test.rs b/crates/gpui2_macros/src/test.rs index 84052a2875b7ff7c5031876344b72b177cd499f0..70c6da22d5a7ab888f586d87f2d8ad261089d1bf 100644 --- a/crates/gpui2_macros/src/test.rs +++ b/crates/gpui2_macros/src/test.rs @@ -175,10 +175,10 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream { )); inner_fn_args.extend(quote!(&mut #cx_varname_lock,)); cx_teardowns.extend(quote!( - dispatcher.run_until_parked(); - #cx_varname_lock.quit(); drop(#cx_varname_lock); dispatcher.run_until_parked(); + #cx_varname.update(|cx| { cx.quit() }); + dispatcher.run_until_parked(); )); continue; }