Skip to content

macro_metavar_expr_concat: support concatenating into string literals - #160570

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:concat_str
Sep 23, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
mejrs:concat_str

Conversation

@mejrs

@mejrs mejrs commented Aug 5, 2026

Copy link
Copy Markdown
Member

View all comments

Usually if you want to concatenate string literals in macros you expand into some combination of concat! and stringify! invocations. However this does not work in nested MetaItems, since those are never expanded (unlike #[path = EXPR] attributes like #[doc = include_str!("README.md")].

This PR adds support for that using ${concat_str(...)}, similar to ${concat(...)}. It is unstable under the same macro_metavar_expr_concat feature. See the tests in this PR for examples.

My motivation for adding this is that I've seen (and had myself) some cases where this would have been really useful. Thus I'd like to add this experimentally.

@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 5, 2026
@rustbot

rustbot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

r? @wesleywiser

rustbot has assigned @wesleywiser.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 19 candidates

@mejrs mejrs added the F-macro_metavar_expr_concat `#![feature(macro_metavar_expr_concat)]` label Aug 5, 2026
@rustbot

This comment has been minimized.

@mejrs

mejrs commented Aug 17, 2026

Copy link
Copy Markdown
Member Author

r? compiler

@rustbot rustbot assigned petrochenkov and unassigned wesleywiser Aug 17, 2026
Comment thread tests/ui/macros/metavar-expressions/concat-str-horror.rs Outdated
Comment thread compiler/rustc_expand/src/mbe/transcribe.rs Outdated
Comment thread compiler/rustc_expand/src/mbe/transcribe.rs
@petrochenkov

Copy link
Copy Markdown
Contributor

since those are not eagerly expanded (unlike #[path = EXPR] attributes like #[doc = include_str!("README.md")].

Technically, include_str in the example is not eagerly expanded either.

@petrochenkov

Copy link
Copy Markdown
Contributor

Besides the is_ident check, the logic here exactly follows the behavior of existing ${concat} metavar, which is pretty conservative, so I don't have any concerns about adding this.
This is unstable, but probably still needs some lang team sign off.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 18, 2026
@rustbot

rustbot commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot

This comment has been minimized.

@mejrs mejrs added I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination labels Aug 20, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 20, 2026
@petrochenkov petrochenkov added S-waiting-on-t-lang Status: Awaiting decision from T-lang and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 21, 2026
@traviscross traviscross added the P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang label Aug 26, 2026
@rustbot

This comment has been minimized.

@joshtriplett

Copy link
Copy Markdown
Member

We talked about this in today's T-lang meeting. We're generally fine with adding something like this.

I'm happy to champion this, alongside the existing macro metavar work. It sounds like you're planning to track it via the same tracking issue?

@mejrs

mejrs commented Sep 13, 2026

Copy link
Copy Markdown
Member Author

Hm, this PR still has all the lang labels. r=me once there's a formal lang approval.

@joshtriplett is the lang team being OK with it and you championing it enough here? if so can you remove some lang labels? I'll edit the existing tracking issue after this is approved.

@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. and removed I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang S-waiting-on-t-lang Status: Awaiting decision from T-lang labels Sep 16, 2026
@mejrs

mejrs commented Sep 22, 2026

Copy link
Copy Markdown
Member Author

per lang labels being gone,

@bors r=petrochenkov

@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8e54ab5 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 22, 2026
macro_metavar_expr_concat: support concatenating into string literals

Usually if you want to concatenate string literals in macros you expand into some combination of concat! and stringify! invocations. However this does not work in nested MetaItems, since those are never expanded (unlike `#[path = EXPR]` attributes like `#[doc = include_str!("README.md")]`.

This PR adds support for that using `${concat_str(...)}`, similar to `${concat(...)}`. It is unstable under the same `macro_metavar_expr_concat` feature. See the tests in this PR for examples.

My motivation for adding this is that I've seen (and had myself) some cases where this would have been really useful. Thus I'd like to add this experimentally.
@JonathanBrouwer

Copy link
Copy Markdown
Member

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

Link to failure: #163164 (comment)

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 22, 2026
@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#163164), which was unapproved.

View changes since this unapproval

@rustbot

rustbot commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@mejrs

mejrs commented Sep 22, 2026

Copy link
Copy Markdown
Member Author

@bors r=petrochenkov

@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 6c0f3aa has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 22, 2026
macro_metavar_expr_concat: support concatenating into string literals

Usually if you want to concatenate string literals in macros you expand into some combination of concat! and stringify! invocations. However this does not work in nested MetaItems, since those are never expanded (unlike `#[path = EXPR]` attributes like `#[doc = include_str!("README.md")]`.

This PR adds support for that using `${concat_str(...)}`, similar to `${concat(...)}`. It is unstable under the same `macro_metavar_expr_concat` feature. See the tests in this PR for examples.

My motivation for adding this is that I've seen (and had myself) some cases where this would have been really useful. Thus I'd like to add this experimentally.
rust-bors Bot pushed a commit that referenced this pull request Sep 22, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #156949 (Detect missing else in let statement)
 - #160436 (stabilize `Box::take`)
 - #160570 (macro_metavar_expr_concat: support concatenating into string literals)
 - #162837 (Dedicated Display type for CStr::display)
 - #163099 (Use wrapping arithmetic in `from_str_radix`)
 - #163166 (Tiny cleanups to deferred liveness)
 - #161667 (Add `f16` inline ASM support for `nvptx64-nvidia-cuda`)
 - #163063 (Restore `Send` and `Sync` for `BorrowedCursor`)
 - #163097 (OpenBSD/sparc64 has switched from GCC to Clang)
 - #163126 (Skip redundant storage-conflict updates during coroutine layout)
 - #163135 (librustdoc: remove stale dep on base64)
 - #163146 (tests: Update `f16b` codegen test for LoongArch and RISC-V)
 - #163159 (treat inductive cycles as ambig)
@rust-bors
rust-bors Bot merged commit 9c60af0 into rust-lang:main Sep 23, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 23, 2026
Rollup merge of #160570 - mejrs:concat_str, r=petrochenkov

macro_metavar_expr_concat: support concatenating into string literals

Usually if you want to concatenate string literals in macros you expand into some combination of concat! and stringify! invocations. However this does not work in nested MetaItems, since those are never expanded (unlike `#[path = EXPR]` attributes like `#[doc = include_str!("README.md")]`.

This PR adds support for that using `${concat_str(...)}`, similar to `${concat(...)}`. It is unstable under the same `macro_metavar_expr_concat` feature. See the tests in this PR for examples.

My motivation for adding this is that I've seen (and had myself) some cases where this would have been really useful. Thus I'd like to add this experimentally.
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)]` I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants