@@ -93,17 +93,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9393 call_expr_id : hir:: HirId ,
9494 allow_private : bool ,
9595 ) -> bool {
96- let mode = probe:: Mode :: MethodCall ;
9796 match self . probe_for_name (
98- method_name. span ,
99- mode,
97+ probe:: Mode :: MethodCall ,
10098 method_name,
10199 IsSuggestion ( false ) ,
102100 self_ty,
103101 call_expr_id,
104102 ProbeScope :: TraitsInScope ,
105103 ) {
106- Ok ( ..) => true ,
104+ Ok ( pick) => {
105+ pick. maybe_emit_unstable_name_collision_hint (
106+ self . tcx ,
107+ method_name. span ,
108+ call_expr_id,
109+ ) ;
110+ true
111+ }
107112 Err ( NoMatch ( ..) ) => false ,
108113 Err ( Ambiguity ( ..) ) => true ,
109114 Err ( PrivateMatch ( ..) ) => allow_private,
@@ -125,10 +130,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
125130 ) {
126131 let params = self
127132 . probe_for_name (
128- method_name. span ,
129133 probe:: Mode :: MethodCall ,
130134 method_name,
131- IsSuggestion ( false ) ,
135+ IsSuggestion ( true ) ,
132136 self_ty,
133137 call_expr. hir_id ,
134138 ProbeScope :: TraitsInScope ,
@@ -175,7 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
175179 args : & ' tcx [ hir:: Expr < ' tcx > ] ,
176180 ) -> Result < MethodCallee < ' tcx > , MethodError < ' tcx > > {
177181 let pick =
178- self . lookup_probe ( span , segment. ident , self_ty, call_expr, ProbeScope :: TraitsInScope ) ?;
182+ self . lookup_probe ( segment. ident , self_ty, call_expr, ProbeScope :: TraitsInScope ) ?;
179183
180184 self . lint_dot_call_from_2018 ( self_ty, segment, span, call_expr, self_expr, & pick, args) ;
181185
@@ -200,42 +204,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200204 . mk_ref ( * region, ty:: TypeAndMut { ty : * t_type, mutbl : mutability. invert ( ) } ) ;
201205 // We probe again to see if there might be a borrow mutability discrepancy.
202206 match self . lookup_probe (
203- span,
204207 segment. ident ,
205208 trait_type,
206209 call_expr,
207210 ProbeScope :: TraitsInScope ,
208211 ) {
209- Ok ( ref new_pick) if * new_pick != pick => {
212+ Ok ( ref new_pick) if pick. differs_from ( new_pick ) => {
210213 needs_mut = true ;
211214 }
212215 _ => { }
213216 }
214217 }
215218
216219 // We probe again, taking all traits into account (not only those in scope).
217- let mut candidates = match self . lookup_probe (
218- span,
219- segment. ident ,
220- self_ty,
221- call_expr,
222- ProbeScope :: AllTraits ,
223- ) {
224- // If we find a different result the caller probably forgot to import a trait.
225- Ok ( ref new_pick) if * new_pick != pick => vec ! [ new_pick. item. container_id( self . tcx) ] ,
226- Err ( Ambiguity ( ref sources) ) => sources
227- . iter ( )
228- . filter_map ( |source| {
229- match * source {
230- // Note: this cannot come from an inherent impl,
231- // because the first probing succeeded.
232- CandidateSource :: Impl ( def) => self . tcx . trait_id_of_impl ( def) ,
233- CandidateSource :: Trait ( _) => None ,
234- }
235- } )
236- . collect ( ) ,
237- _ => Vec :: new ( ) ,
238- } ;
220+ let mut candidates =
221+ match self . lookup_probe ( segment. ident , self_ty, call_expr, ProbeScope :: AllTraits ) {
222+ // If we find a different result the caller probably forgot to import a trait.
223+ Ok ( ref new_pick) if pick. differs_from ( new_pick) => {
224+ vec ! [ new_pick. item. container_id( self . tcx) ]
225+ }
226+ Err ( Ambiguity ( ref sources) ) => sources
227+ . iter ( )
228+ . filter_map ( |source| {
229+ match * source {
230+ // Note: this cannot come from an inherent impl,
231+ // because the first probing succeeded.
232+ CandidateSource :: Impl ( def) => self . tcx . trait_id_of_impl ( def) ,
233+ CandidateSource :: Trait ( _) => None ,
234+ }
235+ } )
236+ . collect ( ) ,
237+ _ => Vec :: new ( ) ,
238+ } ;
239239 candidates. retain ( |candidate| * candidate != self . tcx . parent ( result. callee . def_id ) ) ;
240240
241241 return Err ( IllegalSizedBound ( candidates, needs_mut, span) ) ;
@@ -247,23 +247,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
247247 #[ instrument( level = "debug" , skip( self , call_expr) ) ]
248248 pub fn lookup_probe (
249249 & self ,
250- span : Span ,
251250 method_name : Ident ,
252251 self_ty : Ty < ' tcx > ,
253252 call_expr : & ' tcx hir:: Expr < ' tcx > ,
254253 scope : ProbeScope ,
255254 ) -> probe:: PickResult < ' tcx > {
256- let mode = probe:: Mode :: MethodCall ;
257- let self_ty = self . resolve_vars_if_possible ( self_ty) ;
258- self . probe_for_name (
259- span,
260- mode,
255+ let pick = self . probe_for_name (
256+ probe:: Mode :: MethodCall ,
261257 method_name,
262258 IsSuggestion ( false ) ,
263259 self_ty,
264260 call_expr. hir_id ,
265261 scope,
266- )
262+ ) ?;
263+ pick. maybe_emit_unstable_name_collision_hint ( self . tcx , method_name. span , call_expr. hir_id ) ;
264+ Ok ( pick)
267265 }
268266
269267 pub ( super ) fn obligation_for_method (
@@ -587,7 +585,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
587585 }
588586
589587 let pick = self . probe_for_name (
590- span,
591588 probe:: Mode :: Path ,
592589 method_name,
593590 IsSuggestion ( false ) ,
@@ -596,6 +593,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
596593 ProbeScope :: TraitsInScope ,
597594 ) ?;
598595
596+ pick. maybe_emit_unstable_name_collision_hint ( self . tcx , span, expr_id) ;
597+
599598 self . lint_fully_qualified_call_from_2018 (
600599 span,
601600 method_name,
0 commit comments