Skip to content

Suffix service trait name when it collides with Self keyword#27

Merged
iainmcgin merged 1 commit intomainfrom
fix/service-name-keyword
Apr 2, 2026
Merged

Suffix service trait name when it collides with Self keyword#27
iainmcgin merged 1 commit intomainfrom
fix/service-name-keyword

Conversation

@iainmcgin
Copy link
Copy Markdown
Collaborator

A proto service named Self is accepted by protoc but generates an invalid trait:

service Self {
  rpc Ping(Empty) returns (Empty);
}
generated code failed to parse: expected identifier, found keyword `Self`

codegen.rs builds the handler trait name as format_ident!("{}", service_name.to_upper_camel_case()) with no keyword handling. Self is the only PascalCase Rust keyword reachable this way (the suffixed SelfExt / SelfClient / SelfServer are fine). This is the same class of bug as #23 but for service names rather than method names.

Self cannot be a raw identifier, so the buffa-consistent fix is to suffix it (Self_), matching idents::make_field_ident behaviour for the non-raw-escapable set.

@iainmcgin iainmcgin marked this pull request as ready for review April 2, 2026 00:42
aaomidi
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`.
@iainmcgin iainmcgin force-pushed the fix/service-name-keyword branch from 2ef6e02 to ce9d0b0 Compare April 2, 2026 01:13
@iainmcgin iainmcgin merged commit 08f550b into main Apr 2, 2026
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants