Skip to content

fix: escape Rust keyword field/oneof names in generated accessors#14

Closed
connyay wants to merge 1 commit into
mathematic-inc:mainfrom
connyay:cjh-reserved-keywords
Closed

fix: escape Rust keyword field/oneof names in generated accessors#14
connyay wants to merge 1 commit into
mathematic-inc:mainfrom
connyay:cjh-reserved-keywords

Conversation

@connyay

@connyay connyay commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

The plugin built field accessors (self.<field>) straight from raw proto names, so any field or oneof named with a Rust keyword broke codegen: format_ident! emitted invalid self.type, parse_str::<Ident> returned Err, and Ident::new/new_raw panicked on non-raw-able keywords like self. buffa names the underlying struct fields via make_field_ident (type -> r#type, self -> self_), so the accessors never lined up.

Route every proto-name -> ident site through a shared field_ident helper that delegates to buffa_codegen::idents::make_field_ident, guaranteeing the emitted accessors match buffa's generated structs by construction. Covers the field-CEL, predefined-rule, CEL field-select, oneof, and message-oneof paths, and replaces the incomplete local safe_ident (which panicked on self/super/Self/crate).

Add tests/keyword_idents.rs exercising the real emit::render pipeline for keyword-named fields and oneofs.

The plugin built field accessors (`self.<field>`) straight from raw proto
names, so any field or oneof named with a Rust keyword broke codegen:
`format_ident!` emitted invalid `self.type`, `parse_str::<Ident>` returned
`Err`, and `Ident::new`/`new_raw` panicked on non-raw-able keywords like
`self`. buffa names the underlying struct fields via `make_field_ident`
(`type` -> `r#type`, `self` -> `self_`), so the accessors never lined up.

Route every proto-name -> ident site through a shared `field_ident` helper
that delegates to `buffa_codegen::idents::make_field_ident`, guaranteeing the
emitted accessors match buffa's generated structs by construction. Covers the
field-CEL, predefined-rule, CEL field-select, oneof, and message-`oneof`
paths, and replaces the incomplete local `safe_ident` (which panicked on
`self`/`super`/`Self`/`crate`).

Add tests/keyword_idents.rs exercising the real emit::render pipeline for
keyword-named fields and oneofs.
@jrandolf

Copy link
Copy Markdown
Contributor

Fixed in #17.

@jrandolf jrandolf closed this Jun 28, 2026
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 this pull request may close these issues.

2 participants