Skip to content

Tracking Issue for macro_metavar_expr_concat #124225

Open

Description

@c410-f3r

This is a tracking issue for the experimental feature macro metavariable expressions concat and concat_str (RFC pending).
The feature gate for the issue is #![feature(macro_metavar_expr_concat)].

concat provides a modern alternative to the concat_idents! macro, while concat_str provides an alternative to the concat! macro in places where macros cannot be used.

#![feature(macro_metavar_expr_concat)]

macro_rules! many_idents {
    ($a:ident, $c:ident) => {
        const ${concat($a, B, $c, D)}: &str = ${concat_str($A, $C)};
    };
}

fn main() {
    many_idents!(A, C);
    assert_eq!(ABCD, 1);
}

About experimental features

An experimental feature is one that has not yet had an RFC. The idea is to allow implementation work to proceed to better inform an upcoming RFC. Experimental features cannot be stabilized without first having an RFC. The existence of an experimental feature does not indicate lang team consensus that the feature is desirable, only that there is a problem that is worthy of being solved and that the idea has enough merit to consider exploring. See the lang team process page for more details.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps / History

Unresolved Questions

References

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Apr 21, 2024
  2. added
    T-langRelevant to the language team
    B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).
    on Apr 21, 2024
  3. fmease commented on Apr 21, 2024

    @fmease
    Member

    This still needs a T-lang shepherd, right?

  4. c410-f3r commented on Apr 21, 2024

    @c410-f3r
    ContributorAuthor

    This still needs a T-lang shepherd, right?

    Unfortunately I am not familiar or aware of this procedure.

  5. fmease commented on Apr 21, 2024

    @fmease
    Member

    All language features have to go through the RFC process eventually. However, the implementation can be done before an RFC has been written by following T-lang's experimental feature process which requires a T-lang member to support — shepherd — the venture. Only “small” language (not compiler) “fixes” don't need to follow the RFC process, they just need a T-lang FCP.

  6. fmease commented on Apr 21, 2024

    @fmease
    Member

    T-lang, this feature is seeking a shepherd, therefore I'm nominating this for you.

    An implementation is already under way (#118958). This feature adds a new kind of macro metavariable expression (the latter (overarching) feature has been approved by the merged RFC 3086, see also its tracking issue and stabilization PR (proposed FCP, disposition: merge)). The feature represents a more potent alternative / potential successor to the unstable built-in macro concat_idents (the latter has stalled, blocked on design concerns, see its tracking issue).

    Please consult the tracking issue description for more context.

  7. joshtriplett commented on May 15, 2024

    @joshtriplett
    Member

    Happy to second this with my T-lang hat on.

    @c410-f3r Good luck, and please reach out to #t-lang on Zulip if you have any questions. Feel free to @ me there if needed.

  8. c410-f3r commented on May 15, 2024

    @c410-f3r
    ContributorAuthor

    Thank you @joshtriplett

  9. added a commit that references this issue on Jun 14, 2024
  10. UserIsntAvailable commented on Jun 15, 2024

    @UserIsntAvailable
    Contributor

    Sorry if this is the wrong place to discuss this, but should ${concat} provide its own case-conversion mechanism (just like paste! does), or should we instead provide a standalone ${case} metavar expr to handle this?

    If we where to follow paste! syntax, then it would look like:

    macro_rules! many_idents {
        ($a:ident, $c:ident) => {
            const ${concat($a:upper, B, $c:lower, D)}: i32 = 1;
        };
    }
    
    fn main() {
        many_idents!(a, C);
        assert_eq!(ABcD, 1);
    }

    Or with a future ${case} metavar expr:

    macro_rules! many_idents {
        ($a:ident, $c:ident) => {
            const ${concat(${case($a, upper)}, B, ${case($c, lower)}, D)}: i32 = 1;
        };
    }
    
    fn main() {
        many_idents!(a, C);
        assert_eq!(ABcD, 1);
    }

    Which I think is way too verbose, but maybe I'm just too used to paste! simplicity. The advantage of ${case} over ${concat} would be that, currently, ${concat} requires 2 operands to be able to be used (this could technically be changed), so ${case} would allow:

    use std::ops::Add;
    
    pub struct Wrapper<T>(T);
    
    macro_rules! impl_op {
        ($Op:ident => $Ty:ty) => {
            impl $Op<$Ty> for Wrapper<$Ty> {
                type Output = Self;
    
                // alternative syntax; `:` instead of `,`.
                fn ${case($Op:snake)}(self, rhs: $Ty) -> Self::Output {
                    Self(self.0.${case($Op:snake)}(rhs))
                }
            }
        };
    }
    
    impl_op!(Add => u8);

    With that said, maybe there is a world where both approaches are accepted, but I think there is probably less motivation to do that?

    cc @c410-f3r @joshtriplett for opinions about this.

  11. 41 remaining items

  12. added a commit that references this issue on Sep 1, 2025
  13. added a commit that references this issue on Sep 2, 2025
  14. added a commit that references this issue on Sep 2, 2025
  15. added a commit that references this issue on Sep 2, 2025
  16. vron commented on Sep 9, 2025

    @vron

    Hi, @c410-f3r ,

    I just updated to latest nightly to note that this had replaced the old macro.

    However, this does not work for my use case and I was asked to report it here.

    More info:

    https://users.rust-lang.org/t/macro-metavar-expr-concat-not-working-as-concat-idents/133737/2

  17. added 3 commits that reference this issue on Sep 12, 2025
  18. added a commit that references this issue on Sep 12, 2025
  19. added a commit that references this issue on Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-macro_metavar_expr_concat`#![feature(macro_metavar_expr_concat)]`S-tracking-unimplementedStatus: The feature has not been implemented.T-langRelevant to the language team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions