@@ -49,7 +49,7 @@ pub(super) enum CandidateSource {
49
49
/// Notable examples are auto traits, `Sized`, and `DiscriminantKind`.
50
50
/// For a list of all traits with builtin impls, check out the
51
51
/// [`EvalCtxt::assemble_builtin_impl_candidates`] method. Not
52
- BuiltinImpl ,
52
+ BuiltinImpl ( BuiltinImplSource ) ,
53
53
/// An assumption from the environment.
54
54
///
55
55
/// More precisely we've used the `n-th` assumption in the `param_env`.
@@ -87,6 +87,16 @@ pub(super) enum CandidateSource {
87
87
AliasBound ,
88
88
}
89
89
90
+ /// Records additional information about what kind of built-in impl this is.
91
+ /// This should only be used by selection.
92
+ #[ derive( Debug , Clone , Copy ) ]
93
+ pub ( super ) enum BuiltinImplSource {
94
+ TraitUpcasting ,
95
+ Object ,
96
+ Misc ,
97
+ Ambiguity ,
98
+ }
99
+
90
100
/// Methods used to assemble candidates for either trait or projection goals.
91
101
pub ( super ) trait GoalKind < ' tcx > :
92
102
TypeFoldable < TyCtxt < ' tcx > > + Copy + Eq + std:: fmt:: Display
@@ -295,7 +305,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
295
305
// least structurally resolve the type one layer.
296
306
if goal. predicate . self_ty ( ) . is_ty_var ( ) {
297
307
return vec ! [ Candidate {
298
- source: CandidateSource :: BuiltinImpl ,
308
+ source: CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Ambiguity ) ,
299
309
result: self
300
310
. evaluate_added_goals_and_make_canonical_response( Certainty :: AMBIGUOUS )
301
311
. unwrap( ) ,
@@ -344,7 +354,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
344
354
let result = ecx. evaluate_added_goals_and_make_canonical_response (
345
355
Certainty :: Maybe ( MaybeCause :: Overflow ) ,
346
356
) ?;
347
- Ok ( vec ! [ Candidate { source: CandidateSource :: BuiltinImpl , result } ] )
357
+ Ok ( vec ! [ Candidate {
358
+ source: CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Ambiguity ) ,
359
+ result,
360
+ } ] )
348
361
} ,
349
362
|ecx| {
350
363
let normalized_ty = ecx. next_ty_infer ( ) ;
@@ -447,17 +460,21 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
447
460
} ;
448
461
449
462
match result {
450
- Ok ( result) => {
451
- candidates. push ( Candidate { source : CandidateSource :: BuiltinImpl , result } )
452
- }
463
+ Ok ( result) => candidates. push ( Candidate {
464
+ source : CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Misc ) ,
465
+ result,
466
+ } ) ,
453
467
Err ( NoSolution ) => ( ) ,
454
468
}
455
469
456
470
// There may be multiple unsize candidates for a trait with several supertraits:
457
471
// `trait Foo: Bar<A> + Bar<B>` and `dyn Foo: Unsize<dyn Bar<_>>`
458
472
if lang_items. unsize_trait ( ) == Some ( trait_def_id) {
459
473
for result in G :: consider_builtin_dyn_upcast_candidates ( self , goal) {
460
- candidates. push ( Candidate { source : CandidateSource :: BuiltinImpl , result } ) ;
474
+ candidates. push ( Candidate {
475
+ source : CandidateSource :: BuiltinImpl ( BuiltinImplSource :: TraitUpcasting ) ,
476
+ result,
477
+ } ) ;
461
478
}
462
479
}
463
480
}
@@ -621,9 +638,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
621
638
} ;
622
639
623
640
match result {
624
- Ok ( result) => {
625
- candidates. push ( Candidate { source : CandidateSource :: BuiltinImpl , result } )
626
- }
641
+ Ok ( result) => candidates. push ( Candidate {
642
+ source : CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Misc ) ,
643
+ result,
644
+ } ) ,
627
645
Err ( NoSolution ) => ( ) ,
628
646
}
629
647
}
@@ -688,9 +706,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
688
706
}
689
707
690
708
match G :: consider_object_bound_candidate ( self , goal, assumption) {
691
- Ok ( result) => {
692
- candidates. push ( Candidate { source : CandidateSource :: BuiltinImpl , result } )
693
- }
709
+ Ok ( result) => candidates. push ( Candidate {
710
+ source : CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Object ) ,
711
+ result,
712
+ } ) ,
694
713
Err ( NoSolution ) => ( ) ,
695
714
}
696
715
}
@@ -711,8 +730,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
711
730
Err ( _) => match self
712
731
. evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS )
713
732
{
714
- Ok ( result) => candidates
715
- . push ( Candidate { source : CandidateSource :: BuiltinImpl , result } ) ,
733
+ Ok ( result) => candidates. push ( Candidate {
734
+ source : CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Ambiguity ) ,
735
+ result,
736
+ } ) ,
716
737
// FIXME: This will be reachable at some point if we're in
717
738
// `assemble_candidates_after_normalizing_self_ty` and we get a
718
739
// universe error. We'll deal with it at this point.
0 commit comments