Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid constructing an anyhow::Error when not necessary #8844

Merged
merged 3 commits into from
Nov 9, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ use std::cell::Cell;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::io;
use std::marker;
use std::mem;
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -838,9 +837,9 @@ impl<'cfg> DrainState<'cfg> {
let mut sender = FinishOnDrop {
messages: &messages,
id,
result: Err(format_err!("worker panicked")),
result: None,
};
sender.result = job.run(&state);
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,7 +853,7 @@ 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() && sender.result.is_ok() {
if state.rmeta_required.get() && sender.result.as_ref().unwrap().is_ok() {
messages.push(Message::Finish(id, Artifact::Metadata, Ok(())));
}

Expand All @@ -865,14 +864,21 @@ impl<'cfg> DrainState<'cfg> {
struct FinishOnDrop<'a> {
messages: &'a Queue<Message>,
id: JobId,
result: CargoResult<()>,
result: Option<CargoResult<()>>,
}

impl Drop for FinishOnDrop<'_> {
fn drop(&mut self) {
let msg = mem::replace(&mut self.result, Ok(()));
self.messages
.push(Message::Finish(self.id, Artifact::All, msg));
if let Some(result) = self.result.take() {
bjorn3 marked this conversation as resolved.
Show resolved Hide resolved
self.messages
.push(Message::Finish(self.id, Artifact::All, result));
} else {
self.messages.push(Message::Finish(
self.id,
Artifact::All,
Err(format_err!("worker panicked")),
));
}
}
}
};
Expand Down