diff options
| author | yukang <moorekang@gmail.com> | 2022-12-18 17:38:01 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2022-12-22 16:27:16 +0800 |
| commit | 3b38adf5682c153ce58e67fa346624b7bc5286b2 (patch) | |
| tree | e88370156934f54f0eb584b91325306be10e34ad | |
| parent | 459b234e6ace06854a383aae02c656b3410ec344 (diff) | |
| download | rust-3b38adf5682c153ce58e67fa346624b7bc5286b2.tar.gz rust-3b38adf5682c153ce58e67fa346624b7bc5286b2.zip | |
fix suggest span for #105494
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 7 |
1 files changed, 6 insertions, 1 deletions
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, |
