Skip to content

Commit 5b2b1c0

Browse files
committed
Auto merge of #13651 - weihanglo:borrow_mut, r=epage
test: Add asserts to catch BorrowMutError's ### What does this PR try to resolve? 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. ### How should we test and review this PR? I tested this by ensuring the registry code path panicked before rebasing on top of #13647. Once I rebased, the panic went away. ### Additional information Split off from #13649 to try to avoid appveyor
2 parents 3a77350 + 309cd93 commit 5b2b1c0

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)