Skip to content

Commit

Permalink
test: Add asserts to catch BorrowMutError's
Browse files Browse the repository at this point in the history
This intentionally borrows from `RefCell`s before conditional code
to try to prevent regressions like #13646 without exhaustively
covering every case that could hit these `BorrowMutError`s with
complicated tests.

I tested this by ensuring the registry code path panicked before
rebasing on top of #13647.
Once I rebased, the panic went away.
  • Loading branch information
epage committed Mar 26, 2024
1 parent 3a77350 commit 773f88f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cargo/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@ impl<'gctx> Registry for PackageRegistry<'gctx> {
}

fn block_until_ready(&mut self) -> CargoResult<()> {
if cfg!(debug_assertions) {
// Force borrow to catch invalid borrows, regardless of which source is used and how it
// happens to behave this time
self.gctx.shell().verbosity();
}
for (source_id, source) in self.sources.sources_mut() {
source
.block_until_ready()
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/util/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ fn acquire(
lock_try: &dyn Fn() -> io::Result<()>,
lock_block: &dyn Fn() -> io::Result<()>,
) -> CargoResult<()> {
if cfg!(debug_assertions) {
// Force borrow to catch invalid borrows outside of contention situations
gctx.shell().verbosity();
}
if try_acquire(path, lock_try)? {
return Ok(());
}
Expand Down

0 comments on commit 773f88f

Please sign in to comment.