@@ -13,9 +13,9 @@ use rustc_next_trait_solver::solve::{GenerateProofTree, SolverDelegateEvalExt as
13
13
use rustc_type_ir:: solve:: NoSolution ;
14
14
use tracing:: { instrument, trace} ;
15
15
16
- use crate :: solve:: Certainty ;
17
16
use crate :: solve:: delegate:: SolverDelegate ;
18
17
use crate :: solve:: inspect:: { self , ProofTreeInferCtxtExt , ProofTreeVisitor } ;
18
+ use crate :: solve:: { Certainty , deeply_normalize_for_diagnostics} ;
19
19
use crate :: traits:: { FulfillmentError , FulfillmentErrorCode , wf} ;
20
20
21
21
pub ( super ) fn fulfillment_error_for_no_solution < ' tcx > (
@@ -153,10 +153,17 @@ fn find_best_leaf_obligation<'tcx>(
153
153
// means the leaf obligation may be incorrect.
154
154
infcx
155
155
. fudge_inference_if_ok ( || {
156
+ let goal = obligation. as_goal ( ) ;
156
157
infcx
157
158
. visit_proof_tree (
158
- obligation. as_goal ( ) ,
159
- & mut BestObligation { obligation : obligation. clone ( ) , consider_ambiguities } ,
159
+ goal,
160
+ & mut BestObligation {
161
+ obligation : obligation. with (
162
+ infcx. tcx ,
163
+ deeply_normalize_for_diagnostics ( infcx, goal. param_env , goal. predicate ) ,
164
+ ) ,
165
+ consider_ambiguities,
166
+ } ,
160
167
)
161
168
. break_value ( )
162
169
. ok_or ( ( ) )
@@ -239,21 +246,18 @@ impl<'tcx> BestObligation<'tcx> {
239
246
let param_env = candidate. goal ( ) . goal ( ) . param_env ;
240
247
let body_id = self . obligation . cause . body_id ;
241
248
242
- for obligation in wf:: unnormalized_obligations ( infcx, param_env, arg, self . span ( ) , body_id)
243
- . into_iter ( )
244
- . flatten ( )
249
+ for mut obligation in
250
+ wf:: unnormalized_obligations ( infcx, param_env, arg, self . span ( ) , body_id)
251
+ . into_iter ( )
252
+ . flatten ( )
245
253
{
246
254
let nested_goal = candidate. instantiate_proof_tree_for_nested_goal (
247
255
GoalSource :: Misc ,
248
256
obligation. as_goal ( ) ,
249
257
self . span ( ) ,
250
258
) ;
251
- // Skip nested goals that aren't the *reason* for our goal's failure.
252
- match ( self . consider_ambiguities , nested_goal. result ( ) ) {
253
- ( true , Ok ( Certainty :: Maybe ( MaybeCause :: Ambiguity ) ) ) | ( false , Err ( _) ) => { }
254
- _ => continue ,
255
- }
256
-
259
+ obligation. predicate =
260
+ deeply_normalize_for_diagnostics ( infcx, param_env, obligation. predicate ) ;
257
261
self . with_derived_obligation ( obligation, |this| nested_goal. visit_with ( this) ) ?;
258
262
}
259
263
@@ -277,8 +281,12 @@ impl<'tcx> BestObligation<'tcx> {
277
281
infer_term. into ( ) ,
278
282
ty:: AliasRelationDirection :: Equate ,
279
283
) ;
280
- let obligation =
281
- Obligation :: new ( tcx, self . obligation . cause . clone ( ) , goal. goal ( ) . param_env , pred) ;
284
+ let obligation = Obligation :: new (
285
+ tcx,
286
+ self . obligation . cause . clone ( ) ,
287
+ goal. goal ( ) . param_env ,
288
+ deeply_normalize_for_diagnostics ( goal. infcx ( ) , goal. goal ( ) . param_env , pred) ,
289
+ ) ;
282
290
self . with_derived_obligation ( obligation, |this| {
283
291
goal. infcx ( ) . visit_proof_tree_at_depth (
284
292
goal. goal ( ) . with ( tcx, pred) ,
@@ -307,7 +315,11 @@ impl<'tcx> BestObligation<'tcx> {
307
315
tcx,
308
316
self . obligation . cause . clone ( ) ,
309
317
goal. goal ( ) . param_env ,
310
- alias. trait_ref ( tcx) ,
318
+ deeply_normalize_for_diagnostics (
319
+ goal. infcx ( ) ,
320
+ goal. goal ( ) . param_env ,
321
+ alias. trait_ref ( tcx) ,
322
+ ) ,
311
323
) ;
312
324
self . with_derived_obligation ( obligation, |this| {
313
325
goal. infcx ( ) . visit_proof_tree_at_depth (
@@ -430,12 +442,14 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
430
442
for nested_goal in nested_goals {
431
443
trace ! ( nested_goal = ?( nested_goal. goal( ) , nested_goal. source( ) , nested_goal. result( ) ) ) ;
432
444
433
- let nested_pred = nested_goal. goal ( ) . predicate ;
434
-
435
445
let make_obligation = |cause| Obligation {
436
446
cause,
437
447
param_env : nested_goal. goal ( ) . param_env ,
438
- predicate : nested_pred,
448
+ predicate : deeply_normalize_for_diagnostics (
449
+ nested_goal. infcx ( ) ,
450
+ nested_goal. goal ( ) . param_env ,
451
+ nested_goal. goal ( ) . predicate ,
452
+ ) ,
439
453
recursion_depth : self . obligation . recursion_depth + 1 ,
440
454
} ;
441
455
@@ -508,7 +522,13 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
508
522
&& !projection_clause. bound_vars ( ) . is_empty ( )
509
523
{
510
524
let pred = projection_clause. map_bound ( |proj| proj. projection_term . trait_ref ( tcx) ) ;
511
- self . with_derived_obligation ( self . obligation . with ( tcx, pred) , |this| {
525
+ let obligation = Obligation :: new (
526
+ tcx,
527
+ self . obligation . cause . clone ( ) ,
528
+ goal. goal ( ) . param_env ,
529
+ deeply_normalize_for_diagnostics ( goal. infcx ( ) , goal. goal ( ) . param_env , pred) ,
530
+ ) ;
531
+ self . with_derived_obligation ( obligation, |this| {
512
532
goal. infcx ( ) . visit_proof_tree_at_depth (
513
533
goal. goal ( ) . with ( tcx, pred) ,
514
534
goal. depth ( ) + 1 ,
0 commit comments