-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
concat_idents can create empty identifiers #50403
Comments
Random aside: I thought I would try to do the same thing with error: expected identifier, found reserved identifier ``
--> test.rs:6:1
|
6 | prox_max::to_the_max!{}
| ^^^^^^^^^^^^^^^^^^^^^^^ expected identifier, found reserved identifier
error: expected expression, found reserved identifier ``
--> test.rs:6:1
|
6 | prox_max::to_the_max!{}
| ^^^^^^^^^^^^^^^^^^^^^^^ expected expression (the macro generated this, where ◌ is #[inline(never)]
#[no_mangle]
fn ◌() {
println!("hi there!");
}
fn main() {
◌();
} Edit: Hm. |
#![feature(concat_idents)]
fn main() {
let concat_idents!(fn) = 3; // ERROR non-pattern macro in pattern position
let x = concat_idents!(fn);
}
Edit: This is not an issue I think, because raw identifiers will enable you to do the same |
Forbid constructing empty identifiers from concat_idents The empty identifier is a [reserved identifier](https://github.com/rust-lang/rust/blob/8a37c75a3a661385cc607d934c70e86a9eaf5fd7/src/libsyntax_pos/symbol.rs#L300-L305) in rust, apparently used for black magicks like representing the crate root or somesuch... and therefore, being able to construct it is Ungood. Presumably. ...even if the macro that lets you construct it is so useless that you can't actually do any damage with it. (and believe me, I tried) Fixes rust-lang#50403. **Note:** I noticed that when you try to do something similar with `proc_macro::Term`, the compiler actually catches it and flags the identifier as reserved. Perhaps a better solution would be to somehow have that same check applied here.
I posted this casually on the tracking issue some months back:
I left it at that because I never thought there would be any serious discussion of stabilizing the feature. Never say never, huh?
This is an easy fix and I am working on a PR. I just made this issue so that I have a number to name the test case after. 🦆
The text was updated successfully, but these errors were encountered: