Skip to content

Escape Rust keywords in generated RPC method names#26

Merged
iainmcgin merged 5 commits intomainfrom
fix/issue-23-keyword-method-names
Apr 2, 2026
Merged

Escape Rust keywords in generated RPC method names#26
iainmcgin merged 5 commits intomainfrom
fix/issue-23-keyword-method-names

Conversation

@iainmcgin
Copy link
Copy Markdown
Collaborator

Fixes #23.

An RPC method whose snake_case name collides with a Rust keyword (e.g. rpc Move(...)move) caused codegen to emit invalid identifiers, failing at build-script time with expected identifier, found keyword.

This routes method-name idents through buffa_codegen::idents::make_field_ident, which already handles this for message fields:

  • raw-escapes ordinary keywords: mover#move
  • suffixes the four that cannot be raw idents: selfself_

Covers all four emission sites (trait method, route registration, server dispatch, client method) plus the client doc-comment example. The _with_options client variant is left as-is since the suffix already de-keywords it.

Adds regression tests for both escaping paths (Move and Self), each asserting the full output round-trips through syn::parse_str.

An RPC method whose snake_case name collides with a Rust keyword (e.g.
`rpc Move(...)` -> `move`) caused codegen to emit invalid identifiers
that syn rejects at build-script time.

Route method-name idents through buffa_codegen::idents::make_field_ident,
which raw-escapes keywords (`r#move`) and suffixes the few that cannot
be raw (`self_`). The `_with_options` client variant is already safe
since the suffix de-keywords it.

Fixes #23.
@iainmcgin iainmcgin marked this pull request as ready for review April 2, 2026 00:40
@iainmcgin iainmcgin enabled auto-merge (squash) April 2, 2026 00:52
@iainmcgin iainmcgin merged commit 973a548 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.

Failed to generate code when there is a rpc service called Move

2 participants