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

Disallow keywords as macro arguments names #68

Closed
scottmcm opened this issue Nov 8, 2020 · 8 comments
Closed

Disallow keywords as macro arguments names #68

scottmcm opened this issue Nov 8, 2020 · 8 comments
Labels
final-comment-period The FCP has started, most (if not all) team members are in agreement major-change Major change proposal T-lang to-announce Not yet announced MCP proposals

Comments

@scottmcm
Copy link
Member

scottmcm commented Nov 8, 2020

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.

@scottmcm scottmcm added major-change Major change proposal T-lang labels Nov 8, 2020
@rustbot
Copy link
Collaborator

rustbot commented Nov 8, 2020

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.

@rustbot rustbot added the to-announce Not yet announced MCP proposals label Nov 8, 2020
@joshtriplett
Copy link
Member

Cross-referencing: rust-lang/reference#863

@joshtriplett joshtriplett changed the title Disallow keywords and macro arguments names Disallow keywords as macro arguments names Nov 9, 2020
@joshtriplett
Copy link
Member

joshtriplett commented Nov 9, 2020

I'll second this. I think it's a reasonable change to make, orthogonally to whatever further changes we might make that would use the syntax this reserves.

Clarifying edit: I'm agreeing in principle that this seems like a good idea and is worth pursuing, in the spirit of the MCP process, but I still expect that this will go through a crater run and similar to gauge impact.

@joshtriplett
Copy link
Member

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Nov 9, 2020
@nikomatsakis
Copy link
Contributor

Summary of Zulip comments:

@nikomatsakis
Copy link
Contributor

Discussion from 2020-11-10:

  • Motivation: forwards compatibility with new ideas around macros
  • Are self and super keywords in the sense we mean here? (We believe so, or at least they can't be used as variable names -- may be different from Self.)
  • Would want to do a crater run to try and measure impact, but $self will be the most common
  • Migration plan: $x can go to $r#x, for $self could do $this specifically (presuming it's not in use)
  • Maybe we want to use a different syntax for things like $crate, that are not naming bindings but instead a "special path"

Conclusion of the meeting:

  • Consensus that we need ability to expand macros in the future, but not convinced that $+keyword is the best plan, that would be one option but not the only one.
    • Have to decide who will lead that discussion if we feel it is in scope.
    • Note that alternative syntax would not require an edition change.
    • Crater run to evaluate impact.

@joshtriplett
Copy link
Member

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.

@scottmcm
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
final-comment-period The FCP has started, most (if not all) team members are in agreement major-change Major change proposal T-lang to-announce Not yet announced MCP proposals
Projects
None yet
Development

No branches or pull requests

4 participants