about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-05-27 13:01:35 +0200
committerGitHub <noreply@github.com>2025-05-27 13:01:35 +0200
commit77e35944af57b4f4f2122f251b0a392ece6e199a (patch)
tree36cde48a60c34aebcf14d9dce65211cc076dbf4c /compiler
parentd76fe154029e03aeb64af721beafdcef856d576a (diff)
parent3cd065d3d358c0124368f21a7deb0e75712c286b (diff)
downloadrust-77e35944af57b4f4f2122f251b0a392ece6e199a.tar.gz
rust-77e35944af57b4f4f2122f251b0a392ece6e199a.zip
Rollup merge of #140591 - Kivooeo:new-fix-five, r=davidtwco
Fix malformed suggestion for E0061 when method is a macro token in macro context

fixes #140512

before
```rust
3  -         <Self>::$method(8)
3  +         <Self>::<Self>::$method(8, /* u8 */)
```
now
```rust
3  |         <Self>::$method(8, /* u8 */)
   |                          ++++++++++
```
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs27
1 files changed, 11 insertions, 16 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
index 786d7639a05..59aba6fae5e 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
@@ -1556,25 +1556,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             SuggestionText::Reorder => Some("reorder these arguments".to_string()),
             SuggestionText::DidYouMean => Some("did you mean".to_string()),
         };
-        if let Some(suggestion_text) = suggestion_text {
+        if let Some(suggestion_text) = suggestion_text
+            && !full_call_span.in_external_macro(self.sess().source_map())
+        {
             let source_map = self.sess().source_map();
-            let (mut suggestion, suggestion_span) = if let Some(call_span) =
-                full_call_span.find_ancestor_inside_same_ctxt(error_span)
-            {
-                ("(".to_string(), call_span.shrink_to_hi().to(error_span.shrink_to_hi()))
+            let suggestion_span = if let Some(args_span) = error_span.trim_start(full_call_span) {
+                // Span of the braces, e.g. `(a, b, c)`.
+                args_span
             } else {
-                (
-                    format!(
-                        "{}(",
-                        source_map.span_to_snippet(full_call_span).unwrap_or_else(|_| {
-                            fn_def_id.map_or("".to_string(), |fn_def_id| {
-                                tcx.item_name(fn_def_id).to_string()
-                            })
-                        })
-                    ),
-                    error_span,
-                )
+                // The arg span of a function call that wasn't even given braces
+                // like what might happen with delegation reuse.
+                // e.g. `reuse HasSelf::method;` should suggest `reuse HasSelf::method($args);`.
+                full_call_span.shrink_to_hi()
             };
+            let mut suggestion = "(".to_owned();
             let mut needs_comma = false;
             for (expected_idx, provided_idx) in matched_inputs.iter_enumerated() {
                 if needs_comma {