fix suggest span for #105494

This commit is contained in:
yukang 2022-12-18 17:38:01 +08:00
parent 459b234e6a
commit 3b38adf568

View File

@ -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,