@@ -7,9 +7,8 @@ use rustc_attr_parsing::is_doc_alias_attrs_contain_symbol;
7
7
use rustc_data_structures:: fx:: FxHashSet ;
8
8
use rustc_data_structures:: sso:: SsoHashSet ;
9
9
use rustc_errors:: Applicability ;
10
- use rustc_hir as hir;
11
- use rustc_hir:: HirId ;
12
10
use rustc_hir:: def:: DefKind ;
11
+ use rustc_hir:: { self as hir, ExprKind , HirId , Node } ;
13
12
use rustc_hir_analysis:: autoderef:: { self , Autoderef } ;
14
13
use rustc_infer:: infer:: canonical:: { Canonical , OriginalQueryValues , QueryResponse } ;
15
14
use rustc_infer:: infer:: { BoundRegionConversionTime , DefineOpaqueTypes , InferOk , TyCtxtInferExt } ;
@@ -296,7 +295,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
296
295
IsSuggestion ( true ) ,
297
296
self_ty,
298
297
scope_expr_id,
299
- None ,
300
298
ProbeScope :: AllTraits ,
301
299
|probe_cx| Ok ( probe_cx. candidate_method_names ( candidate_filter) ) ,
302
300
)
@@ -312,7 +310,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
312
310
IsSuggestion ( true ) ,
313
311
self_ty,
314
312
scope_expr_id,
315
- None ,
316
313
ProbeScope :: AllTraits ,
317
314
|probe_cx| probe_cx. pick ( ) ,
318
315
)
@@ -332,7 +329,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
332
329
self_ty : Ty < ' tcx > ,
333
330
scope_expr_id : HirId ,
334
331
scope : ProbeScope ,
335
- self_expr_span : Option < Span > ,
336
332
) -> PickResult < ' tcx > {
337
333
self . probe_op (
338
334
item_name. span ,
@@ -342,7 +338,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
342
338
is_suggestion,
343
339
self_ty,
344
340
scope_expr_id,
345
- self_expr_span,
346
341
scope,
347
342
|probe_cx| probe_cx. pick ( ) ,
348
343
)
@@ -367,7 +362,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
367
362
is_suggestion,
368
363
self_ty,
369
364
scope_expr_id,
370
- None ,
371
365
scope,
372
366
|probe_cx| {
373
367
Ok ( probe_cx
@@ -388,7 +382,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
388
382
is_suggestion : IsSuggestion ,
389
383
self_ty : Ty < ' tcx > ,
390
384
scope_expr_id : HirId ,
391
- self_expr : Option < Span > ,
392
385
scope : ProbeScope ,
393
386
op : OP ,
394
387
) -> Result < R , MethodError < ' tcx > >
@@ -492,12 +485,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
492
485
let ty = self . resolve_vars_if_possible ( ty. value ) ;
493
486
let guar = match * ty. kind ( ) {
494
487
ty:: Infer ( ty:: TyVar ( _) ) => {
488
+ // We want to get the variable name that the method
489
+ // is being called on. If it is a method call.
490
+ let err_span = match ( mode, self . tcx . hir_node ( scope_expr_id) ) {
491
+ (
492
+ Mode :: MethodCall ,
493
+ Node :: Expr ( hir:: Expr {
494
+ kind : ExprKind :: MethodCall ( _, recv, ..) ,
495
+ ..
496
+ } ) ,
497
+ ) => recv. span ,
498
+ _ => span,
499
+ } ;
500
+
495
501
let raw_ptr_call = bad_ty. reached_raw_pointer
496
502
&& !self . tcx . features ( ) . arbitrary_self_types ( ) ;
497
503
498
504
let mut err = self . err_ctxt ( ) . emit_inference_failure_err (
499
505
self . body_id ,
500
- self_expr . unwrap_or ( span ) ,
506
+ err_span ,
501
507
ty. into ( ) ,
502
508
TypeAnnotationNeeded :: E0282 ,
503
509
!raw_ptr_call,
0 commit comments