Skip to content

Commit

Permalink
Rollup merge of rust-lang#114138 - compiler-errors:bad-rcvr-span-on-m…
Browse files Browse the repository at this point in the history
…ethod-sugg, r=estebank

Adjust spans correctly for fn -> method suggestion

Fixes rust-lang#114131
  • Loading branch information
matthiaskrgr authored Jul 28, 2023
2 parents 56d15e0 + b09091c commit cc6c943
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/methods/suggest-method-on-call-with-macro-rcvr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// issue: 114131

fn main() {
let hello = len(vec![]);
//~^ ERROR cannot find function `len` in this scope
}
15 changes: 15 additions & 0 deletions tests/ui/methods/suggest-method-on-call-with-macro-rcvr.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit cc6c943

Please sign in to comment.