about summary refs log tree commit diff
path: root/tests/ui/macros/metavar-expressions/usage-errors.rs
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-07-01 04:25:36 +0200
committerGitHub <noreply@github.com>2025-07-01 04:25:36 +0200
commitcfe1942a3f1a98ea733b544559bd4845e41d5797 (patch)
treed5503c6f0ad2ff03ab758d510e5f2f4981e0ab18 /tests/ui/macros/metavar-expressions/usage-errors.rs
parente2ea213874477e0874af598eecdb730ef2a52b32 (diff)
parenta1a066999b9fbfc10e93931d9a552bf87dc32e4d (diff)
downloadrust-cfe1942a3f1a98ea733b544559bd4845e41d5797.tar.gz
rust-cfe1942a3f1a98ea733b544559bd4845e41d5797.zip
Rollup merge of #143245 - tgross35:metavariable-expr-organization, r=petrochenkov
mbe: Add tests and restructure metavariable expressions

Add tests that show better diagnostics, and factor `concat` handling to a separate function. Each commit message has further details.

This performs the nonfunctional perparation for further changes such as https://github.com/rust-lang/rust/pull/142950 and https://github.com/rust-lang/rust/pull/142975 .
Diffstat (limited to 'tests/ui/macros/metavar-expressions/usage-errors.rs')
-rw-r--r--tests/ui/macros/metavar-expressions/usage-errors.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/ui/macros/metavar-expressions/usage-errors.rs b/tests/ui/macros/metavar-expressions/usage-errors.rs
new file mode 100644
index 00000000000..feff02e2ce4
--- /dev/null
+++ b/tests/ui/macros/metavar-expressions/usage-errors.rs
@@ -0,0 +1,55 @@
+// Errors for the `count` and `length` metavariable expressions
+
+#![feature(macro_metavar_expr)]
+
+// `curly` = Right hand side curly brackets
+// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function"
+// `round` = Left hand side round brackets
+
+macro_rules! curly__no_rhs_dollar__round {
+    ( $( $i:ident ),* ) => { ${ count($i) } };
+}
+const _: u32 = curly__no_rhs_dollar__round!(a, b, c);
+
+macro_rules! curly__no_rhs_dollar__no_round {
+    ( $i:ident ) => { ${ count($i) } };
+    //~^ ERROR `count` can not be placed inside the innermost repetition
+}
+curly__no_rhs_dollar__no_round!(a);
+
+macro_rules! curly__rhs_dollar__no_round {
+    ( $i:ident ) => { ${ count($i) } };
+    //~^ ERROR `count` can not be placed inside the innermost repetition
+}
+curly__rhs_dollar__no_round !(a);
+
+#[rustfmt::skip] // autoformatters can break a few of the error traces
+macro_rules! no_curly__no_rhs_dollar__round {
+    ( $( $i:ident ),* ) => { count(i) };
+    //~^ ERROR missing `fn` or `struct` for function or struct definition
+}
+no_curly__no_rhs_dollar__round !(a, b, c);
+
+#[rustfmt::skip] // autoformatters can break a few of the error traces
+macro_rules! no_curly__no_rhs_dollar__no_round {
+    ( $i:ident ) => { count(i) };
+    //~^ ERROR missing `fn` or `struct` for function or struct definition
+}
+no_curly__no_rhs_dollar__no_round !(a);
+
+#[rustfmt::skip] // autoformatters can break a few of the error traces
+macro_rules! no_curly__rhs_dollar__round {
+    ( $( $i:ident ),* ) => { count($i) };
+    //~^ ERROR variable `i` is still repeating at this depth
+}
+no_curly__rhs_dollar__round! (a);
+
+#[rustfmt::skip] // autoformatters can break a few of the error traces
+macro_rules! no_curly__rhs_dollar__no_round {
+    ( $i:ident ) => { count($i) };
+    //~^ ERROR cannot find function `count` in this scope
+}
+const _: u32 = no_curly__rhs_dollar__no_round! (a);
+//~^ ERROR cannot find value `a` in this scope
+
+fn main() {}