@@ -7,9 +7,8 @@ use rustc_attr_parsing::is_doc_alias_attrs_contain_symbol;
77use rustc_data_structures:: fx:: FxHashSet ;
88use rustc_data_structures:: sso:: SsoHashSet ;
99use rustc_errors:: Applicability ;
10- use rustc_hir as hir;
11- use rustc_hir:: HirId ;
1210use rustc_hir:: def:: DefKind ;
11+ use rustc_hir:: { self as hir, ExprKind , HirId , Node } ;
1312use rustc_hir_analysis:: autoderef:: { self , Autoderef } ;
1413use rustc_infer:: infer:: canonical:: { Canonical , OriginalQueryValues , QueryResponse } ;
1514use rustc_infer:: infer:: { BoundRegionConversionTime , DefineOpaqueTypes , InferOk , TyCtxtInferExt } ;
@@ -486,13 +485,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
486485 let ty = self . resolve_vars_if_possible ( ty. value ) ;
487486 let guar = match * ty. kind ( ) {
488487 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+
489501 let raw_ptr_call = bad_ty. reached_raw_pointer
490502 && !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+
493504 let mut err = self . err_ctxt ( ) . emit_inference_failure_err (
494505 self . body_id ,
495- span ,
506+ err_span ,
496507 ty. into ( ) ,
497508 TypeAnnotationNeeded :: E0282 ,
498509 !raw_ptr_call,
0 commit comments