Skip to content

Commit c771a4c

Browse files
committed
When activating for the better error messages don't waste time on the other backtrack frames
1 parent dd9ff1f commit c771a4c

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/cargo/core/resolver/mod.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,18 +1097,34 @@ fn activate_deps_loop(
10971097
has_past_conflicting_dep = true;
10981098
}
10991099
}
1100-
// if not has_another we we activate for the better error messages
1101-
frame.just_for_error_messages = has_past_conflicting_dep;
1102-
if !has_past_conflicting_dep
1103-
|| (!has_another && (just_here_for_the_error_messages || {
1100+
let activate_for_error_message = has_past_conflicting_dep && !has_another && {
1101+
// has_past_conflicting_dep -> One of this candidate deps will fail.
1102+
// !has_another -> If the candidate is not accepted we will backtrack.
1103+
1104+
// So the question is will the user see that we skipped this candidate?
1105+
just_here_for_the_error_messages || {
1106+
// make sure we know about all the possible conflicts
11041107
conflicting_activations
11051108
.extend(remaining_candidates.conflicting_prev_active.clone());
1109+
// test if backtracking will get to the user
11061110
find_candidate(
11071111
&mut backtrack_stack.clone(),
11081112
&parent,
11091113
&conflicting_activations,
11101114
).is_none()
1111-
})) {
1115+
}
1116+
};
1117+
if activate_for_error_message {
1118+
// We know one of this candidate deps will fail,
1119+
// which means we will fail,
1120+
// and that none of the backtrack frames will
1121+
// find a candidate that will help.
1122+
// So lets clean up the useless backtrack frames.
1123+
backtrack_stack.clear();
1124+
}
1125+
// if not has_another we we activate for the better error messages
1126+
frame.just_for_error_messages = has_past_conflicting_dep;
1127+
if !has_past_conflicting_dep || activate_for_error_message {
11121128
remaining_deps.push(frame);
11131129
} else {
11141130
trace!(

0 commit comments

Comments
 (0)