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

"__r#type" is not a valid identifier #839

Closed
ShadowJonathan opened this issue Nov 20, 2021 · 3 comments · Fixed by #841
Closed

"__r#type" is not a valid identifier #839

ShadowJonathan opened this issue Nov 20, 2021 · 3 comments · Fixed by #841

Comments

@ShadowJonathan
Copy link

ShadowJonathan commented Nov 20, 2021

I currently have to work with the raw identifier r#type, as one database table is using this. I can't change this name, as i'm merely reading out the data from a pre-existing format.

However, when i try to put in a struct format, like so;

#[derive(Debug, ToSql, FromSql)]
struct DeviceInboxMessageFormat {
    pub messages: Json<HashMap<UserId, HashMap<DeviceId, Value>>>,
    pub sender: UserId,
    pub r#type: String,
}

The proc-macro panics on;

error: proc-macro derive panicked
  --> adapters/synapse/src/extract.rs:83:24
   |
83 | #[derive(Debug, ToSql, FromSql)]
   |                        ^^^^^^^
   |
   = help: message: `"__r#type"` is not a valid identifier

I think this problem will be the same across all raw identifiers.

@sfackler
Copy link
Owner

It looks like it's due to this line: https://github.com/sfackler/rust-postgres/blob/master/postgres-derive/src/fromsql.rs#L122, which is actually mirroring an example in proc-macro2: https://docs.rs/proc-macro2/1.0.32/proc_macro2/struct.Ident.html#examples.

It may be a bug in either proc-macro2 or the stdlib proc-macro?

@ShadowJonathan
Copy link
Author

ShadowJonathan commented Nov 20, 2021

dtolnay/proc-macro2#234, the examples arent correct enough, this is right behaviour, raw identifiers need to be handled differently, it seems.

@sfackler
Copy link
Owner

dtolnay/proc-macro2#302

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 a pull request may close this issue.

2 participants