Skip to content

Commit

Permalink
Always send message through FinishOnDrop
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Nov 9, 2020
1 parent 821d8ea commit 5af00d0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,9 @@ impl<'cfg> DrainState<'cfg> {
let mut sender = FinishOnDrop {
messages: &messages,
id,
ok: false,
result: None,
};
let result = job.run(&state);
sender.ok = true;
sender.result = Some(job.run(&state));

// If the `rmeta_required` wasn't consumed but it was set
// previously, then we either have:
Expand All @@ -854,25 +853,26 @@ impl<'cfg> DrainState<'cfg> {
// we'll just naturally abort the compilation operation but for 1
// we need to make sure that the metadata is flagged as produced so
// send a synthetic message here.
if state.rmeta_required.get() && result.is_ok() {
if state.rmeta_required.get() && sender.result.as_ref().unwrap().is_ok() {
messages.push(Message::Finish(id, Artifact::Metadata, Ok(())));
}

messages.push(Message::Finish(id, Artifact::All, result));

// Use a helper struct with a `Drop` implementation to guarantee
// that a `Finish` message is sent even if our job panics. We
// shouldn't panic unless there's a bug in Cargo, so we just need
// to make sure nothing hangs by accident.
struct FinishOnDrop<'a> {
messages: &'a Queue<Message>,
id: JobId,
ok: bool,
result: Option<CargoResult<()>>,
}

impl Drop for FinishOnDrop<'_> {
fn drop(&mut self) {
if !self.ok {
if let Some(result) = self.result.take() {
self.messages
.push(Message::Finish(self.id, Artifact::All, result));
} else {
self.messages.push(Message::Finish(
self.id,
Artifact::All,
Expand Down

0 comments on commit 5af00d0

Please sign in to comment.