File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -800,11 +800,9 @@ impl<'gctx> Registry for PackageRegistry<'gctx> {
800
800
801
801
#[ tracing:: instrument( skip_all) ]
802
802
fn block_until_ready ( & mut self ) -> CargoResult < ( ) > {
803
- if cfg ! ( debug_assertions) {
804
- // Force borrow to catch invalid borrows, regardless of which source is used and how it
805
- // happens to behave this time
806
- self . gctx . shell ( ) . verbosity ( ) ;
807
- }
803
+ // Ensure `shell` is not already in use,
804
+ // regardless of which source is used and how it happens to behave this time
805
+ self . gctx . debug_assert_shell_not_borrowed ( ) ;
808
806
for ( source_id, source) in self . sources . sources_mut ( ) {
809
807
source
810
808
. block_until_ready ( )
Original file line number Diff line number Diff line change @@ -412,6 +412,17 @@ impl GlobalContext {
412
412
self . shell . borrow_mut ( )
413
413
}
414
414
415
+ /// Assert [`Self::shell`] is not in use
416
+ ///
417
+ /// Testing might not identify bugs with two accesses to `shell` at once
418
+ /// due to conditional logic,
419
+ /// so place this outside of the conditions to catch these bugs in more situations.
420
+ pub fn debug_assert_shell_not_borrowed ( & self ) {
421
+ if cfg ! ( debug_assertions) {
422
+ self . shell ( ) . verbosity ( ) ;
423
+ }
424
+ }
425
+
415
426
/// Gets the path to the `rustdoc` executable.
416
427
pub fn rustdoc ( & self ) -> CargoResult < & Path > {
417
428
self . rustdoc
Original file line number Diff line number Diff line change @@ -389,10 +389,9 @@ fn acquire(
389
389
lock_try : & dyn Fn ( ) -> Result < ( ) , TryLockError > ,
390
390
lock_block : & dyn Fn ( ) -> io:: Result < ( ) > ,
391
391
) -> CargoResult < ( ) > {
392
- if cfg ! ( debug_assertions) {
393
- // Force borrow to catch invalid borrows outside of contention situations
394
- gctx. shell ( ) . verbosity ( ) ;
395
- }
392
+ // Ensure `shell` is not already in use,
393
+ // regardless of whether we hit contention or not
394
+ gctx. debug_assert_shell_not_borrowed ( ) ;
396
395
if try_acquire ( path, lock_try) ? {
397
396
return Ok ( ( ) ) ;
398
397
}
You can’t perform that action at this time.
0 commit comments