Skip to content

Commit 3b38adf

Browse files
committed
fix suggest span for #105494
1 parent 459b234 commit 3b38adf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
338338
if let hir::ExprKind::MethodCall(hir::PathSegment { ident: method, .. }, recv_expr, &[], _) = expr.kind &&
339339
let Some(recv_ty) = self.typeck_results.borrow().expr_ty_opt(recv_expr) &&
340340
self.can_coerce(recv_ty, expected) {
341+
let span = if let Some(recv_span) = recv_expr.span.find_ancestor_inside(expr.span) {
342+
expr.span.with_lo(recv_span.hi())
343+
} else {
344+
expr.span.with_lo(method.span.lo() - rustc_span::BytePos(1))
345+
};
341346
err.span_suggestion_verbose(
342-
expr.span.with_lo(method.span.lo() - rustc_span::BytePos(1)),
347+
span,
343348
"try removing the method call",
344349
"",
345350
Applicability::MachineApplicable,

0 commit comments

Comments
 (0)