From 01f3da6b244c8cd9c72f2cf32321ec09d97145e6 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 14 Aug 2023 11:48:40 +0200 Subject: [PATCH] inspect: handle `None` in `nested` --- .../src/solve/inspect.rs | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_trait_selection/src/solve/inspect.rs b/compiler/rustc_trait_selection/src/solve/inspect.rs index 05c180f5049..b78abf0d544 100644 --- a/compiler/rustc_trait_selection/src/solve/inspect.rs +++ b/compiler/rustc_trait_selection/src/solve/inspect.rs @@ -182,11 +182,11 @@ impl<'tcx> ProofTreeBuilder<'tcx> { } } - fn nested(&self, state: impl Into>) -> Self { + fn nested>>(&self, state: impl FnOnce() -> T) -> Self { match &self.state { Some(prev_state) => Self { state: Some(Box::new(BuilderData { - tree: state.into(), + tree: state().into(), use_global_cache: prev_state.use_global_cache, })), }, @@ -255,11 +255,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> { goal: Goal<'tcx, ty::Predicate<'tcx>>, is_normalizes_to_hack: IsNormalizesToHack, ) -> ProofTreeBuilder<'tcx> { - if self.state.is_none() { - return ProofTreeBuilder { state: None }; - } - - self.nested(WipGoalEvaluation { + self.nested(|| WipGoalEvaluation { uncanonicalized_goal: goal, evaluation: None, is_normalizes_to_hack, @@ -271,11 +267,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> { &mut self, goal: CanonicalInput<'tcx>, ) -> ProofTreeBuilder<'tcx> { - if self.state.is_none() { - return ProofTreeBuilder { state: None }; - } - - self.nested(WipCanonicalGoalEvaluation { + self.nested(|| WipCanonicalGoalEvaluation { goal, cache_hit: None, evaluation_steps: vec![], @@ -336,11 +328,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> { &mut self, instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>, ) -> ProofTreeBuilder<'tcx> { - if self.state.is_none() { - return ProofTreeBuilder { state: None }; - } - - self.nested(WipGoalEvaluationStep { + self.nested(|| WipGoalEvaluationStep { instantiated_goal, added_goals_evaluations: vec![], candidates: vec![], @@ -362,11 +350,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> { } pub fn new_goal_candidate(&mut self) -> ProofTreeBuilder<'tcx> { - if self.state.is_none() { - return ProofTreeBuilder { state: None }; - } - - self.nested(WipGoalCandidate { + self.nested(|| WipGoalCandidate { added_goals_evaluations: vec![], candidates: vec![], kind: None, @@ -398,11 +382,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> { } pub fn new_evaluate_added_goals(&mut self) -> ProofTreeBuilder<'tcx> { - if self.state.is_none() { - return ProofTreeBuilder { state: None }; - } - - self.nested(WipAddedGoalsEvaluation { evaluations: vec![], result: None }) + self.nested(|| WipAddedGoalsEvaluation { evaluations: vec![], result: None }) } pub fn evaluate_added_goals_loop_start(&mut self) {