about summary refs log tree commit diff
path: root/tests/ui/methods
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-03-06 12:22:13 -0500
committerGitHub <noreply@github.com>2025-03-06 12:22:13 -0500
commitaab7b145d0e1c0d297fe2b678e327daffb62e909 (patch)
treefd8e3a30affebcd3f950548874d943f6c692b1ad /tests/ui/methods
parentcc5d90cbad746560c2e1a6a71777c096f7a7c575 (diff)
parent09e584671b439dc8a9d57cc900cc26668a69ddea (diff)
downloadrust-aab7b145d0e1c0d297fe2b678e327daffb62e909.tar.gz
rust-aab7b145d0e1c0d297fe2b678e327daffb62e909.zip
Rollup merge of #137565 - compiler-errors:macro-ex, r=estebank
Try to point of macro expansion from resolver and method errors if it involves macro var

In the case that a macro caller passes an identifier into a macro generating a path or method expression, point out that identifier in the context of the *macro* so it's a bit more clear how the macro is involved in causing the error.

r? ``````````@estebank`````````` or reassign
Diffstat (limited to 'tests/ui/methods')
-rw-r--r--tests/ui/methods/ident-from-macro-expansion.rs18
-rw-r--r--tests/ui/methods/ident-from-macro-expansion.stderr21
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/methods/ident-from-macro-expansion.rs b/tests/ui/methods/ident-from-macro-expansion.rs
new file mode 100644
index 00000000000..38d2fee0e53
--- /dev/null
+++ b/tests/ui/methods/ident-from-macro-expansion.rs
@@ -0,0 +1,18 @@
+macro_rules! dot {
+    ($id:ident) => {
+        ().$id();
+    }
+}
+
+macro_rules! dispatch {
+    ($id:ident) => {
+        <()>::$id();
+    }
+}
+
+fn main() {
+    dot!(hello);
+    //~^ ERROR no method named `hello` found for unit type `()` in the current scope
+    dispatch!(hello);
+    //~^ ERROR no function or associated item named `hello` found for unit type `()` in the current scope
+}
diff --git a/tests/ui/methods/ident-from-macro-expansion.stderr b/tests/ui/methods/ident-from-macro-expansion.stderr
new file mode 100644
index 00000000000..b596ce29f6f
--- /dev/null
+++ b/tests/ui/methods/ident-from-macro-expansion.stderr
@@ -0,0 +1,21 @@
+error[E0599]: no method named `hello` found for unit type `()` in the current scope
+  --> $DIR/ident-from-macro-expansion.rs:14:10
+   |
+LL |         ().$id();
+   |            --- due to this macro variable
+...
+LL |     dot!(hello);
+   |          ^^^^^ method not found in `()`
+
+error[E0599]: no function or associated item named `hello` found for unit type `()` in the current scope
+  --> $DIR/ident-from-macro-expansion.rs:16:15
+   |
+LL |         <()>::$id();
+   |               --- due to this macro variable
+...
+LL |     dispatch!(hello);
+   |               ^^^^^ function or associated item not found in `()`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0599`.