question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disallow keywords as macro arguments names

See original GitHub issue

Proposal

Summary and problem statement

It was recently determined https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/postfix.20macros/near/216030097 that self and if and such are valid as identifiers in macros ($self, $if, etc).

That prevents adding new things like $crate, since there are no reserved identifiers. So it would be nice to treat them like normal identifiers, where keywords are not allowed. And because these are just identifiers, and thus unaffected by alpha-conversion, all expressible macros are still expressible. (And arguably not calling things $if is probably good.)

Motivation, use-cases, and solution sketches

This would just be an edition change for the edition in which the macro is written.

Prioritization

This would need to happen fairly promptly if it were to make it for the 2021 edition.

Links and related work

https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/postfix.20macros/near/216031552

Initial people involved

@joshtriplett

What happens now?

This issue is part of the experimental MCP process described in RFC 2936. Once this issue is filed, a Zulip topic will be opened for discussion, and the lang-team will review open MCPs in its weekly triage meetings. You should receive feedback within a week or two.

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
joshtriplettcommented, Nov 17, 2020

Discussion in today’s lang team meeting: the only urgency would be if we’re going to prohibit keywords, and that’s sufficiently high impact that we likely won’t end up doing it, even without having to do a full crater run. We’re more likely to accept an alternative syntax, such as $$ or similar, that isn’t currently valid syntax. And if we go that path, this doesn’t need to be tied to an edition.

0reactions
scottmcmcommented, Nov 19, 2020

The “let’s just do better in macros 2.0” from the meeting was persuasive to me.

Given that anything going to happen here would be substantially more than what I described in the OP, I’m going to close. Anyone motivated to take up the larger task should absolutely make a new proposal, however.

Read more comments on GitHub >

github_iconTop Results From Across the Web

May the name of a macro parameter be a keyword?
I defined a macro in my code and accidentally used the keyword int as the variable name of parameter of that macro. The...
Read more >
Macro Arguments (The C Preprocessor)
To invoke a macro that takes arguments, you write the name of the macro followed by a list of actual arguments in parentheses,...
Read more >
Keywords shall not be used as macros identifiers
In programming languages keywords have a special meaning and are reserved to the language. It is hence a bad idea to define macros...
Read more >
Keyword arguments without a keyword? - Internals & Design
I've been using a macro get this syntax, but its not very elegant because only way I figured to make it work was...
Read more >
MACRO Statement - SAS Help Center
A parameter list can contain any number of macro parameters separated by commas. ... If both positional and keyword parameters appear in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found