@@ -93,17 +93,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
93
93
call_expr_id : hir:: HirId ,
94
94
allow_private : bool ,
95
95
) -> bool {
96
- let mode = probe:: Mode :: MethodCall ;
97
96
match self . probe_for_name (
98
- method_name. span ,
99
- mode,
97
+ probe:: Mode :: MethodCall ,
100
98
method_name,
101
99
IsSuggestion ( false ) ,
102
100
self_ty,
103
101
call_expr_id,
104
102
ProbeScope :: TraitsInScope ,
105
103
) {
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
+ }
107
112
Err ( NoMatch ( ..) ) => false ,
108
113
Err ( Ambiguity ( ..) ) => true ,
109
114
Err ( PrivateMatch ( ..) ) => allow_private,
@@ -125,10 +130,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
125
130
) {
126
131
let params = self
127
132
. probe_for_name (
128
- method_name. span ,
129
133
probe:: Mode :: MethodCall ,
130
134
method_name,
131
- IsSuggestion ( false ) ,
135
+ IsSuggestion ( true ) ,
132
136
self_ty,
133
137
call_expr. hir_id ,
134
138
ProbeScope :: TraitsInScope ,
@@ -175,7 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
175
179
args : & ' tcx [ hir:: Expr < ' tcx > ] ,
176
180
) -> Result < MethodCallee < ' tcx > , MethodError < ' tcx > > {
177
181
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 ) ?;
179
183
180
184
self . lint_dot_call_from_2018 ( self_ty, segment, span, call_expr, self_expr, & pick, args) ;
181
185
@@ -200,42 +204,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200
204
. mk_ref ( * region, ty:: TypeAndMut { ty : * t_type, mutbl : mutability. invert ( ) } ) ;
201
205
// We probe again to see if there might be a borrow mutability discrepancy.
202
206
match self . lookup_probe (
203
- span,
204
207
segment. ident ,
205
208
trait_type,
206
209
call_expr,
207
210
ProbeScope :: TraitsInScope ,
208
211
) {
209
- Ok ( ref new_pick) if * new_pick != pick => {
212
+ Ok ( ref new_pick) if pick. differs_from ( new_pick ) => {
210
213
needs_mut = true ;
211
214
}
212
215
_ => { }
213
216
}
214
217
}
215
218
216
219
// 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
+ } ;
239
239
candidates. retain ( |candidate| * candidate != self . tcx . parent ( result. callee . def_id ) ) ;
240
240
241
241
return Err ( IllegalSizedBound ( candidates, needs_mut, span) ) ;
@@ -247,23 +247,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
247
247
#[ instrument( level = "debug" , skip( self , call_expr) ) ]
248
248
pub fn lookup_probe (
249
249
& self ,
250
- span : Span ,
251
250
method_name : Ident ,
252
251
self_ty : Ty < ' tcx > ,
253
252
call_expr : & ' tcx hir:: Expr < ' tcx > ,
254
253
scope : ProbeScope ,
255
254
) -> 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 ,
261
257
method_name,
262
258
IsSuggestion ( false ) ,
263
259
self_ty,
264
260
call_expr. hir_id ,
265
261
scope,
266
- )
262
+ ) ?;
263
+ pick. maybe_emit_unstable_name_collision_hint ( self . tcx , method_name. span , call_expr. hir_id ) ;
264
+ Ok ( pick)
267
265
}
268
266
269
267
pub ( super ) fn obligation_for_method (
@@ -587,7 +585,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
587
585
}
588
586
589
587
let pick = self . probe_for_name (
590
- span,
591
588
probe:: Mode :: Path ,
592
589
method_name,
593
590
IsSuggestion ( false ) ,
@@ -596,6 +593,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
596
593
ProbeScope :: TraitsInScope ,
597
594
) ?;
598
595
596
+ pick. maybe_emit_unstable_name_collision_hint ( self . tcx , span, expr_id) ;
597
+
599
598
self . lint_fully_qualified_call_from_2018 (
600
599
span,
601
600
method_name,
0 commit comments