@@ -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 } ;
@@ -486,13 +485,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
486
485
let ty = self . resolve_vars_if_possible ( ty. value ) ;
487
486
let guar = match * ty. kind ( ) {
488
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
+
489
501
let raw_ptr_call = bad_ty. reached_raw_pointer
490
502
&& !self . tcx . features ( ) . arbitrary_self_types ( ) ;
491
- // FIXME: Ideally we'd use the span of the self-expr here,
492
- // not of the method path.
503
+
493
504
let mut err = self . err_ctxt ( ) . emit_inference_failure_err (
494
505
self . body_id ,
495
- span ,
506
+ err_span ,
496
507
ty. into ( ) ,
497
508
TypeAnnotationNeeded :: E0282 ,
498
509
!raw_ptr_call,
0 commit comments