Adjust spans correctly for fn -> method suggestion

This commit is contained in:
Michael Goulet 2023-07-27 16:50:28 +00:00
parent b73e9a48ae
commit b09091c69b
3 changed files with 27 additions and 2 deletions

View file

@ -531,8 +531,12 @@ fn suggest_call_as_method(
return;
}
let up_to_rcvr_span = segment.ident.span.until(callee_expr.span);
let rest_span = callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
let Some(callee_expr_span) = callee_expr.span.find_ancestor_inside(call_expr.span)
else {
return;
};
let up_to_rcvr_span = segment.ident.span.until(callee_expr_span);
let rest_span = callee_expr_span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
let rest_snippet = if let Some(first) = rest.first() {
self.tcx
.sess

View file

@ -0,0 +1,6 @@
// issue: 114131
fn main() {
let hello = len(vec![]);
//~^ ERROR cannot find function `len` in this scope
}

View file

@ -0,0 +1,15 @@
error[E0425]: cannot find function `len` in this scope
--> $DIR/suggest-method-on-call-with-macro-rcvr.rs:4:17
|
LL | let hello = len(vec![]);
| ^^^ not found in this scope
|
help: use the `.` operator to call the method `len` on `&Vec<_>`
|
LL - let hello = len(vec![]);
LL + let hello = vec![].len();
|
error: aborting due to previous error
For more information about this error, try `rustc --explain E0425`.