Skip to content

Conversation

jullanggit
Copy link

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 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!

@rustbot
Copy link
Collaborator

rustbot commented Aug 31, 2025

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 31, 2025
@jullanggit
Copy link
Author

@rustbot label F-macro_metavar_expr_concat

@rustbot rustbot added the F-macro_metavar_expr_concat `#![feature(macro_metavar_expr_concat)]` label Aug 31, 2025
@rust-log-analyzer

This comment has been minimized.

@fmease
Copy link
Member

fmease commented Aug 31, 2025

Please add a regression test, squash your commits and make the error message start with a lower case letter (https://rustc-dev-guide.rust-lang.org/diagnostics.html?highlight=diagnostic#diagnostic-output-style-guide)

@rust-log-analyzer

This comment has been minimized.

@jullanggit
Copy link
Author

@fmease like this?

Replace unimplemented()! with a more helpful compiler error.
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-19-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test [crashes] tests/crashes/140123-4.rs ... ok
test [crashes] tests/crashes/140123.rs ... ok
test [crashes] tests/crashes/138361.rs ... ok
test [crashes] tests/crashes/140275.rs ... ok
2025-08-31T22:27:17.312425Z ERROR compiletest::runtest: fatal error, panic: "crashtest no longer crashes/triggers ICE, hooray! Please give it a meaningful name, add a doc-comment to the start of the test explaining why it exists and move it to tests/ui or wherever you see fit. Adding 'Fixes #<issueNr>' to your PR description ensures that the corresponding ticket is auto-closed upon merge. If you want to see verbose output, set `COMPILETEST_VERBOSE_CRASHES=1`."
test [crashes] tests/crashes/140381.rs ... ok
test [crashes] tests/crashes/140479.rs ... FAILED
test [crashes] tests/crashes/140303.rs ... ok
test [crashes] tests/crashes/140609.rs ... ok
test [crashes] tests/crashes/140729.rs ... ok
---

---- [crashes] tests/crashes/140479.rs stdout ----
------rustc stdout------------------------------

------rustc stderr------------------------------
error: unexpected token: [
##[error] --> /checkout/tests/crashes/140479.rs:2:27
  |
2 | macro_rules! a { ( $( { $ [ $b:c ] } )) => ( $(${ concat(d, $b)} ))}
  |                           ^^^^^^^^

note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions
 --> /checkout/tests/crashes/140479.rs:2:27
  |
2 | macro_rules! a { ( $( { $ [ $b:c ] } )) => ( $(${ concat(d, $b)} ))}
  |                           ^^^^^^^^

error: invalid fragment specifier `c`
##[error] --> /checkout/tests/crashes/140479.rs:2:29
  |
2 | macro_rules! a { ( $( { $ [ $b:c ] } )) => ( $(${ concat(d, $b)} ))}
  |                             ^^^^
  |
  = help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`, along with `expr_2021` and `pat_param` for edition compatibility

error: expected one of: `*`, `+`, or `?`
##[error] --> /checkout/tests/crashes/140479.rs:2:27
  |
2 | macro_rules! a { ( $( { $ [ $b:c ] } )) => ( $(${ concat(d, $b)} ))}
  |                           ^^^^^^^^

error: expected one of: `*`, `+`, or `?`
##[error] --> /checkout/tests/crashes/140479.rs:2:21
  |
2 | macro_rules! a { ( $( { $ [ $b:c ] } )) => ( $(${ concat(d, $b)} ))}
  |                     ^^^^^^^^^^^^^^^^^^

error[E0658]: the `concat` meta-variable expression is unstable
##[error] --> /checkout/tests/crashes/140479.rs:2:49
  |
2 | macro_rules! a { ( $( { $ [ $b:c ] } )) => ( $(${ concat(d, $b)} ))}
  |                                                 ^^^^^^^^^^^^^^^^
  |
  = note: see issue #124225 <https://github.com/rust-lang/rust/issues/124225> for more information
  = help: add `#![feature(macro_metavar_expr_concat)]` to the crate attributes to enable
  = note: this compiler was built on 2025-08-31; consider upgrading it if it is out of date

error: expected one of: `*`, `+`, or `?`
##[error] --> /checkout/tests/crashes/140479.rs:2:47
  |
2 | macro_rules! a { ( $( { $ [ $b:c ] } )) => ( $(${ concat(d, $b)} ))}
  |                                               ^^^^^^^^^^^^^^^^^^^^

error: nested repetitions with `${concat(...)}` metavariable expressions are not yet supported
##[error] --> /checkout/tests/crashes/140479.rs:2:62
  |
2 | macro_rules! a { ( $( { $ [ $b:c ] } )) => ( $(${ concat(d, $b)} ))}
  |                                                              ^

error[E0601]: `main` function not found in crate `140479`
##[error] --> /checkout/tests/crashes/140479.rs:5:2
  |
---
For more information about an error, try `rustc --explain E0601`.

------------------------------------------

error: crashtest no longer crashes/triggers ICE, hooray! Please give it a meaningful name, add a doc-comment to the start of the test explaining why it exists and move it to tests/ui or wherever you see fit. Adding 'Fixes #<issueNr>' to your PR description ensures that the corresponding ticket is auto-closed upon merge. If you want to see verbose output, set `COMPILETEST_VERBOSE_CRASHES=1`.

thread '[crashes] tests/crashes/140479.rs' panicked at src/tools/compiletest/src/runtest/crashes.rs:17:18:
fatal error
stack backtrace:
   0: __rustc::rust_begin_unwind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-macro_metavar_expr_concat `#![feature(macro_metavar_expr_concat)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants