[macro_metavar_expr_concat] Add support for literals#127542
Merged
bors merged 1 commit intorust-lang:masterfrom Jul 18, 2024
Merged
[macro_metavar_expr_concat] Add support for literals#127542bors merged 1 commit intorust-lang:masterfrom
macro_metavar_expr_concat] Add support for literals#127542bors merged 1 commit intorust-lang:masterfrom
Conversation
tgross35
reviewed
Jul 10, 2024
Comment on lines
+145
to
+154
| 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) |
Contributor
There was a problem hiding this comment.
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.
Contributor
|
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). |
Contributor
|
Addressing #127542 (comment) would also be good. |
Contributor
Author
Looks like a good candidate for a following PR. @rustbot review |
Contributor
|
@bors r+ |
Collaborator
Contributor
Author
|
Спасибо! |
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Jul 17, 2024
[`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`
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jul 18, 2024
…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
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jul 18, 2024
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
9 tasks
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jul 18, 2024
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``
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds support for literals in macro parameters.
cc #124225
r? @petrochenkov