From 0bfebc6105ea882d7048057718b2e34d09a5d17e Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 27 Nov 2023 00:50:51 +0100 Subject: Detect attempts to expand a macro to a match arm again Because a macro invocation can expand to a never pattern, we can't rule out a `arm!(),` arm at parse time. Instead we detect that case at expansion time, if the macro tries to output a pattern followed by `=>`. --- tests/ui/parser/macro/macro-expand-to-match-arm.rs | 1 + tests/ui/parser/macro/macro-expand-to-match-arm.stderr | 1 + 2 files changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/ui/parser/macro/macro-expand-to-match-arm.rs b/tests/ui/parser/macro/macro-expand-to-match-arm.rs index 972ca61cc84..98d2a27884f 100644 --- a/tests/ui/parser/macro/macro-expand-to-match-arm.rs +++ b/tests/ui/parser/macro/macro-expand-to-match-arm.rs @@ -3,6 +3,7 @@ macro_rules! arm { $pattern => $block //~^ ERROR macro expansion ignores token `=>` and any following //~| NOTE the usage of `arm!` is likely invalid in pattern context + //~| NOTE macros cannot expand to match arms }; } diff --git a/tests/ui/parser/macro/macro-expand-to-match-arm.stderr b/tests/ui/parser/macro/macro-expand-to-match-arm.stderr index a62109c5050..f162f7dd47b 100644 --- a/tests/ui/parser/macro/macro-expand-to-match-arm.stderr +++ b/tests/ui/parser/macro/macro-expand-to-match-arm.stderr @@ -8,6 +8,7 @@ LL | arm!(None => {}), | ---------------- caused by the macro expansion here | = note: the usage of `arm!` is likely invalid in pattern context + = note: macros cannot expand to match arms error: aborting due to 1 previous error -- cgit 1.4.1-3-g733a5