From 3b38adf5682c153ce58e67fa346624b7bc5286b2 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 18 Dec 2022 17:38:01 +0800 Subject: [PATCH] fix suggest span for #105494 --- compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 720fbd1ad14..9a7d753e66b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -338,8 +338,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::MethodCall(hir::PathSegment { ident: method, .. }, recv_expr, &[], _) = expr.kind && let Some(recv_ty) = self.typeck_results.borrow().expr_ty_opt(recv_expr) && self.can_coerce(recv_ty, expected) { + let span = if let Some(recv_span) = recv_expr.span.find_ancestor_inside(expr.span) { + expr.span.with_lo(recv_span.hi()) + } else { + expr.span.with_lo(method.span.lo() - rustc_span::BytePos(1)) + }; err.span_suggestion_verbose( - expr.span.with_lo(method.span.lo() - rustc_span::BytePos(1)), + span, "try removing the method call", "", Applicability::MachineApplicable,