Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expr metavariable drops commas #98906

Closed
robertbastian opened this issue Jul 4, 2022 · 4 comments
Closed

expr metavariable drops commas #98906

robertbastian opened this issue Jul 4, 2022 · 4 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@robertbastian
Copy link
Contributor

robertbastian commented Jul 4, 2022

When matching an expression in a macro_rules, trailing commas in argument lists and initializers disappear.

macro_rules! compare {
    ($expr: expr) => {
        assert_eq!(stringify!($expr), "Foo { bar: 32, }");
    };
}

compare!(Foo { foo: 32, }); // fails
              // this ^ comma disappears

Playground

@robertbastian robertbastian added the C-bug Category: This is a bug. label Jul 4, 2022
@robertbastian
Copy link
Contributor Author

(this is not an issue with stringify, I'm actually encountering this when I pass the expression into the quote macro)

@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@sffc
Copy link

sffc commented Sep 11, 2023

To be clear, the use case here is to check an arbitrary TokenStream, such as one generated by a derive macro, against code in stringify!($expr). I understand that the stringified form of TokenStream is not stable, but two TokenStreams should have the same ToString.

@fmease fmease added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Jan 25, 2024
@fmease
Copy link
Member

fmease commented Jan 25, 2024

As already mentioned in this thread, the output of stringify! is not stable. Closing as wontfix / works as intended.

To be clear, the use case here is to check an arbitrary TokenStream, such as one generated by a derive macro, against code in stringify!($expr). I understand that the stringified form of TokenStream is not stable, but two TokenStreams should have the same ToString.

Please provide a concrete reproducer for this if you think it doesn't directly relate to stringify.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2024
@robertbastian
Copy link
Contributor Author

I did mention that this is not an issue with the stringify! macro, but with macro variables. Here's a reproduction using quote!: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c168c46ac64ef031f0f9b3c271aa63ab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants