Suffix service trait name when it collides with Self keyword#27
Merged
Suffix service trait name when it collides with Self keyword#27
Conversation
aaomidi
previously approved these changes
Apr 2, 2026
A proto service named `Self` (accepted by protoc) generated `trait Self`, which fails to parse since `Self` is a Rust keyword that cannot be a raw identifier. Suffix the bare trait name to `Self_` in that case. The derived `SelfExt`/`SelfClient`/`SelfServer` names are already safe; `server_name` is now built from the unsuffixed UpperCamelCase string alongside the others rather than from `trait_name`, so it stays `SelfServer` rather than `Self_Server`.
2ef6e02 to
ce9d0b0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A proto service named
Selfis accepted by protoc but generates an invalid trait:codegen.rsbuilds the handler trait name asformat_ident!("{}", service_name.to_upper_camel_case())with no keyword handling.Selfis the only PascalCase Rust keyword reachable this way (the suffixedSelfExt/SelfClient/SelfServerare fine). This is the same class of bug as #23 but for service names rather than method names.Selfcannot be a raw identifier, so the buffa-consistent fix is to suffix it (Self_), matchingidents::make_field_identbehaviour for the non-raw-escapable set.