diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs index b2e464bd7fb..5d1083090e3 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs @@ -180,34 +180,6 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { let mode = if infcx.intercrate { SolverMode::Coherence } else { SolverMode::Normal }; let mut search_graph = search_graph::SearchGraph::new(infcx.tcx, mode); - let inspect = { - let generate_proof_tree = match ( - infcx.tcx.sess.opts.unstable_opts.dump_solver_proof_tree, - infcx.tcx.sess.opts.unstable_opts.dump_solver_proof_tree_use_cache, - generate_proof_tree, - ) { - (_, Some(use_cache), GenerateProofTree::Yes(_)) => { - GenerateProofTree::Yes(DisableGlobalCache::from_bool(!use_cache)) - } - - (SolverProofTreeCondition::Always, use_cache, GenerateProofTree::No) => { - let use_cache = use_cache.unwrap_or(true); - GenerateProofTree::Yes(DisableGlobalCache::from_bool(!use_cache)) - } - - (_, None, GenerateProofTree::Yes(_)) => generate_proof_tree, - (SolverProofTreeCondition::OnRequest, _, _) => generate_proof_tree, - (SolverProofTreeCondition::OnError, _, _) => generate_proof_tree, - }; - - match generate_proof_tree { - GenerateProofTree::No => ProofTreeBuilder::new_noop(), - GenerateProofTree::Yes(global_cache_disabled) => { - ProofTreeBuilder::new_root(global_cache_disabled) - } - } - }; - let mut ecx = EvalCtxt { search_graph: &mut search_graph, infcx: infcx, @@ -221,7 +193,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { var_values: CanonicalVarValues::dummy(), nested_goals: NestedGoals::new(), tainted: Ok(()), - inspect, + inspect: ProofTreeBuilder::new_maybe_root(infcx.tcx, generate_proof_tree), }; let result = f(&mut ecx); diff --git a/compiler/rustc_trait_selection/src/solve/inspect.rs b/compiler/rustc_trait_selection/src/solve/inspect.rs index 1872c0c92d8..2061c3feb82 100644 --- a/compiler/rustc_trait_selection/src/solve/inspect.rs +++ b/compiler/rustc_trait_selection/src/solve/inspect.rs @@ -3,9 +3,11 @@ use rustc_middle::traits::solve::inspect::{self, CacheHit, CandidateKind}; use rustc_middle::traits::solve::{ CanonicalInput, Certainty, Goal, IsNormalizesToHack, QueryInput, QueryResult, }; -use rustc_middle::ty; +use rustc_middle::ty::{self, TyCtxt}; +use rustc_session::config::SolverProofTreeCondition; use super::eval_ctxt::DisableGlobalCache; +use super::GenerateProofTree; #[derive(Eq, PartialEq, Debug, Hash, HashStable)] pub struct WipGoalEvaluation<'tcx> { @@ -173,6 +175,37 @@ impl<'tcx> ProofTreeBuilder<'tcx> { self.disable_global_cache } + pub fn new_maybe_root( + tcx: TyCtxt<'tcx>, + generate_proof_tree: GenerateProofTree, + ) -> ProofTreeBuilder<'tcx> { + let generate_proof_tree = match ( + tcx.sess.opts.unstable_opts.dump_solver_proof_tree, + tcx.sess.opts.unstable_opts.dump_solver_proof_tree_use_cache, + generate_proof_tree, + ) { + (_, Some(use_cache), GenerateProofTree::Yes(_)) => { + GenerateProofTree::Yes(DisableGlobalCache::from_bool(!use_cache)) + } + + (SolverProofTreeCondition::Always, use_cache, GenerateProofTree::No) => { + let use_cache = use_cache.unwrap_or(true); + GenerateProofTree::Yes(DisableGlobalCache::from_bool(!use_cache)) + } + + (_, None, GenerateProofTree::Yes(_)) => generate_proof_tree, + (SolverProofTreeCondition::OnRequest, _, _) => generate_proof_tree, + (SolverProofTreeCondition::OnError, _, _) => generate_proof_tree, + }; + + match generate_proof_tree { + GenerateProofTree::No => ProofTreeBuilder::new_noop(), + GenerateProofTree::Yes(global_cache_disabled) => { + ProofTreeBuilder::new_root(global_cache_disabled) + } + } + } + pub fn new_root(disable_global_cache: DisableGlobalCache) -> ProofTreeBuilder<'tcx> { ProofTreeBuilder::new(DebugSolver::Root, disable_global_cache) }