@@ -39,6 +39,7 @@ pub use self::PickKind::*;
39
39
40
40
/// Boolean flag used to indicate if this search is for a suggestion
41
41
/// or not. If true, we can allow ambiguity and so forth.
42
+ #[ derive( Clone , Copy ) ]
42
43
pub struct IsSuggestion ( pub bool ) ;
43
44
44
45
struct ProbeContext < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
@@ -66,6 +67,8 @@ struct ProbeContext<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
66
67
/// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
67
68
/// for error reporting
68
69
unsatisfied_predicates : Vec < TraitRef < ' tcx > > ,
70
+
71
+ is_suggestion : IsSuggestion ,
69
72
}
70
73
71
74
impl < ' a , ' gcx , ' tcx > Deref for ProbeContext < ' a , ' gcx , ' tcx > {
@@ -277,8 +280,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
277
280
// this creates one big transaction so that all type variables etc
278
281
// that we create during the probe process are removed later
279
282
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
+ ) ;
282
286
283
287
probe_cx. assemble_inherent_candidates ( ) ;
284
288
match scope {
@@ -379,7 +383,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
379
383
mode : Mode ,
380
384
method_name : Option < ast:: Name > ,
381
385
return_type : Option < Ty < ' tcx > > ,
382
- steps : Rc < Vec < CandidateStep < ' tcx > > > )
386
+ steps : Rc < Vec < CandidateStep < ' tcx > > > ,
387
+ is_suggestion : IsSuggestion )
383
388
-> ProbeContext < ' a , ' gcx , ' tcx > {
384
389
ProbeContext {
385
390
fcx,
@@ -395,6 +400,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
395
400
allow_similar_names : false ,
396
401
private_candidate : None ,
397
402
unsatisfied_predicates : Vec :: new ( ) ,
403
+ is_suggestion,
398
404
}
399
405
}
400
406
@@ -952,14 +958,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
952
958
Some ( & mut unstable_candidates) ,
953
959
) ;
954
960
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 ( ) {
956
962
if let Ok ( p) = & pick {
957
963
// Emit a lint if there are unstable candidates alongside the stable ones.
958
964
//
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.
963
967
self . emit_unstable_name_collision_hint ( p, & unstable_candidates) ;
964
968
}
965
969
}
@@ -1265,7 +1269,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1265
1269
let steps = self . steps . clone ( ) ;
1266
1270
self . probe ( |_| {
1267
1271
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 ) ) ;
1269
1273
pcx. allow_similar_names = true ;
1270
1274
pcx. assemble_inherent_candidates ( ) ;
1271
1275
pcx. assemble_extension_candidates_for_traits_in_scope ( ast:: DUMMY_NODE_ID ) ?;
0 commit comments