@@ -8,11 +8,10 @@ use rustc_hir::def_id::DefId;
8
8
use rustc_hir:: LangItem ;
9
9
use rustc_infer:: traits:: query:: NoSolution ;
10
10
use rustc_infer:: traits:: solve:: inspect:: ProbeKind ;
11
+ use rustc_infer:: traits:: solve:: MaybeCause ;
11
12
use rustc_infer:: traits:: specialization_graph:: LeafDef ;
12
13
use rustc_infer:: traits:: Reveal ;
13
- use rustc_middle:: traits:: solve:: {
14
- CandidateSource , CanonicalResponse , Certainty , Goal , QueryResult ,
15
- } ;
14
+ use rustc_middle:: traits:: solve:: { CandidateSource , Certainty , Goal , QueryResult } ;
16
15
use rustc_middle:: traits:: BuiltinImplSource ;
17
16
use rustc_middle:: ty:: fast_reject:: { DeepRejectCtxt , TreatParams } ;
18
17
use rustc_middle:: ty:: NormalizesTo ;
@@ -119,14 +118,15 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
119
118
120
119
fn probe_and_match_goal_against_assumption (
121
120
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
121
+ source : CandidateSource ,
122
122
goal : Goal < ' tcx , Self > ,
123
123
assumption : ty:: Clause < ' tcx > ,
124
124
then : impl FnOnce ( & mut EvalCtxt < ' _ , ' tcx > ) -> QueryResult < ' tcx > ,
125
- ) -> QueryResult < ' tcx > {
125
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
126
126
if let Some ( projection_pred) = assumption. as_projection_clause ( ) {
127
127
if projection_pred. projection_def_id ( ) == goal. predicate . def_id ( ) {
128
128
let tcx = ecx. tcx ( ) ;
129
- ecx. probe_misc_candidate ( "assumption" ) . enter ( |ecx| {
129
+ ecx. probe_trait_candidate ( source ) . enter ( |ecx| {
130
130
let assumption_projection_pred =
131
131
ecx. instantiate_binder_with_infer ( projection_pred) ;
132
132
ecx. eq (
@@ -300,14 +300,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
300
300
fn consider_error_guaranteed_candidate (
301
301
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
302
302
_guar : ErrorGuaranteed ,
303
- ) -> QueryResult < ' tcx > {
303
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
304
304
Err ( NoSolution )
305
305
}
306
306
307
307
fn consider_auto_trait_candidate (
308
308
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
309
309
goal : Goal < ' tcx , Self > ,
310
- ) -> QueryResult < ' tcx > {
310
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
311
311
ecx. tcx ( ) . dcx ( ) . span_delayed_bug (
312
312
ecx. tcx ( ) . def_span ( goal. predicate . def_id ( ) ) ,
313
313
"associated types not allowed on auto traits" ,
@@ -318,43 +318,43 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
318
318
fn consider_trait_alias_candidate (
319
319
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
320
320
goal : Goal < ' tcx , Self > ,
321
- ) -> QueryResult < ' tcx > {
321
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
322
322
bug ! ( "trait aliases do not have associated types: {:?}" , goal) ;
323
323
}
324
324
325
325
fn consider_builtin_sized_candidate (
326
326
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
327
327
goal : Goal < ' tcx , Self > ,
328
- ) -> QueryResult < ' tcx > {
328
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
329
329
bug ! ( "`Sized` does not have an associated type: {:?}" , goal) ;
330
330
}
331
331
332
332
fn consider_builtin_copy_clone_candidate (
333
333
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
334
334
goal : Goal < ' tcx , Self > ,
335
- ) -> QueryResult < ' tcx > {
335
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
336
336
bug ! ( "`Copy`/`Clone` does not have an associated type: {:?}" , goal) ;
337
337
}
338
338
339
339
fn consider_builtin_pointer_like_candidate (
340
340
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
341
341
goal : Goal < ' tcx , Self > ,
342
- ) -> QueryResult < ' tcx > {
342
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
343
343
bug ! ( "`PointerLike` does not have an associated type: {:?}" , goal) ;
344
344
}
345
345
346
346
fn consider_builtin_fn_ptr_trait_candidate (
347
347
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
348
348
goal : Goal < ' tcx , Self > ,
349
- ) -> QueryResult < ' tcx > {
349
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
350
350
bug ! ( "`FnPtr` does not have an associated type: {:?}" , goal) ;
351
351
}
352
352
353
353
fn consider_builtin_fn_trait_candidates (
354
354
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
355
355
goal : Goal < ' tcx , Self > ,
356
356
goal_kind : ty:: ClosureKind ,
357
- ) -> QueryResult < ' tcx > {
357
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
358
358
let tcx = ecx. tcx ( ) ;
359
359
let tupled_inputs_and_output =
360
360
match structural_traits:: extract_tupled_inputs_and_output_from_callable (
@@ -364,8 +364,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
364
364
) ? {
365
365
Some ( tupled_inputs_and_output) => tupled_inputs_and_output,
366
366
None => {
367
- return ecx
368
- . evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS ) ;
367
+ return ecx. forced_ambiguity ( MaybeCause :: Ambiguity ) ;
369
368
}
370
369
} ;
371
370
let output_is_sized_pred = tupled_inputs_and_output. map_bound ( |( _, output) | {
@@ -387,6 +386,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
387
386
// (FIXME: technically we only need to check this if the type is a fn ptr...)
388
387
Self :: probe_and_consider_implied_clause (
389
388
ecx,
389
+ CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Misc ) ,
390
390
goal,
391
391
pred,
392
392
[ goal. with ( tcx, output_is_sized_pred) ] ,
@@ -397,7 +397,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
397
397
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
398
398
goal : Goal < ' tcx , Self > ,
399
399
goal_kind : ty:: ClosureKind ,
400
- ) -> QueryResult < ' tcx > {
400
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
401
401
let tcx = ecx. tcx ( ) ;
402
402
403
403
let env_region = match goal_kind {
@@ -468,6 +468,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
468
468
// (FIXME: technically we only need to check this if the type is a fn ptr...)
469
469
Self :: probe_and_consider_implied_clause (
470
470
ecx,
471
+ CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Misc ) ,
471
472
goal,
472
473
pred,
473
474
[ goal. with ( tcx, output_is_sized_pred) ]
@@ -479,7 +480,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
479
480
fn consider_builtin_async_fn_kind_helper_candidate (
480
481
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
481
482
goal : Goal < ' tcx , Self > ,
482
- ) -> QueryResult < ' tcx > {
483
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
483
484
let [
484
485
closure_fn_kind_ty,
485
486
goal_kind_ty,
@@ -494,7 +495,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
494
495
495
496
// Bail if the upvars haven't been constrained.
496
497
if tupled_upvars_ty. expect_ty ( ) . is_ty_var ( ) {
497
- return ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS ) ;
498
+ return ecx. forced_ambiguity ( MaybeCause :: Ambiguity ) ;
498
499
}
499
500
500
501
let Some ( closure_kind) = closure_fn_kind_ty. expect_ty ( ) . to_opt_closure_kind ( ) else {
@@ -517,25 +518,27 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
517
518
borrow_region. expect_region ( ) ,
518
519
) ;
519
520
520
- ecx. instantiate_normalizes_to_term ( goal, upvars_ty. into ( ) ) ;
521
- ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
521
+ ecx. probe_builtin_trait_candidate ( BuiltinImplSource :: Misc ) . enter ( |ecx| {
522
+ ecx. instantiate_normalizes_to_term ( goal, upvars_ty. into ( ) ) ;
523
+ ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
524
+ } )
522
525
}
523
526
524
527
fn consider_builtin_tuple_candidate (
525
528
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
526
529
goal : Goal < ' tcx , Self > ,
527
- ) -> QueryResult < ' tcx > {
530
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
528
531
bug ! ( "`Tuple` does not have an associated type: {:?}" , goal) ;
529
532
}
530
533
531
534
fn consider_builtin_pointee_candidate (
532
535
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
533
536
goal : Goal < ' tcx , Self > ,
534
- ) -> QueryResult < ' tcx > {
537
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
535
538
let tcx = ecx. tcx ( ) ;
536
539
let metadata_def_id = tcx. require_lang_item ( LangItem :: Metadata , None ) ;
537
540
assert_eq ! ( metadata_def_id, goal. predicate. def_id( ) ) ;
538
- ecx. probe_misc_candidate ( "builtin pointee" ) . enter ( |ecx| {
541
+ ecx. probe_builtin_trait_candidate ( BuiltinImplSource :: Misc ) . enter ( |ecx| {
539
542
let metadata_ty = match goal. predicate . self_ty ( ) . kind ( ) {
540
543
ty:: Bool
541
544
| ty:: Char
@@ -614,7 +617,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
614
617
fn consider_builtin_future_candidate (
615
618
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
616
619
goal : Goal < ' tcx , Self > ,
617
- ) -> QueryResult < ' tcx > {
620
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
618
621
let self_ty = goal. predicate . self_ty ( ) ;
619
622
let ty:: Coroutine ( def_id, args) = * self_ty. kind ( ) else {
620
623
return Err ( NoSolution ) ;
@@ -630,6 +633,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
630
633
631
634
Self :: probe_and_consider_implied_clause (
632
635
ecx,
636
+ CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Misc ) ,
633
637
goal,
634
638
ty:: ProjectionPredicate {
635
639
projection_ty : ty:: AliasTy :: new ( ecx. tcx ( ) , goal. predicate . def_id ( ) , [ self_ty] ) ,
@@ -645,7 +649,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
645
649
fn consider_builtin_iterator_candidate (
646
650
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
647
651
goal : Goal < ' tcx , Self > ,
648
- ) -> QueryResult < ' tcx > {
652
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
649
653
let self_ty = goal. predicate . self_ty ( ) ;
650
654
let ty:: Coroutine ( def_id, args) = * self_ty. kind ( ) else {
651
655
return Err ( NoSolution ) ;
@@ -661,6 +665,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
661
665
662
666
Self :: probe_and_consider_implied_clause (
663
667
ecx,
668
+ CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Misc ) ,
664
669
goal,
665
670
ty:: ProjectionPredicate {
666
671
projection_ty : ty:: AliasTy :: new ( ecx. tcx ( ) , goal. predicate . def_id ( ) , [ self_ty] ) ,
@@ -676,14 +681,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
676
681
fn consider_builtin_fused_iterator_candidate (
677
682
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
678
683
goal : Goal < ' tcx , Self > ,
679
- ) -> QueryResult < ' tcx > {
684
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
680
685
bug ! ( "`FusedIterator` does not have an associated type: {:?}" , goal) ;
681
686
}
682
687
683
688
fn consider_builtin_async_iterator_candidate (
684
689
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
685
690
goal : Goal < ' tcx , Self > ,
686
- ) -> QueryResult < ' tcx > {
691
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
687
692
let self_ty = goal. predicate . self_ty ( ) ;
688
693
let ty:: Coroutine ( def_id, args) = * self_ty. kind ( ) else {
689
694
return Err ( NoSolution ) ;
@@ -695,7 +700,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
695
700
return Err ( NoSolution ) ;
696
701
}
697
702
698
- ecx. probe_misc_candidate ( "builtin AsyncIterator kind" ) . enter ( |ecx| {
703
+ ecx. probe_builtin_trait_candidate ( BuiltinImplSource :: Misc ) . enter ( |ecx| {
699
704
let expected_ty = ecx. next_ty_infer ( ) ;
700
705
// Take `AsyncIterator<Item = I>` and turn it into the corresponding
701
706
// coroutine yield ty `Poll<Option<I>>`.
@@ -719,7 +724,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
719
724
fn consider_builtin_coroutine_candidate (
720
725
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
721
726
goal : Goal < ' tcx , Self > ,
722
- ) -> QueryResult < ' tcx > {
727
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
723
728
let self_ty = goal. predicate . self_ty ( ) ;
724
729
let ty:: Coroutine ( def_id, args) = * self_ty. kind ( ) else {
725
730
return Err ( NoSolution ) ;
@@ -744,6 +749,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
744
749
745
750
Self :: probe_and_consider_implied_clause (
746
751
ecx,
752
+ CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Misc ) ,
747
753
goal,
748
754
ty:: ProjectionPredicate {
749
755
projection_ty : ty:: AliasTy :: new (
@@ -763,14 +769,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
763
769
fn consider_structural_builtin_unsize_candidates (
764
770
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
765
771
goal : Goal < ' tcx , Self > ,
766
- ) -> Vec < ( CanonicalResponse < ' tcx > , BuiltinImplSource ) > {
772
+ ) -> Vec < Candidate < ' tcx > > {
767
773
bug ! ( "`Unsize` does not have an associated type: {:?}" , goal) ;
768
774
}
769
775
770
776
fn consider_builtin_discriminant_kind_candidate (
771
777
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
772
778
goal : Goal < ' tcx , Self > ,
773
- ) -> QueryResult < ' tcx > {
779
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
774
780
let self_ty = goal. predicate . self_ty ( ) ;
775
781
let discriminant_ty = match * self_ty. kind ( ) {
776
782
ty:: Bool
@@ -813,7 +819,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
813
819
) ,
814
820
} ;
815
821
816
- ecx. probe_misc_candidate ( "builtin discriminant kind" ) . enter ( |ecx| {
822
+ ecx. probe_builtin_trait_candidate ( BuiltinImplSource :: Misc ) . enter ( |ecx| {
817
823
ecx. instantiate_normalizes_to_term ( goal, discriminant_ty. into ( ) ) ;
818
824
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
819
825
} )
@@ -822,7 +828,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
822
828
fn consider_builtin_async_destruct_candidate (
823
829
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
824
830
goal : Goal < ' tcx , Self > ,
825
- ) -> QueryResult < ' tcx > {
831
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
826
832
let self_ty = goal. predicate . self_ty ( ) ;
827
833
let async_destructor_ty = match * self_ty. kind ( ) {
828
834
ty:: Bool
@@ -865,7 +871,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
865
871
) ,
866
872
} ;
867
873
868
- ecx. probe_misc_candidate ( "builtin async destruct" ) . enter ( |ecx| {
874
+ ecx. probe_builtin_trait_candidate ( BuiltinImplSource :: Misc ) . enter ( |ecx| {
869
875
ecx. eq ( goal. param_env , goal. predicate . term , async_destructor_ty. into ( ) )
870
876
. expect ( "expected goal term to be fully unconstrained" ) ;
871
877
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
@@ -875,14 +881,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
875
881
fn consider_builtin_destruct_candidate (
876
882
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
877
883
goal : Goal < ' tcx , Self > ,
878
- ) -> QueryResult < ' tcx > {
884
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
879
885
bug ! ( "`Destruct` does not have an associated type: {:?}" , goal) ;
880
886
}
881
887
882
888
fn consider_builtin_transmute_candidate (
883
889
_ecx : & mut EvalCtxt < ' _ , ' tcx > ,
884
890
goal : Goal < ' tcx , Self > ,
885
- ) -> QueryResult < ' tcx > {
891
+ ) -> Result < Candidate < ' tcx > , NoSolution > {
886
892
bug ! ( "`BikeshedIntrinsicFrom` does not have an associated type: {:?}" , goal)
887
893
}
888
894
}
0 commit comments