From 9929c8796da2493f531c805e6e4007c7ff1d66c6 Mon Sep 17 00:00:00 2001 From: Matyas Susits Date: Fri, 12 Sep 2025 12:58:16 +0200 Subject: [PATCH] Assert, rather than hang, on shell-in-use assertions Previously, `gctx.shell().verbosity()` was used to check that `gctx.shell` is not borrowed. Since shell is now behind a `Mutex` and not a `RefCell`, this would hang waiting for the unlock instead panicking. Borrow state checking is now done using `Mutex::try_lock` in `GlobalContext::debug_assert_shell_not_borrowed` --- src/cargo/util/context/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index c9f069b73..01ba9909a 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -418,7 +418,10 @@ impl GlobalContext { /// so place this outside of the conditions to catch these bugs in more situations. pub fn debug_assert_shell_not_borrowed(&self) { if cfg!(debug_assertions) { - self.shell().verbosity(); + match self.shell.try_lock() { + Ok(_) | Err(std::sync::TryLockError::Poisoned(_)) => (), + Err(std::sync::TryLockError::WouldBlock) => panic!("shell is borrowed!"), + } } }