Skip to content

Commit 9929c87

Browse files
susitsmepage
authored andcommitted
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`
1 parent 3fd0af4 commit 9929c87

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/cargo/util/context/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,10 @@ impl GlobalContext {
418418
/// so place this outside of the conditions to catch these bugs in more situations.
419419
pub fn debug_assert_shell_not_borrowed(&self) {
420420
if cfg!(debug_assertions) {
421-
self.shell().verbosity();
421+
match self.shell.try_lock() {
422+
Ok(_) | Err(std::sync::TryLockError::Poisoned(_)) => (),
423+
Err(std::sync::TryLockError::WouldBlock) => panic!("shell is borrowed!"),
424+
}
422425
}
423426
}
424427

0 commit comments

Comments
 (0)