diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-09-02 17:08:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-02 17:08:54 +0200 |
| commit | 7b2bfa361e74c0c0b34bfe3c52e696d8bc6d4330 (patch) | |
| tree | 2df1fbc1d75d6bc950b15ff569908801303b5d9f | |
| parent | 5d855c6b9e72d1dd55bfcb0d86e80116bc3c0272 (diff) | |
| parent | f6e7c81061c24a2210149ff94670d8672bd0224a (diff) | |
| download | rust-7b2bfa361e74c0c0b34bfe3c52e696d8bc6d4330.tar.gz rust-7b2bfa361e74c0c0b34bfe3c52e696d8bc6d4330.zip | |
Rollup merge of #146064 - jullanggit:patch-1, r=fmease
Add compiler error when trying to use concat metavar expr in repetitions ## Disclaimer This is my first PR to rust, so if I missed/could improve something about this PR, please excuse and tell me! ## The improvement The [metavar_expr_concat feature](https://github.com/rust-lang/rust/issues/124225) currently does not seem to support nested repetitions, and throws an ICE without much explanation if the relevant code path is hit. This PR adds a draft compiler error that attempts to explain the issue. I am not 100% sure what all the ways of triggering this error are, so the message is currently pretty generic, please do correct me if there's something wrong with it or it could be improved. Thank you for you time! Fixes rust-lang/rust#140479.
| -rw-r--r-- | compiler/rustc_expand/src/mbe/transcribe.rs | 7 | ||||
| -rw-r--r-- | tests/crashes/140479.rs | 5 | ||||
| -rw-r--r-- | tests/ui/macros/macro-metavar-expr-concat/in-repetition.rs | 21 | ||||
| -rw-r--r-- | tests/ui/macros/macro-metavar-expr-concat/in-repetition.stderr | 8 |
4 files changed, 35 insertions, 6 deletions
diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 174844d6ad6..e4e4866b64c 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -556,7 +556,12 @@ fn metavar_expr_concat<'tx>( }; match &named_matches[*curr_idx] { // FIXME(c410-f3r) Nested repetitions are unimplemented - MatchedSeq(_) => unimplemented!(), + MatchedSeq(_) => { + return Err(dcx.struct_span_err( + ident.span, + "nested repetitions with `${concat(...)}` metavariable expressions are not yet supported", + )); + } MatchedSingle(pnr) => extract_symbol_from_pnr(dcx, pnr, ident.span)?, } } diff --git a/tests/crashes/140479.rs b/tests/crashes/140479.rs deleted file mode 100644 index ed3ca887546..00000000000 --- a/tests/crashes/140479.rs +++ /dev/null @@ -1,5 +0,0 @@ -//@ known-bug: #140479 -macro_rules! a { ( $( { $ [ $b:c ] } )) => ( $(${ concat(d, $b)} ))} -fn e() { - a!({}) -} diff --git a/tests/ui/macros/macro-metavar-expr-concat/in-repetition.rs b/tests/ui/macros/macro-metavar-expr-concat/in-repetition.rs new file mode 100644 index 00000000000..d2bd31b06d6 --- /dev/null +++ b/tests/ui/macros/macro-metavar-expr-concat/in-repetition.rs @@ -0,0 +1,21 @@ +// issue: <https://github.com/rust-lang/rust/issues/140479> +// Ensure a proper compiler error, instead of an ICE occurs. +// FIXME(macro_metavar_expr_concat): this error message could be improved +#![feature(macro_metavar_expr_concat)] + +macro_rules! InRepetition { + ( + $( + $($arg:ident),+ + )+ + ) => { + $( + $( + ${concat(_, $arg)} //~ ERROR nested repetitions with `${concat(...)}` metavariable expressions are not yet supported + )* + )* + }; +} +InRepetition!(other); + +fn main() {} diff --git a/tests/ui/macros/macro-metavar-expr-concat/in-repetition.stderr b/tests/ui/macros/macro-metavar-expr-concat/in-repetition.stderr new file mode 100644 index 00000000000..ec39ca799e1 --- /dev/null +++ b/tests/ui/macros/macro-metavar-expr-concat/in-repetition.stderr @@ -0,0 +1,8 @@ +error: nested repetitions with `${concat(...)}` metavariable expressions are not yet supported + --> $DIR/in-repetition.rs:14:30 + | +LL | ${concat(_, $arg)} + | ^^^ + +error: aborting due to 1 previous error + |
