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

Unsupported raw identifiers in 0.5 #179

Closed
fujiapple852 opened this issue Apr 30, 2019 · 2 comments
Closed

Unsupported raw identifiers in 0.5 #179

fujiapple852 opened this issue Apr 30, 2019 · 2 comments

Comments

@fujiapple852
Copy link
Contributor

I have a proto file (that I do not control) which contains a field named self (of type Unit). In PROST 0.4 this is generated as Self_ which works whereas in PROST 0.5 it is generated as r#Self which fails to compile in stable rust (1.34) with r#Self is not currently supported (see discussion on why here).

Workaround is either to use PROST 0.4 (which in turn forces using Rust 2015 and therefore the PROST generated code needs to be in a separate crate for Rust 2018 projects) or some clunky pre or post processing of the proto file or generated code.

Suggested fix: revert to appending an _ to keyword identifiers for the list of 5 keywords not supported by raw identifiers.

Aside: I tried using the field_attributes option to prepend an _ to the field but this doesn't work as it is rendered as a separate token to the identifier:

    #[prost(message, tag="1")]
    _
    r#Self(super::Unit),
@fujiapple852
Copy link
Contributor Author

fujiapple852 commented Apr 30, 2019

I made a simple local fix to the to_snake and to_upper_camel functions to resolve the issue.

A little investigation suggests that self, Self, super, extern & crate keywords need to be excluded from the raw identifier handling and instead suffixed with an underscore.

Fix submitted in PR https://github.com/danburkert/prost/pull/180

@danburkert
Copy link
Collaborator

Fixed in #180, thanks!

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

No branches or pull requests

2 participants