@@ -106,7 +106,7 @@ pub(crate) struct Candidate<'tcx> {
106106pub ( crate ) enum CandidateKind < ' tcx > {
107107 InherentImplCandidate { impl_def_id : DefId , receiver_steps : usize } ,
108108 ObjectCandidate ( ty:: PolyTraitRef < ' tcx > ) ,
109- TraitCandidate ( ty:: PolyTraitRef < ' tcx > ) ,
109+ TraitCandidate ( ty:: PolyTraitRef < ' tcx > , bool /* lint_ambiguous */ ) ,
110110 WhereClauseCandidate ( ty:: PolyTraitRef < ' tcx > ) ,
111111}
112112
@@ -235,7 +235,10 @@ pub(crate) struct Pick<'tcx> {
235235pub ( crate ) enum PickKind < ' tcx > {
236236 InherentImplPick ,
237237 ObjectPick ,
238- TraitPick ,
238+ TraitPick (
239+ // Is Ambiguously Imported
240+ bool ,
241+ ) ,
239242 WhereClausePick (
240243 // Trait
241244 ty:: PolyTraitRef < ' tcx > ,
@@ -560,7 +563,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
560563 probe_cx. push_candidate (
561564 Candidate {
562565 item,
563- kind : CandidateKind :: TraitCandidate ( ty:: Binder :: dummy ( trait_ref) ) ,
566+ kind : CandidateKind :: TraitCandidate (
567+ ty:: Binder :: dummy ( trait_ref) ,
568+ false ,
569+ ) ,
564570 import_ids : smallvec ! [ ] ,
565571 } ,
566572 false ,
@@ -1018,6 +1024,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10181024 self . assemble_extension_candidates_for_trait (
10191025 & trait_candidate. import_ids ,
10201026 trait_did,
1027+ trait_candidate. lint_ambiguous ,
10211028 ) ;
10221029 }
10231030 }
@@ -1029,7 +1036,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10291036 let mut duplicates = FxHashSet :: default ( ) ;
10301037 for trait_info in suggest:: all_traits ( self . tcx ) {
10311038 if duplicates. insert ( trait_info. def_id ) {
1032- self . assemble_extension_candidates_for_trait ( & smallvec ! [ ] , trait_info. def_id ) ;
1039+ self . assemble_extension_candidates_for_trait (
1040+ & smallvec ! [ ] ,
1041+ trait_info. def_id ,
1042+ false ,
1043+ ) ;
10331044 }
10341045 }
10351046 }
@@ -1055,6 +1066,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10551066 & mut self ,
10561067 import_ids : & SmallVec < [ LocalDefId ; 1 ] > ,
10571068 trait_def_id : DefId ,
1069+ lint_ambiguous : bool ,
10581070 ) {
10591071 let trait_args = self . fresh_args_for_item ( self . span , trait_def_id) ;
10601072 let trait_ref = ty:: TraitRef :: new_from_args ( self . tcx , trait_def_id, trait_args) ;
@@ -1076,7 +1088,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10761088 Candidate {
10771089 item,
10781090 import_ids : import_ids. clone ( ) ,
1079- kind : TraitCandidate ( bound_trait_ref) ,
1091+ kind : TraitCandidate ( bound_trait_ref, lint_ambiguous ) ,
10801092 } ,
10811093 false ,
10821094 ) ;
@@ -1099,7 +1111,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10991111 Candidate {
11001112 item,
11011113 import_ids : import_ids. clone ( ) ,
1102- kind : TraitCandidate ( ty:: Binder :: dummy ( trait_ref) ) ,
1114+ kind : TraitCandidate ( ty:: Binder :: dummy ( trait_ref) , lint_ambiguous ) ,
11031115 } ,
11041116 false ,
11051117 ) ;
@@ -1842,7 +1854,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18421854 ObjectCandidate ( _) | WhereClauseCandidate ( _) => {
18431855 CandidateSource :: Trait ( candidate. item . container_id ( self . tcx ) )
18441856 }
1845- TraitCandidate ( trait_ref) => self . probe ( |_| {
1857+ TraitCandidate ( trait_ref, _ ) => self . probe ( |_| {
18461858 let trait_ref = self . instantiate_binder_with_fresh_vars (
18471859 self . span ,
18481860 BoundRegionConversionTime :: FnCall ,
@@ -1872,7 +1884,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18721884 fn candidate_source_from_pick ( & self , pick : & Pick < ' tcx > ) -> CandidateSource {
18731885 match pick. kind {
18741886 InherentImplPick => CandidateSource :: Impl ( pick. item . container_id ( self . tcx ) ) ,
1875- ObjectPick | WhereClausePick ( _) | TraitPick => {
1887+ ObjectPick | WhereClausePick ( _) | TraitPick ( _ ) => {
18761888 CandidateSource :: Trait ( pick. item . container_id ( self . tcx ) )
18771889 }
18781890 }
@@ -1948,7 +1960,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
19481960 impl_bounds,
19491961 ) ) ;
19501962 }
1951- TraitCandidate ( poly_trait_ref) => {
1963+ TraitCandidate ( poly_trait_ref, _ ) => {
19521964 // Some trait methods are excluded for arrays before 2021.
19531965 // (`array.into_iter()` wants a slice iterator for compatibility.)
19541966 if let Some ( method_name) = self . method_name {
@@ -2274,11 +2286,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
22742286 }
22752287 }
22762288
2289+ let lint_ambiguous = match probes[ 0 ] . 0 . kind {
2290+ TraitCandidate ( _, lint) => lint,
2291+ _ => false ,
2292+ } ;
2293+
22772294 // FIXME: check the return type here somehow.
22782295 // If so, just use this trait and call it a day.
22792296 Some ( Pick {
22802297 item : probes[ 0 ] . 0 . item ,
2281- kind : TraitPick ,
2298+ kind : TraitPick ( lint_ambiguous ) ,
22822299 import_ids : probes[ 0 ] . 0 . import_ids . clone ( ) ,
22832300 autoderefs : 0 ,
22842301 autoref_or_ptr_adjustment : None ,
@@ -2348,9 +2365,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
23482365 }
23492366 }
23502367
2368+ let lint_ambiguous = match probes[ 0 ] . 0 . kind {
2369+ TraitCandidate ( _, lint) => lint,
2370+ _ => false ,
2371+ } ;
2372+
23512373 Some ( Pick {
23522374 item : child_candidate. item ,
2353- kind : TraitPick ,
2375+ kind : TraitPick ( lint_ambiguous ) ,
23542376 import_ids : child_candidate. import_ids . clone ( ) ,
23552377 autoderefs : 0 ,
23562378 autoref_or_ptr_adjustment : None ,
@@ -2613,7 +2635,7 @@ impl<'tcx> Candidate<'tcx> {
26132635 kind : match self . kind {
26142636 InherentImplCandidate { .. } => InherentImplPick ,
26152637 ObjectCandidate ( _) => ObjectPick ,
2616- TraitCandidate ( _) => TraitPick ,
2638+ TraitCandidate ( _, lint_ambiguous ) => TraitPick ( lint_ambiguous ) ,
26172639 WhereClauseCandidate ( trait_ref) => {
26182640 // Only trait derived from where-clauses should
26192641 // appear here, so they should not contain any
0 commit comments