Skip to content

Commit 035fd8b

Browse files
committed
Auto merge of #141542 - compiler-errors:rerun, r=<try>
[perf] Don't use ocx in `evaluate_obligation` in new solver Also tests how bad it is to rerun in `pred_known_to_hold_modulo_regions` in new solver. r? `@ghost`
2 parents aa57e46 + a7ba656 commit 035fd8b

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn pred_known_to_hold_modulo_regions<'tcx>(
221221

222222
if result.must_apply_modulo_regions() {
223223
true
224-
} else if result.may_apply() {
224+
} else if result.may_apply() && !infcx.next_trait_solver() {
225225
// Sometimes obligations are ambiguous because the recursive evaluator
226226
// is not smart enough, so we fall back to fulfillment when we're not certain
227227
// that an obligation holds or not. Even still, we must make sure that

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use rustc_macros::extension;
22
use rustc_middle::span_bug;
3+
use rustc_next_trait_solver::solve::{Certainty, GenerateProofTree, SolverDelegateEvalExt};
4+
use rustc_span::DUMMY_SP;
35

46
use crate::infer::InferCtxt;
57
use crate::infer::canonical::OriginalQueryValues;
6-
use crate::traits::{
7-
EvaluationResult, ObligationCtxt, OverflowError, PredicateObligation, SelectionContext,
8-
};
8+
use crate::solve::SolverDelegate;
9+
use crate::traits::{EvaluationResult, OverflowError, PredicateObligation, SelectionContext};
910

1011
#[extension(pub trait InferCtxtExt<'tcx>)]
1112
impl<'tcx> InferCtxt<'tcx> {
@@ -69,16 +70,14 @@ impl<'tcx> InferCtxt<'tcx> {
6970

7071
if self.next_trait_solver() {
7172
self.probe(|snapshot| {
72-
let ocx = ObligationCtxt::new(self);
73-
ocx.register_obligation(obligation.clone());
74-
let mut result = EvaluationResult::EvaluatedToOk;
75-
for error in ocx.select_all_or_error() {
76-
if error.is_true_error() {
77-
return Ok(EvaluationResult::EvaluatedToErr);
78-
} else {
79-
result = result.max(EvaluationResult::EvaluatedToAmbig);
80-
}
81-
}
73+
let mut result = match <&SolverDelegate<'tcx>>::from(self)
74+
.evaluate_root_goal(obligation.as_goal(), GenerateProofTree::No, DUMMY_SP)
75+
.0
76+
{
77+
Ok((_, Certainty::Yes)) => EvaluationResult::EvaluatedToOk,
78+
Ok((_, Certainty::Maybe(_))) => EvaluationResult::EvaluatedToAmbig,
79+
Err(_) => EvaluationResult::EvaluatedToErr,
80+
};
8281
if self.opaque_types_added_in_snapshot(snapshot) {
8382
result = result.max(EvaluationResult::EvaluatedToOkModuloOpaqueTypes);
8483
} else if self.region_constraints_added_in_snapshot(snapshot) {

0 commit comments

Comments
 (0)