@@ -39,6 +39,7 @@ pub use self::PickKind::*;
3939
4040/// Boolean flag used to indicate if this search is for a suggestion
4141/// or not. If true, we can allow ambiguity and so forth.
42+ #[ derive( Clone , Copy ) ]
4243pub struct IsSuggestion ( pub bool ) ;
4344
4445struct ProbeContext < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
@@ -66,6 +67,8 @@ struct ProbeContext<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
6667 /// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
6768 /// for error reporting
6869 unsatisfied_predicates : Vec < TraitRef < ' tcx > > ,
70+
71+ is_suggestion : IsSuggestion ,
6972}
7073
7174impl < ' a , ' gcx , ' tcx > Deref for ProbeContext < ' a , ' gcx , ' tcx > {
@@ -277,8 +280,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
277280 // this creates one big transaction so that all type variables etc
278281 // that we create during the probe process are removed later
279282 self . probe ( |_| {
280- let mut probe_cx =
281- ProbeContext :: new ( self , span, mode, method_name, return_type, Rc :: new ( steps) ) ;
283+ let mut probe_cx = ProbeContext :: new (
284+ self , span, mode, method_name, return_type, Rc :: new ( steps) , is_suggestion,
285+ ) ;
282286
283287 probe_cx. assemble_inherent_candidates ( ) ;
284288 match scope {
@@ -379,7 +383,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
379383 mode : Mode ,
380384 method_name : Option < ast:: Name > ,
381385 return_type : Option < Ty < ' tcx > > ,
382- steps : Rc < Vec < CandidateStep < ' tcx > > > )
386+ steps : Rc < Vec < CandidateStep < ' tcx > > > ,
387+ is_suggestion : IsSuggestion )
383388 -> ProbeContext < ' a , ' gcx , ' tcx > {
384389 ProbeContext {
385390 fcx,
@@ -395,6 +400,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
395400 allow_similar_names : false ,
396401 private_candidate : None ,
397402 unsatisfied_predicates : Vec :: new ( ) ,
403+ is_suggestion,
398404 }
399405 }
400406
@@ -952,14 +958,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
952958 Some ( & mut unstable_candidates) ,
953959 ) ;
954960 if let Some ( pick) = res {
955- if !unstable_candidates . is_empty ( ) && !self_ty . is_ty_var ( ) {
961+ if !self . is_suggestion . 0 && !unstable_candidates . is_empty ( ) {
956962 if let Ok ( p) = & pick {
957963 // Emit a lint if there are unstable candidates alongside the stable ones.
958964 //
959- // Note, we suppress warning if `self_ty` is TyVar (`_`), since every
960- // possible candidates of every type will be considered, which leads to
961- // bogus ambiguity like `str::rsplit` vs `[_]::rsplit`. This condition is
962- // seen in `src/test/compile-fail/occurs-check-2.rs`.
965+ // We suppress warning if we're picking the method only because it is a
966+ // suggestion.
963967 self . emit_unstable_name_collision_hint ( p, & unstable_candidates) ;
964968 }
965969 }
@@ -1265,7 +1269,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
12651269 let steps = self . steps . clone ( ) ;
12661270 self . probe ( |_| {
12671271 let mut pcx = ProbeContext :: new ( self . fcx , self . span , self . mode , self . method_name ,
1268- self . return_type , steps) ;
1272+ self . return_type , steps, IsSuggestion ( true ) ) ;
12691273 pcx. allow_similar_names = true ;
12701274 pcx. assemble_inherent_candidates ( ) ;
12711275 pcx. assemble_extension_candidates_for_traits_in_scope ( ast:: DUMMY_NODE_ID ) ?;
0 commit comments