@@ -45,7 +45,7 @@ pub struct InspectCandidate<'a, 'tcx> {
4545 nested_goals : Vec < inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > > ,
4646 final_state : inspect:: CanonicalState < ' tcx , ( ) > ,
4747 result : QueryResult < ' tcx > ,
48- candidate_certainty : Option < Certainty > ,
48+ shallow_certainty : Certainty ,
4949}
5050
5151impl < ' a , ' tcx > InspectCandidate < ' a , ' tcx > {
@@ -59,15 +59,14 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
5959
6060 /// Certainty passed into `evaluate_added_goals_and_make_canonical_response`.
6161 ///
62- /// If this certainty is `Some( Yes) `, then we must be confident that the candidate
62+ /// If this certainty is `Yes`, then we must be confident that the candidate
6363 /// must hold iff it's nested goals hold. This is not true if the certainty is
64- /// `Some(Maybe)`, which suggests we forced ambiguity instead, or if it is `None`,
65- /// which suggests we may have not assembled any candidates at all.
64+ /// `Maybe(..)`, which suggests we forced ambiguity instead.
6665 ///
67- /// This is *not* the certainty of the candidate's nested evaluation, which can be
68- /// accessed with [`Self::result`] instead.
69- pub fn candidate_certainty ( & self ) -> Option < Certainty > {
70- self . candidate_certainty
66+ /// This is *not* the certainty of the candidate's full nested evaluation, which
67+ /// can be accessed with [`Self::result`] instead.
68+ pub fn shallow_certainty ( & self ) -> Certainty {
69+ self . shallow_certainty
7170 }
7271
7372 /// Visit all nested goals of this candidate without rolling
@@ -174,9 +173,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
174173 nested_goals : & mut Vec < inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > > ,
175174 probe : & inspect:: Probe < ' tcx > ,
176175 ) {
177- let mut candidate_certainty = None ;
178- let num_candidates = candidates. len ( ) ;
179-
176+ let mut shallow_certainty = None ;
180177 for step in & probe. steps {
181178 match step {
182179 & inspect:: ProbeStep :: AddGoal ( _source, goal) => nested_goals. push ( goal) ,
@@ -188,8 +185,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
188185 self . candidates_recur ( candidates, nested_goals, probe) ;
189186 nested_goals. truncate ( num_goals) ;
190187 }
191- inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty } => {
192- assert_eq ! ( candidate_certainty . replace( * shallow_certainty ) , None ) ;
188+ inspect:: ProbeStep :: MakeCanonicalResponse { shallow_certainty : c } => {
189+ assert_eq ! ( shallow_certainty . replace( * c ) , None ) ;
193190 }
194191 inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
195192 }
@@ -198,37 +195,27 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
198195 match probe. kind {
199196 inspect:: ProbeKind :: NormalizedSelfTyAssembly
200197 | inspect:: ProbeKind :: UnsizeAssembly
201- | inspect:: ProbeKind :: UpcastProjectionCompatibility
202- | inspect :: ProbeKind :: OpaqueTypeStorageLookup => ( ) ,
203- // We add a candidate for the root evaluation if there
198+ | inspect:: ProbeKind :: UpcastProjectionCompatibility => ( ) ,
199+
200+ // We add a candidate even for the root evaluation if there
204201 // is only one way to prove a given goal, e.g. for `WellFormed`.
205- //
206- // FIXME: This is currently wrong if we don't even try any
207- // candidates, e.g. for a trait goal, as in this case `candidates` is
208- // actually supposed to be empty.
209202 inspect:: ProbeKind :: Root { result }
210- | inspect:: ProbeKind :: TryNormalizeNonRigid { result } => {
211- if candidates. len ( ) == num_candidates {
203+ | inspect:: ProbeKind :: TryNormalizeNonRigid { result }
204+ | inspect:: ProbeKind :: TraitCandidate { source : _, result }
205+ | inspect:: ProbeKind :: OpaqueTypeStorageLookup { result } => {
206+ // We only add a candidate if `shallow_certainty` was set, which means
207+ // that we ended up calling `evaluate_added_goals_and_make_canonical_response`.
208+ if let Some ( shallow_certainty) = shallow_certainty {
212209 candidates. push ( InspectCandidate {
213210 goal : self ,
214211 kind : probe. kind ,
215212 nested_goals : nested_goals. clone ( ) ,
216213 final_state : probe. final_state ,
217214 result,
218- candidate_certainty ,
219- } )
215+ shallow_certainty ,
216+ } ) ;
220217 }
221218 }
222- inspect:: ProbeKind :: TraitCandidate { source : _, result } => {
223- candidates. push ( InspectCandidate {
224- goal : self ,
225- kind : probe. kind ,
226- nested_goals : nested_goals. clone ( ) ,
227- final_state : probe. final_state ,
228- result,
229- candidate_certainty,
230- } ) ;
231- }
232219 }
233220 }
234221
0 commit comments