File tree Expand file tree Collapse file tree 3 files changed +15
-9
lines changed Expand file tree Collapse file tree 3 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -788,11 +788,9 @@ impl<'gctx> Registry for PackageRegistry<'gctx> {
788
788
789
789
#[ tracing:: instrument( skip_all) ]
790
790
fn block_until_ready ( & mut self ) -> CargoResult < ( ) > {
791
- if cfg ! ( debug_assertions) {
792
- // Force borrow to catch invalid borrows, regardless of which source is used and how it
793
- // happens to behave this time
794
- self . gctx . shell ( ) . verbosity ( ) ;
795
- }
791
+ // Force borrow to catch invalid borrows, regardless of which source is used and how it
792
+ // happens to behave this time
793
+ self . gctx . debug_assert_shell_not_borrowed ( ) ;
796
794
for ( source_id, source) in self . sources . sources_mut ( ) {
797
795
source
798
796
. block_until_ready ( )
Original file line number Diff line number Diff line change @@ -413,6 +413,16 @@ impl GlobalContext {
413
413
self . shell . lock ( ) . unwrap ( )
414
414
}
415
415
416
+ /// If debug assertions are enabled, checks that `shell` is not borrowed
417
+ pub fn debug_assert_shell_not_borrowed ( & self ) {
418
+ if cfg ! ( debug_assertions) {
419
+ match self . shell . try_lock ( ) {
420
+ Ok ( _) | Err ( std:: sync:: TryLockError :: Poisoned ( _) ) => ( ) ,
421
+ Err ( std:: sync:: TryLockError :: WouldBlock ) => panic ! ( "shell is borrowed!" ) ,
422
+ }
423
+ }
424
+ }
425
+
416
426
/// Gets the path to the `rustdoc` executable.
417
427
pub fn rustdoc ( & self ) -> CargoResult < & Path > {
418
428
self . rustdoc
Original file line number Diff line number Diff line change @@ -392,10 +392,8 @@ fn acquire(
392
392
lock_try : & dyn Fn ( ) -> io:: Result < ( ) > ,
393
393
lock_block : & dyn Fn ( ) -> io:: Result < ( ) > ,
394
394
) -> CargoResult < ( ) > {
395
- if cfg ! ( debug_assertions) {
396
- // Force borrow to catch invalid borrows outside of contention situations
397
- gctx. shell ( ) . verbosity ( ) ;
398
- }
395
+ // Force borrow to catch invalid borrows outside of contention situations
396
+ gctx. debug_assert_shell_not_borrowed ( ) ;
399
397
if try_acquire ( path, lock_try) ? {
400
398
return Ok ( ( ) ) ;
401
399
}
You can’t perform that action at this time.
0 commit comments