Skip to content

Commit 4fdea65

Browse files
committed
Don't place side-effect expressions in assert! macros.
1 parent e0d8204 commit 4fdea65

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/cargo/sources/registry/http_remote.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,12 @@ impl<'cfg> HttpRegistry<'cfg> {
269269
};
270270
for (token, result) in results {
271271
let (mut download, handle) = self.downloads.pending.remove(&token).unwrap();
272-
assert!(self.downloads.pending_paths.remove(&download.path));
272+
let was_present = self.downloads.pending_paths.remove(&download.path);
273+
assert!(
274+
was_present,
275+
"expected pending_paths to contain {:?}",
276+
download.path
277+
);
273278
let mut handle = self.multi.remove(handle)?;
274279
let data = download.data.take();
275280
let url = self.full_url(&download.path);
@@ -403,17 +408,10 @@ impl<'cfg> HttpRegistry<'cfg> {
403408
for (dl, handle) in self.downloads.sleeping.to_retry() {
404409
let mut handle = self.multi.add(handle)?;
405410
handle.set_token(dl.token)?;
406-
assert!(
407-
self.downloads.pending_paths.insert(dl.path.to_path_buf()),
408-
"path queued for download more than once"
409-
);
410-
assert!(
411-
self.downloads
412-
.pending
413-
.insert(dl.token, (dl, handle))
414-
.is_none(),
415-
"dl token queued more than once"
416-
);
411+
let is_new = self.downloads.pending_paths.insert(dl.path.to_path_buf());
412+
assert!(is_new, "path queued for download more than once");
413+
let previous = self.downloads.pending.insert(dl.token, (dl, handle));
414+
assert!(previous.is_none(), "dl token queued more than once");
417415
}
418416
Ok(())
419417
}
@@ -477,8 +475,9 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
477475
let result =
478476
result.with_context(|| format!("download of {} failed", path.display()))?;
479477

478+
let is_new = self.fresh.insert(path.to_path_buf());
480479
assert!(
481-
self.fresh.insert(path.to_path_buf()),
480+
is_new,
482481
"downloaded the index file `{}` twice",
483482
path.display()
484483
);
@@ -634,10 +633,8 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
634633
let token = self.downloads.next;
635634
self.downloads.next += 1;
636635
debug!("downloading {} as {}", path.display(), token);
637-
assert!(
638-
self.downloads.pending_paths.insert(path.to_path_buf()),
639-
"path queued for download more than once"
640-
);
636+
let is_new = self.downloads.pending_paths.insert(path.to_path_buf());
637+
assert!(is_new, "path queued for download more than once");
641638

642639
// Each write should go to self.downloads.pending[&token].data.
643640
// Since the write function must be 'static, we access downloads through a thread-local.

0 commit comments

Comments
 (0)