Skip to content

Commit 3aa8da1

Browse files
authored
Rollup merge of #114138 - compiler-errors:bad-rcvr-span-on-method-sugg, r=estebank
Adjust spans correctly for fn -> method suggestion Fixes #114131
2 parents 02f1e2a + b09091c commit 3aa8da1

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

compiler/rustc_hir_typeck/src/callee.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
531531
return;
532532
}
533533

534-
let up_to_rcvr_span = segment.ident.span.until(callee_expr.span);
535-
let rest_span = callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
534+
let Some(callee_expr_span) = callee_expr.span.find_ancestor_inside(call_expr.span)
535+
else {
536+
return;
537+
};
538+
let up_to_rcvr_span = segment.ident.span.until(callee_expr_span);
539+
let rest_span = callee_expr_span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
536540
let rest_snippet = if let Some(first) = rest.first() {
537541
self.tcx
538542
.sess
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// issue: 114131
2+
3+
fn main() {
4+
let hello = len(vec![]);
5+
//~^ ERROR cannot find function `len` in this scope
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0425]: cannot find function `len` in this scope
2+
--> $DIR/suggest-method-on-call-with-macro-rcvr.rs:4:17
3+
|
4+
LL | let hello = len(vec![]);
5+
| ^^^ not found in this scope
6+
|
7+
help: use the `.` operator to call the method `len` on `&Vec<_>`
8+
|
9+
LL - let hello = len(vec![]);
10+
LL + let hello = vec![].len();
11+
|
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)