Skip to content

Commit dc6d219

Browse files
Store maximum queue length
Previously, the queue length was constantly decreasing as we built crates, which meant that we were incorrectly displaying the progress bar. In debug builds, this even led to panics (due to underflow on subtraction).
1 parent b68b097 commit dc6d219

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/cargo/core/compiler/job_queue.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ pub struct JobQueue<'a, 'cfg> {
9595
/// It is created from JobQueue when we have fully assembled the crate graph
9696
/// (i.e., all package dependencies are known).
9797
struct DrainState<'a, 'cfg> {
98+
// This is the length of the DependencyQueue when starting out
99+
total_units: usize,
100+
98101
queue: DependencyQueue<Unit<'a>, Artifact, Job>,
99102
tx: Sender<Message>,
100103
rx: Receiver<Message>,
@@ -341,6 +344,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
341344
let (tx, rx) = channel();
342345
let progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
343346
let state = DrainState {
347+
total_units: self.queue.len(),
344348
queue: self.queue,
345349
tx,
346350
rx,
@@ -713,7 +717,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
713717
.collect::<Vec<_>>();
714718
drop(self.progress.tick_now(
715719
self.finished,
716-
self.queue.len(),
720+
self.total_units,
717721
&format!(": {}", active_names.join(", ")),
718722
));
719723
}

src/cargo/util/progress.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ impl<'cfg> State<'cfg> {
224224

225225
impl Format {
226226
fn progress(&self, cur: usize, max: usize) -> Option<String> {
227+
assert!(cur <= max);
227228
// Render the percentage at the far right and then figure how long the
228229
// progress bar is
229230
let pct = (cur as f64) / (max as f64);

0 commit comments

Comments
 (0)