@@ -45,7 +45,7 @@ pub struct InspectCandidate<'a, 'tcx> {
45
45
nested_goals : Vec < inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > > ,
46
46
final_state : inspect:: CanonicalState < ' tcx , ( ) > ,
47
47
result : QueryResult < ' tcx > ,
48
- candidate_certainty : Option < Certainty > ,
48
+ shallow_certainty : Certainty ,
49
49
}
50
50
51
51
impl < ' a , ' tcx > InspectCandidate < ' a , ' tcx > {
@@ -59,15 +59,14 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
59
59
60
60
/// Certainty passed into `evaluate_added_goals_and_make_canonical_response`.
61
61
///
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
63
63
/// 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.
66
65
///
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
71
70
}
72
71
73
72
/// Visit all nested goals of this candidate without rolling
@@ -174,9 +173,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
174
173
nested_goals : & mut Vec < inspect:: CanonicalState < ' tcx , Goal < ' tcx , ty:: Predicate < ' tcx > > > > ,
175
174
probe : & inspect:: Probe < ' tcx > ,
176
175
) {
177
- let mut candidate_certainty = None ;
178
- let num_candidates = candidates. len ( ) ;
179
-
176
+ let mut shallow_certainty = None ;
180
177
for step in & probe. steps {
181
178
match step {
182
179
& inspect:: ProbeStep :: AddGoal ( _source, goal) => nested_goals. push ( goal) ,
@@ -188,8 +185,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
188
185
self . candidates_recur ( candidates, nested_goals, probe) ;
189
186
nested_goals. truncate ( num_goals) ;
190
187
}
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 ) ;
193
190
}
194
191
inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
195
192
}
@@ -198,37 +195,27 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
198
195
match probe. kind {
199
196
inspect:: ProbeKind :: NormalizedSelfTyAssembly
200
197
| 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
204
201
// 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.
209
202
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 {
212
209
candidates. push ( InspectCandidate {
213
210
goal : self ,
214
211
kind : probe. kind ,
215
212
nested_goals : nested_goals. clone ( ) ,
216
213
final_state : probe. final_state ,
217
214
result,
218
- candidate_certainty ,
219
- } )
215
+ shallow_certainty ,
216
+ } ) ;
220
217
}
221
218
}
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
- }
232
219
}
233
220
}
234
221
0 commit comments