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

Reserve macro identifiers #456

Closed
wants to merge 1 commit into from
Closed

Conversation

Manishearth
Copy link
Member

@Manishearth Manishearth mentioned this pull request Nov 9, 2014
@eddyb
Copy link
Member

eddyb commented Nov 9, 2014

Something that has been on my mind is using \ for escaping: we already need something like $($foo:ident)\+* to work, and this would also allow some future multi-level $ escaping, in a consistent manner.

@Manishearth
Copy link
Member Author

@eddyb That seems like a good idea-- however backslashes in macro definitions don't work anyway, so there's no need to reserve anything for now.

@huonw
Copy link
Member

huonw commented Nov 9, 2014

I don't think $$foo can currently be used for any syntax variables inside a macro_rules! (although it is definitely a valid sequence of tokens to pass to macros), and $_foo is just a syntax variable called _foo, which, to me, feels like a valid way to indicate that something is not being used (and I personally use it this way).

@Manishearth
Copy link
Member Author

@huonw Yeah, I noted in the RfC that it can't, but since it's a valid token to pass to macros I probably should edit the RfC to ask for it to be reserved everywhere.

As for $_foo, whenever a discussion crops up when we need a special builtin identifier for something in the context of macros, somehow the dollar-underscore combination always comes up. Since macros don't lint unused variables anyway, I guess it's not much of a disadvantage if $_foo is reserved.

@huonw
Copy link
Member

huonw commented Nov 9, 2014

whenever a discussion crops up when we need a special builtin identifier for something in the context of macros

FWIW, I've never seen any discussion of this form. I actually find it incredibly ugly (mainly theoretically, but also syntactically) but maybe because I'm just reading it as a token sequence $, _foo rather than the psuedo-token sequence $_, foo.

Since macros don't lint unused variables anyway, I guess it's not much of a disadvantage if $_foo is reserved.

Yet: there has been a few times where a bug in one of my macros would have been solved by being told that something was unused. I do see removing the option to add these diagnostics as a disadvantage.

@Manishearth
Copy link
Member Author

@huonw Hm, agreed. So what about simply focusing on $$foo and reserving tokens of that form? Or picking another prefix to reserve (I'd rather have both $$ and something else)?

@lifthrasiir
Copy link
Contributor

How about reserving $UPPERCASED variables instead?

@Manishearth
Copy link
Member Author

@lifthrasiir That's an interesting idea, but that seems to be too restrictive. Especially since it would leave out one-letter ones which might be useful.

@reem
Copy link

reem commented Nov 10, 2014

I prefer reserving $$foo for compiler-blessed stuff myself, I find it much more pleasing to look at then $_, which makes me think it is supposed to be hidden.

@Manishearth
Copy link
Member Author

@reem What if we need more than one? In the case of higher order macros, we might need a distinction. (eg $$ for user-defined higher order thingies, something else for compiler-blessed magic words)

@paulstansifer
Copy link

I believe that we're planning on using $$ to escape $ for macro-defining macros, though.

Another factor: we will eventually need to have special syntax for identifier concatenation: perhaps the two special syntaxes for these things could be related.

@Manishearth
Copy link
Member Author

Oh, right. In that case $$foo is out of the question. Anyone have any other ideas for a prefix?

@reem
Copy link

reem commented Nov 10, 2014

Why don't we use \$foo to escape macros-producing-macros? That feels more natural to me than $$ for escaping.

@huonw
Copy link
Member

huonw commented Nov 10, 2014

(Background: the macro-producing-macro syntax is covered by rust-lang/rust#6994.)

@nikomatsakis
Copy link
Contributor

During triage meeting, we discussed this PR and decided to close it. We already know we will eventually require a mechanism for introducing keywords into the language as a whole, and that same mechanism could presumably be used here as well. Furthermore, $$ is already reserved, as the RFC notes, which seems adequate.

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.

7 participants