@@ -123,6 +123,9 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
123
123
& inspect:: ProbeStep :: AddGoal ( goal) => nested_goals. push ( goal) ,
124
124
inspect:: ProbeStep :: EvaluateGoals ( _) => ( ) ,
125
125
inspect:: ProbeStep :: NestedProbe ( ref probe) => {
126
+ // Nested probes have to prove goals added in their parent
127
+ // but do not leak them, so we truncate the added goals
128
+ // afterwards.
126
129
let num_goals = nested_goals. len ( ) ;
127
130
self . candidates_recur ( candidates, nested_goals, probe) ;
128
131
nested_goals. truncate ( num_goals) ;
@@ -131,10 +134,25 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
131
134
}
132
135
133
136
match probe. kind {
134
- inspect:: ProbeKind :: Root { result : _ }
135
- | inspect:: ProbeKind :: NormalizedSelfTyAssembly
137
+ inspect:: ProbeKind :: NormalizedSelfTyAssembly
136
138
| inspect:: ProbeKind :: UnsizeAssembly
137
139
| inspect:: ProbeKind :: UpcastProjectionCompatibility => ( ) ,
140
+ // We add a candidate for the root evaluation if there
141
+ // is only one way to prove a given goal, e.g. for `WellFormed`.
142
+ //
143
+ // FIXME: This is currently wrong if we don't even try any
144
+ // candidates, e.g. for a trait goal, as in this case `candidates` is
145
+ // actually supposed to be empty.
146
+ inspect:: ProbeKind :: Root { result : _ } => {
147
+ if candidates. is_empty ( ) {
148
+ candidates. push ( InspectCandidate {
149
+ goal : self ,
150
+ kind : probe. kind ,
151
+ nested_goals : nested_goals. clone ( ) ,
152
+ result,
153
+ } ) ;
154
+ }
155
+ }
138
156
inspect:: ProbeKind :: MiscCandidate { name : _, result }
139
157
| inspect:: ProbeKind :: TraitCandidate { source : _, result } => {
140
158
candidates. push ( InspectCandidate {
@@ -167,15 +185,6 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
167
185
let mut nested_goals = vec ! [ ] ;
168
186
self . candidates_recur ( & mut candidates, & mut nested_goals, & last_eval_step. evaluation ) ;
169
187
170
- if candidates. is_empty ( ) {
171
- candidates. push ( InspectCandidate {
172
- goal : self ,
173
- kind : last_eval_step. evaluation . kind ,
174
- nested_goals,
175
- result : self . evaluation . evaluation . result ,
176
- } ) ;
177
- }
178
-
179
188
candidates
180
189
}
181
190
0 commit comments