You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't define a function name using concat_idents!() #12249
Reacted by chpio, Willow Chargin, Hao Shi, Evgeniy Dushistov, Serhii Potapov, no longer on github, Werner Echezuría, Dentosal, Danilo Guanabara, Malet and 10 more
Just ran into this problem wanting to generate two tests for encoder I'm implementing. One checking if encoding is correct and the other if encode . decode = id. Now i basicaly have to pass two test names that only differ in prefixes.
Another use case: a macro used to define both foo() and foo_mut(), which have similar code that calls bar() / baz() or bar_mut() / baz_mut() respectively.
I just ran into this. a few of uses I had in mind- convenience for making a single-function trait, rolling accessors for emulating anon structs; convenience for rolling double-dispatch traits to emulate overloading.
( I'd also be interested in a syntax rules to convert indents to/from camel/snake case for these .. working with the naming conventions)
A more wholesome design is needed, I don't want to keep extending the macro system ad-hoc. The monthish I spent around and with @jbclements inspired me to want to take ownership of macros.
Leveraging some of the recent code from @jbclements in the macro_rules implementation this can technically be done in a user-defined syntax extension. The method is... well, it's utterly horrifying, but it works for now.
In case anyone wants a slightly simpler solution to this problem while waiting for better macros, I made a syntax plugin that's sure to break once after each nightly release: interpolate_idents. I would be very cautious to use this for anything.
This is an issue that I find frustrating when working on winapi, making macros needlessly more complicated with extra parameters just because concat_idents! is completely useless. This is by far the most common deficiency of macros I see people run into, and I think it would be worth the additional complexity to support this sort of thing.
We've already had a working PR that was closed due to needing an RFC and then an RFC that was closed due to trying to avoid jamming up the macro system with 1.0 approaching.
Now that Rust has had several stable versions and the magical new macro system that people are heralding is nowhere in sight still, maybe we can consider opening an RFC for allowing macros in ident positions and actually having a discussion instead of just shutting it down immediately.
macro reform is in the works right now, expect an internals post soon addressing things to fix (although a plan will take a bit longer). Concatenating identifiers is definitely on the agenda. It is a hard problem though - hygiene considerations means there is no easy solution.
Activity
lifthrasiir commentedon Feb 14, 2014
A duplicate of #4365. Should we make this an RFC?
kmcallister commentedon Feb 14, 2014
I think it's a pretty essential feature. Even C macros can do this with
##.To give a more realistic use case, Servo has functions like
and I generate these from macro invocations
but would much rather have
arjantop commentedon Mar 13, 2014
Just ran into this problem wanting to generate two tests for encoder I'm implementing. One checking if encoding is correct and the other if
encode . decode = id. Now i basicaly have to pass two test names that only differ in prefixes.lpy commentedon Apr 11, 2014
cc @lpy
huonw commentedon Apr 11, 2014
cc #13294
nrc commentedon Apr 27, 2014
+1 for implementing this, seems like the kind of thing macros would be useful for
kmcallister commentedon Apr 28, 2014
Another use case: a macro used to define both
foo()andfoo_mut(), which have similar code that callsbar()/baz()orbar_mut()/baz_mut()respectively.dobkeratops commentedon May 14, 2014
I just ran into this. a few of uses I had in mind- convenience for making a single-function trait, rolling accessors for emulating anon structs; convenience for rolling double-dispatch traits to emulate overloading.
( I'd also be interested in a syntax rules to convert indents to/from camel/snake case for these .. working with the naming conventions)
emberian commentedon Jul 19, 2014
This is really just due to how hacky and awful macro expansion is. Macro invocation is only allowed in certain predesignated places in the ast.
kmcallister commentedon Jul 19, 2014
Note that this can't be implemented if we enforce hygiene for all macros (including syntax extensions).
emberian commentedon Jul 19, 2014
A more wholesome design is needed, I don't want to keep extending the macro system ad-hoc. The monthish I spent around and with @jbclements inspired me to want to take ownership of macros.
trws commentedon Jul 23, 2014
Leveraging some of the recent code from @jbclements in the macro_rules implementation this can technically be done in a user-defined syntax extension. The method is... well, it's utterly horrifying, but it works for now.
Where expand_string_to_expr! is a registered macro leveraging the ParserAnyMacro type from macro_rules.rs as below.
SkylerLipthay commentedon Mar 22, 2015
In case anyone wants a slightly simpler solution to this problem while waiting for better macros, I made a syntax plugin that's sure to break once after each nightly release: interpolate_idents. I would be very cautious to use this for anything.
retep998 commentedon Nov 7, 2015
This is an issue that I find frustrating when working on
winapi, making macros needlessly more complicated with extra parameters just becauseconcat_idents!is completely useless. This is by far the most common deficiency of macros I see people run into, and I think it would be worth the additional complexity to support this sort of thing.We've already had a working PR that was closed due to needing an RFC and then an RFC that was closed due to trying to avoid jamming up the macro system with 1.0 approaching.
Now that Rust has had several stable versions and the magical new macro system that people are heralding is nowhere in sight still, maybe we can consider opening an RFC for allowing macros in ident positions and actually having a discussion instead of just shutting it down immediately.
nrc commentedon Nov 8, 2015
macro reform is in the works right now, expect an internals post soon addressing things to fix (although a plan will take a bit longer). Concatenating identifiers is definitely on the agenda. It is a hard problem though - hygiene considerations means there is no easy solution.
wchargin commentedon Nov 9, 2015
Awesome, thanks for working on this. Definitely a 👍 from me. Looking forward to it.
steveklabnik commentedon May 24, 2016
Closing in favor of #29599
Remove macro