fix(rust): escape Rust keywords in union constructor names and deconflict unknown#16635
fix(rust): escape Rust keywords in union constructor names and deconflict unknown#16635devin-ai-integration[bot] wants to merge 2 commits into
unknown#16635Conversation
…lict unknown Fixes two bugs in UnionGenerator.ts that cause generated Rust code to fail compilation: 1. Union variant constructor names that are Rust keywords (static, override, etc.) now use r# raw identifier prefix. 2. The forward-compatible catch-all constructor deconflicts to 'unknown_value' when a real variant already produces an 'unknown' constructor name. Adds regression test with KeywordUnion type exercising both fixes. Resolves FER-11400 Co-Authored-By: judah <jsklan.development@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
There was a problem hiding this comment.
🚩 Missing model generator changelog entry
The code change is in generators/rust/model/src/union/UnionGenerator.ts, which belongs to the model generator (independently versioned at generators/rust/model/versions.yml). The PR only adds a changelog entry for the SDK generator (generators/rust/sdk/changes/unreleased/fix-union-keyword-escaping.yml). The model generator doesn't use a changes/unreleased/ workflow — its versions.yml is edited directly in PRs. Since the model generator is released independently (as shown by its own version history), this fix would not be reflected in model generator release notes. The SDK changelog covers the SDK release, but users of the standalone model generator would miss this fix in their changelogs.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Intentional — rust-model doesn't have its own changelog/release entry. The SDK depends on the model package ("@fern-api/rust-model": "workspace:*") and publishes them together, so the SDK changelog is the correct place.
Handles edge case where both 'unknown' and 'unknown_value' variants exist by iterating until a collision-free name is found. Co-Authored-By: judah <jsklan.development@gmail.com>
Description
Linear ticket: Closes FER-11400
Fixes two compilation errors in generated Rust code for discriminated unions in
UnionGenerator.ts:static,override, etc.) now emitr#raw identifier prefix viaescapeRustKeyword.unknown_valuewhen a real variant already uses theunknownname.Changes Made
this.context.escapeRustKeyword()ingenerateVariantConstructorgetUnknownConstructorName()helper that returns"unknown_value"when a real variant collidesKeywordUnionregression test (discriminants:static,override,unknown) to the snapshot harnessGenerated output for the regression test:
Testing
KeywordUniontypepnpm --filter @fern-api/rust-model testpasses (16/16)Link to Devin session: https://app.devin.ai/sessions/797a62f254f3410cbe25eab33737157d
Requested by: @jsklan