@@ -49,7 +49,7 @@ pub(super) enum CandidateSource {
4949 /// Notable examples are auto traits, `Sized`, and `DiscriminantKind`.
5050 /// For a list of all traits with builtin impls, check out the
5151 /// [`EvalCtxt::assemble_builtin_impl_candidates`] method. Not
52- BuiltinImpl ,
52+ BuiltinImpl ( BuiltinImplSource ) ,
5353 /// An assumption from the environment.
5454 ///
5555 /// More precisely we've used the `n-th` assumption in the `param_env`.
@@ -87,6 +87,16 @@ pub(super) enum CandidateSource {
8787 AliasBound ,
8888}
8989
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+
90100/// Methods used to assemble candidates for either trait or projection goals.
91101pub ( super ) trait GoalKind < ' tcx > :
92102 TypeFoldable < TyCtxt < ' tcx > > + Copy + Eq + std:: fmt:: Display
@@ -295,7 +305,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
295305 // least structurally resolve the type one layer.
296306 if goal. predicate . self_ty ( ) . is_ty_var ( ) {
297307 return vec ! [ Candidate {
298- source: CandidateSource :: BuiltinImpl ,
308+ source: CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Ambiguity ) ,
299309 result: self
300310 . evaluate_added_goals_and_make_canonical_response( Certainty :: AMBIGUOUS )
301311 . unwrap( ) ,
@@ -344,7 +354,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
344354 let result = ecx. evaluate_added_goals_and_make_canonical_response (
345355 Certainty :: Maybe ( MaybeCause :: Overflow ) ,
346356 ) ?;
347- Ok ( vec ! [ Candidate { source: CandidateSource :: BuiltinImpl , result } ] )
357+ Ok ( vec ! [ Candidate {
358+ source: CandidateSource :: BuiltinImpl ( BuiltinImplSource :: Ambiguity ) ,
359+ result,
360+ } ] )
348361 } ,
349362 |ecx| {
350363 let normalized_ty = ecx. next_ty_infer ( ) ;
@@ -447,17 +460,21 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
447460 } ;
448461
449462 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+ } ) ,
453467 Err ( NoSolution ) => ( ) ,
454468 }
455469
456470 // There may be multiple unsize candidates for a trait with several supertraits:
457471 // `trait Foo: Bar<A> + Bar<B>` and `dyn Foo: Unsize<dyn Bar<_>>`
458472 if lang_items. unsize_trait ( ) == Some ( trait_def_id) {
459473 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+ } ) ;
461478 }
462479 }
463480 }
@@ -621,9 +638,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
621638 } ;
622639
623640 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+ } ) ,
627645 Err ( NoSolution ) => ( ) ,
628646 }
629647 }
@@ -688,9 +706,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
688706 }
689707
690708 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+ } ) ,
694713 Err ( NoSolution ) => ( ) ,
695714 }
696715 }
@@ -711,8 +730,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
711730 Err ( _) => match self
712731 . evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS )
713732 {
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+ } ) ,
716737 // FIXME: This will be reachable at some point if we're in
717738 // `assemble_candidates_after_normalizing_self_ty` and we get a
718739 // universe error. We'll deal with it at this point.
0 commit comments