@@ -182,8 +182,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
182
182
self_expr : & ' tcx hir:: Expr < ' tcx > ,
183
183
args : & ' tcx [ hir:: Expr < ' tcx > ] ,
184
184
) -> Result < MethodCallee < ' tcx > , MethodError < ' tcx > > {
185
- let pick =
186
- self . lookup_probe ( segment. ident , self_ty, call_expr, ProbeScope :: TraitsInScope ) ?;
185
+ let probe_scope =
186
+ segment. res . opt_def_id ( ) . map_or ( ProbeScope :: TraitsInScope , ProbeScope :: DefId ) ;
187
+ let pick = self . lookup_probe ( segment. ident , self_ty, call_expr, probe_scope) ?;
187
188
188
189
self . lint_dot_call_from_2018 ( self_ty, segment, span, call_expr, self_expr, & pick, args) ;
189
190
@@ -202,12 +203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
202
203
if let ty:: Ref ( region, t_type, mutability) = self_ty. kind ( ) {
203
204
let trait_type = Ty :: new_ref ( self . tcx , * region, * t_type, mutability. invert ( ) ) ;
204
205
// We probe again to see if there might be a borrow mutability discrepancy.
205
- match self . lookup_probe (
206
- segment. ident ,
207
- trait_type,
208
- call_expr,
209
- ProbeScope :: TraitsInScope ,
210
- ) {
206
+ match self . lookup_probe ( segment. ident , trait_type, call_expr, probe_scope) {
211
207
Ok ( ref new_pick) if pick. differs_from ( new_pick) => {
212
208
needs_mut = new_pick. self_ty . ref_mutability ( ) != self_ty. ref_mutability ( ) ;
213
209
}
@@ -216,29 +212,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
216
212
}
217
213
218
214
// We probe again, taking all traits into account (not only those in scope).
219
- let candidates = match self . lookup_probe_for_diagnostic (
220
- segment. ident ,
221
- self_ty,
222
- call_expr,
223
- ProbeScope :: AllTraits ,
224
- None ,
225
- ) {
226
- // If we find a different result the caller probably forgot to import a trait.
227
- Ok ( ref new_pick) if pick. differs_from ( new_pick) => {
228
- vec ! [ new_pick. item. container_id( self . tcx) ]
215
+ let candidates = if probe_scope == ProbeScope :: TraitsInScope {
216
+ match self . lookup_probe_for_diagnostic (
217
+ segment. ident ,
218
+ self_ty,
219
+ call_expr,
220
+ ProbeScope :: AllTraits ,
221
+ None ,
222
+ ) {
223
+ // If we find a different result the caller probably forgot to import a trait.
224
+ Ok ( ref new_pick) if pick. differs_from ( new_pick) => {
225
+ vec ! [ new_pick. item. container_id( self . tcx) ]
226
+ }
227
+ Err ( Ambiguity ( ref sources) ) => sources
228
+ . iter ( )
229
+ . filter_map ( |source| {
230
+ match * source {
231
+ // Note: this cannot come from an inherent impl,
232
+ // because the first probing succeeded.
233
+ CandidateSource :: Impl ( def) => self . tcx . trait_id_of_impl ( def) ,
234
+ CandidateSource :: Trait ( _) => None ,
235
+ }
236
+ } )
237
+ . collect ( ) ,
238
+ _ => Vec :: new ( ) ,
229
239
}
230
- Err ( Ambiguity ( ref sources) ) => sources
231
- . iter ( )
232
- . filter_map ( |source| {
233
- match * source {
234
- // Note: this cannot come from an inherent impl,
235
- // because the first probing succeeded.
236
- CandidateSource :: Impl ( def) => self . tcx . trait_id_of_impl ( def) ,
237
- CandidateSource :: Trait ( _) => None ,
238
- }
239
- } )
240
- . collect ( ) ,
241
- _ => Vec :: new ( ) ,
240
+ } else {
241
+ Vec :: new ( )
242
242
} ;
243
243
244
244
return Err ( IllegalSizedBound { candidates, needs_mut, bound_span : span, self_expr } ) ;
@@ -255,13 +255,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
255
255
call_expr : & ' tcx hir:: Expr < ' tcx > ,
256
256
self_expr : & ' tcx hir:: Expr < ' tcx > ,
257
257
) -> Result < MethodCallee < ' tcx > , MethodError < ' tcx > > {
258
- let pick = self . lookup_probe_for_diagnostic (
259
- segment. ident ,
260
- self_ty,
261
- call_expr,
262
- ProbeScope :: TraitsInScope ,
263
- None ,
264
- ) ?;
258
+ let probe_scope =
259
+ segment. res . opt_def_id ( ) . map_or ( ProbeScope :: TraitsInScope , ProbeScope :: DefId ) ;
260
+
261
+ let pick =
262
+ self . lookup_probe_for_diagnostic ( segment. ident , self_ty, call_expr, probe_scope, None ) ?;
265
263
266
264
Ok ( self
267
265
. confirm_method_for_diagnostic ( span, self_expr, call_expr, self_ty, & pick, segment)
0 commit comments