From 8304b17c87d5943f719a76621a09127c207cc510 Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Tue, 6 Mar 2018 14:05:59 -0500 Subject: [PATCH] don't clone a BacktrackFrame if we are not going to backtrack --- src/cargo/core/resolver/mod.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index b5ca6d9cba4..1ee360f40f5 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -892,15 +892,19 @@ fn activate_deps_loop( // We have a candidate. Clone a `BacktrackFrame` // so we can add it to the `backtrack_stack` if activation succeeds. // We clone now in case `activate` changes `cx` and then fails. - let backtrack = BacktrackFrame { - cur, - context_backup: Context::clone(&cx), - deps_backup: >::clone(&remaining_deps), - remaining_candidates: remaining_candidates.clone(), - parent: Summary::clone(&parent), - dep: Dependency::clone(&dep), - features: Rc::clone(&features), - conflicting_activations: conflicting_activations.clone(), + let backtrack = if has_another { + Some(BacktrackFrame { + cur, + context_backup: Context::clone(&cx), + deps_backup: >::clone(&remaining_deps), + remaining_candidates: remaining_candidates.clone(), + parent: Summary::clone(&parent), + dep: Dependency::clone(&dep), + features: Rc::clone(&features), + conflicting_activations: conflicting_activations.clone(), + }) + } else { + None }; let method = Method::Required { @@ -925,12 +929,14 @@ fn activate_deps_loop( // Add an entry to the `backtrack_stack` so // we can try the next one if this one fails. if successfully_activated { - if has_another { - backtrack_stack.push(backtrack); + if let Some(b) = backtrack { + backtrack_stack.push(b); } } else { - // `activate` changed `cx` and then failed so put things back. - cx = backtrack.context_backup; + if let Some(b) = backtrack { + // `activate` changed `cx` and then failed so put things back. + cx = b.context_backup; + } // else we are just using the cx for the error message so we can live with a corrupted one } } }