mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
Abstract away an assertions details
This will make it easier to change the implementation in the future.
This commit is contained in:
parent
b624a44978
commit
bfb8479d83
@ -800,11 +800,9 @@ impl<'gctx> Registry for PackageRegistry<'gctx> {
|
|||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
fn block_until_ready(&mut self) -> CargoResult<()> {
|
fn block_until_ready(&mut self) -> CargoResult<()> {
|
||||||
if cfg!(debug_assertions) {
|
// Ensure `shell` is not already in use,
|
||||||
// Force borrow to catch invalid borrows, regardless of which source is used and how it
|
// regardless of which source is used and how it happens to behave this time
|
||||||
// happens to behave this time
|
self.gctx.debug_assert_shell_not_borrowed();
|
||||||
self.gctx.shell().verbosity();
|
|
||||||
}
|
|
||||||
for (source_id, source) in self.sources.sources_mut() {
|
for (source_id, source) in self.sources.sources_mut() {
|
||||||
source
|
source
|
||||||
.block_until_ready()
|
.block_until_ready()
|
||||||
|
@ -412,6 +412,17 @@ impl GlobalContext {
|
|||||||
self.shell.borrow_mut()
|
self.shell.borrow_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Assert [`Self::shell`] is not in use
|
||||||
|
///
|
||||||
|
/// Testing might not identify bugs with two accesses to `shell` at once
|
||||||
|
/// due to conditional logic,
|
||||||
|
/// so place this outside of the conditions to catch these bugs in more situations.
|
||||||
|
pub fn debug_assert_shell_not_borrowed(&self) {
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
self.shell().verbosity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the path to the `rustdoc` executable.
|
/// Gets the path to the `rustdoc` executable.
|
||||||
pub fn rustdoc(&self) -> CargoResult<&Path> {
|
pub fn rustdoc(&self) -> CargoResult<&Path> {
|
||||||
self.rustdoc
|
self.rustdoc
|
||||||
|
@ -389,10 +389,9 @@ fn acquire(
|
|||||||
lock_try: &dyn Fn() -> Result<(), TryLockError>,
|
lock_try: &dyn Fn() -> Result<(), TryLockError>,
|
||||||
lock_block: &dyn Fn() -> io::Result<()>,
|
lock_block: &dyn Fn() -> io::Result<()>,
|
||||||
) -> CargoResult<()> {
|
) -> CargoResult<()> {
|
||||||
if cfg!(debug_assertions) {
|
// Ensure `shell` is not already in use,
|
||||||
// Force borrow to catch invalid borrows outside of contention situations
|
// regardless of whether we hit contention or not
|
||||||
gctx.shell().verbosity();
|
gctx.debug_assert_shell_not_borrowed();
|
||||||
}
|
|
||||||
if try_acquire(path, lock_try)? {
|
if try_acquire(path, lock_try)? {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user