Skip to content

Commit cc12919

Browse files
committed
Auto merge of #8844 - bjorn3:no_backtrace_capture, r=alexcrichton
Avoid constructing an anyhow::Error when not necessary `anyhow::Error` always captures a backtrace when created, which is expensive. Split out of #8837
2 parents 03976af + e643df0 commit cc12919

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/cargo/core/compiler/job_queue.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use std::cell::Cell;
5353
use std::collections::{BTreeMap, HashMap, HashSet};
5454
use std::io;
5555
use std::marker;
56-
use std::mem;
5756
use std::sync::Arc;
5857
use std::time::Duration;
5958

@@ -838,9 +837,9 @@ impl<'cfg> DrainState<'cfg> {
838837
let mut sender = FinishOnDrop {
839838
messages: &messages,
840839
id,
841-
result: Err(format_err!("worker panicked")),
840+
result: None,
842841
};
843-
sender.result = job.run(&state);
842+
sender.result = Some(job.run(&state));
844843

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

@@ -865,14 +864,17 @@ impl<'cfg> DrainState<'cfg> {
865864
struct FinishOnDrop<'a> {
866865
messages: &'a Queue<Message>,
867866
id: JobId,
868-
result: CargoResult<()>,
867+
result: Option<CargoResult<()>>,
869868
}
870869

871870
impl Drop for FinishOnDrop<'_> {
872871
fn drop(&mut self) {
873-
let msg = mem::replace(&mut self.result, Ok(()));
872+
let result = self
873+
.result
874+
.take()
875+
.unwrap_or_else(|| Err(format_err!("worker panicked")));
874876
self.messages
875-
.push(Message::Finish(self.id, Artifact::All, msg));
877+
.push(Message::Finish(self.id, Artifact::All, result));
876878
}
877879
}
878880
};

0 commit comments

Comments
 (0)