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

[WIP] Allow macros in identifier position #14266

Closed
wants to merge 10 commits into from

Conversation

bgamari
Copy link
Contributor

@bgamari bgamari commented May 17, 2014

This allows macros to be used in identifier position of items, making concat_idents! far more useful. This is very much a work in progress.

@eddyb
Copy link
Member

eddyb commented May 17, 2014

cc me @sfackler

@huonw
Copy link
Member

huonw commented May 17, 2014

This probably needs an RFC.

@bgamari
Copy link
Contributor Author

bgamari commented May 17, 2014

@huonw I can try putting together an RFC if necessary. Is it the grammar changes that are concerning?

@huonw
Copy link
Member

huonw commented May 17, 2014

And the interactions with hygiene.

@alexcrichton
Copy link
Member

Closing, this change is definitely one that warrants an RFC. This looks pretty awesome, however, and I would love to see this implemented!

Some thoughts that may affect the writeup of the RFC:

  • How does this interact with hygiene? What scope are the identifiers created bound to, can they reference local variables for example?
  • How does this interact with our grammar? Are there ambiguities allowing macros as idents? If we one day allow for invoke macros via paths, this may require infinite lookahead to determine if an ident is a macro invocation (when used as an expression). This may not be super-relevant, however (just something to think about).

There may be other concerns, but I'm sure an RFC would flesh them out!

@vadimcn
Copy link
Contributor

vadimcn commented Feb 1, 2015

@bgamari, @alexcrichton: So why was this PR abandoned? Were there any technical problems with it, or just the absence of an RFC?

@alexcrichton
Copy link
Member

Ah sorry, my memory is a little hazy on this, but I believe it would definitely need to start out with an RFC today.

@eddyb
Copy link
Member

eddyb commented Feb 1, 2015

There was an RFC and it was rejected. Though it doesn't point to this PR specifically (which is technically superior in that it doesn't increase the size of Ident or make it non-Copy).

It seems a bit odd to me that it was, because we have since added pattern macros and trait/impl interior macros (i.e. macros that can expand to methods or associated items).

Making ident macros unstable to use should avoid any de facto problematic design stabilization.
I proposed foo.(concat_idents!(bar, baz)) for method calls, which is far from optimal, but we have UFCS now, so maybe we don't need this to work with method call syntax.

@SiegeLord
Copy link
Contributor

I don't quite understand how UFCS resolves the desired syntax sugar from my comment in that RFC (if it's meant to). I specifically want a sugaring that looks like this: foo.bar!(a = 5) and desugars into foo.baz(5) (or the UFCS equivalent). Deviations into bar!(foo, a = 5) are unacceptable, and foo.(bar!(a = 5)) are unfortunate.

@eddyb
Copy link
Member

eddyb commented Feb 1, 2015

@SiegeLord I don't see how that's relevant, you seem to want something which doesn't expand to a single identifier. I am talking about identifier macros in method name position, which caused some issues during the implementation of this, though I don't see them mentioned anywhere now.

@eddyb
Copy link
Member

eddyb commented Feb 1, 2015

Oh, I think this was is about conflicts between ident macros and hypothetical method macros (which you seem to be referring to). In which case, what I meant about UFCS is that it removes the requirement for the former (you wouldn't use ident macros for methods outside of macros yourself, I wouldn't think), leaving the obvious syntax for the latter.

@vadimcn
Copy link
Contributor

vadimcn commented Feb 1, 2015

So shall we reopen the RFC (and this PR)? Not being able to create new idents in macros is annoying.

lnicola pushed a commit to lnicola/rust that referenced this pull request Mar 13, 2023
feature: Make replace_or_with_or_else assists more generally applicable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants