diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-07-28 19:51:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-28 19:51:15 +0200 |
| commit | 3aa8da1474daedd4c063403ecdf9a808354b4486 (patch) | |
| tree | 804561bb18cf0ba6a9ef9577650d84776ec1491f | |
| parent | 02f1e2ada7a2c225853707a9685b71deefbe7dbd (diff) | |
| parent | b09091c69bb086e7ed4ecf7f6509654f1c776dde (diff) | |
| download | rust-3aa8da1474daedd4c063403ecdf9a808354b4486.tar.gz rust-3aa8da1474daedd4c063403ecdf9a808354b4486.zip | |
Rollup merge of #114138 - compiler-errors:bad-rcvr-span-on-method-sugg, r=estebank
Adjust spans correctly for fn -> method suggestion Fixes #114131
| -rw-r--r-- | compiler/rustc_hir_typeck/src/callee.rs | 8 | ||||
| -rw-r--r-- | tests/ui/methods/suggest-method-on-call-with-macro-rcvr.rs | 6 | ||||
| -rw-r--r-- | tests/ui/methods/suggest-method-on-call-with-macro-rcvr.stderr | 15 |
3 files changed, 27 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index a4759722199..c68f2d94f35 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -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 diff --git a/tests/ui/methods/suggest-method-on-call-with-macro-rcvr.rs b/tests/ui/methods/suggest-method-on-call-with-macro-rcvr.rs new file mode 100644 index 00000000000..93b7ddf5e9e --- /dev/null +++ b/tests/ui/methods/suggest-method-on-call-with-macro-rcvr.rs @@ -0,0 +1,6 @@ +// issue: 114131 + +fn main() { + let hello = len(vec![]); + //~^ ERROR cannot find function `len` in this scope +} diff --git a/tests/ui/methods/suggest-method-on-call-with-macro-rcvr.stderr b/tests/ui/methods/suggest-method-on-call-with-macro-rcvr.stderr new file mode 100644 index 00000000000..9694f80ab6d --- /dev/null +++ b/tests/ui/methods/suggest-method-on-call-with-macro-rcvr.stderr @@ -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`. |
