-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[macro_metavar_expr_concat
] Add support for literals
#127542
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
error: `${concat(..)}` is not generating a valid identifier | ||
--> $DIR/syntax-errors.rs:103:16 | ||
| | ||
LL | const ${concat(_foo, $literal)}: () = (); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | bad_literal_parameter!("\x41"); | ||
| ------------------------------ in this macro invocation | ||
| | ||
= note: this error originates in the macro `bad_literal_parameter` (in Nightly builds, run with -Z macro-backtrace for more info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these error messages would be improved if they print the created identifier as a note. E.g. "_foo🤷
is not a valid identifier" can help narrow down what exactly is wrong when the exact combination isn't as obvious.
Doesn't have to be a part of this PR though.
FYI you might need to wait a bit for a review, I think petrochenkov is currently out on vacation. (Somebody else might be able to pick it up but petrochenkov seems to be the expert in macro expansion). |
Addressing #127542 (comment) would also be good. |
Looks like a good candidate for a following PR. @rustbot review |
@bors r+ |
Спасибо! |
[`macro_metavar_expr_concat`] Add support for literals Adds support for literals in macro parameters. ```rust macro_rules! with_literal { ($literal:literal) => { const ${concat(FOO, $literal)}: i32 = 1; } } fn main() { with_literal!("_BAR"); assert_eq!(FOO_BAR, 1); } ``` cc rust-lang#124225 r? `@petrochenkov`
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#127542 ([`macro_metavar_expr_concat`] Add support for literals) - rust-lang#127652 (Unignore cg_gcc fmt) - rust-lang#127664 (Fix precise capturing suggestion for hidden regions when we have APITs) - rust-lang#127806 (Some parser improvements) - rust-lang#127828 (Commonize `uname -m` results for `aarch64` in docker runner) - rust-lang#127845 (unix: break `stack_overflow::install_main_guard` into smaller fn) - rust-lang#127854 (Add internal lint for detecting non-glob imports of `rustc_type_ir::inherent`) - rust-lang#127861 (Document the column numbers for the dbg! macro) - rust-lang#127875 (style-guide: Clarify version-sorting) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 9 pull requests Successful merges: - rust-lang#127542 ([`macro_metavar_expr_concat`] Add support for literals) - rust-lang#127652 (Unignore cg_gcc fmt) - rust-lang#127664 (Fix precise capturing suggestion for hidden regions when we have APITs) - rust-lang#127806 (Some parser improvements) - rust-lang#127828 (Commonize `uname -m` results for `aarch64` in docker runner) - rust-lang#127845 (unix: break `stack_overflow::install_main_guard` into smaller fn) - rust-lang#127859 (ptr::metadata: avoid references to extern types) - rust-lang#127861 (Document the column numbers for the dbg! macro) - rust-lang#127875 (style-guide: Clarify version-sorting) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#127542 - c410-f3r:concat-again, r=petrochenkov [`macro_metavar_expr_concat`] Add support for literals Adds support for literals in macro parameters. ```rust macro_rules! with_literal { ($literal:literal) => { const ${concat(FOO, $literal)}: i32 = 1; } } fn main() { with_literal!("_BAR"); assert_eq!(FOO_BAR, 1); } ``` cc rust-lang#124225 r? ``@petrochenkov``
Adds support for literals in macro parameters.
cc #124225
r? @petrochenkov