Skip to content

Commit 73b638d

Browse files
epagecharmitro
authored andcommitted
test: Add asserts to catch BorrowMutError's
This intentionally borrows from `RefCell`s before conditional code to try to prevent regressions like rust-lang#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 rust-lang#13647. Once I rebased, the panic went away. Co-authored-by: Ed Page <[email protected]>
1 parent 2c57622 commit 73b638d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/cargo/core/registry.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,11 @@ impl<'gctx> Registry for PackageRegistry<'gctx> {
739739
}
740740

741741
fn block_until_ready(&mut self) -> CargoResult<()> {
742+
if cfg!(debug_assertions) {
743+
// Force borrow to catch invalid borrows, regardless of which source is used and how it
744+
// happens to behave this time
745+
self.gctx.shell().verbosity();
746+
}
742747
for (source_id, source) in self.sources.sources_mut() {
743748
source
744749
.block_until_ready()

src/cargo/util/flock.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ fn acquire(
392392
lock_try: &dyn Fn() -> io::Result<()>,
393393
lock_block: &dyn Fn() -> io::Result<()>,
394394
) -> CargoResult<()> {
395+
if cfg!(debug_assertions) {
396+
// Force borrow to catch invalid borrows outside of contention situations
397+
gctx.shell().verbosity();
398+
}
395399
if try_acquire(path, lock_try)? {
396400
return Ok(());
397401
}

0 commit comments

Comments
 (0)