Fix Go and Rust generator edge cases#1596
Merged
Merged
Conversation
Update the Go generator to avoid discriminator method collisions only when a generated variant field would otherwise conflict. Update the Rust generator to keep RPC methods using internal schemas crate-private and allow intentionally unused generated internal items. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Go and Rust code generators to handle schema edge cases that previously produced naming collisions (Go discriminated unions) or invalid public API surfaces (Rust typed RPC methods referencing internal-only schemas), and regenerates the affected Rust outputs accordingly.
Changes:
- Go: choose a discriminator accessor method name that avoids collisions with actually-emitted variant struct fields by falling back to an unexported union-prefixed method name only when needed.
- Rust: make typed RPC methods
pub(crate)when their params/result types resolve to internal schemas, and suppress resultingdead_codewarnings in generated modules so Rust CI (clippy/docs with-D warnings) remains clean. - Regenerated Rust
api_types.rsandrpc.rsto reflect the generator updates.
Show a summary per file
| File | Description |
|---|---|
| scripts/codegen/rust.ts | Makes typed RPC methods crate-private when they depend on internal schemas; adds dead_code allow to generated Rust modules. |
| scripts/codegen/go.ts | Adds discriminator accessor naming logic to avoid method/field collisions in generated discriminated unions. |
| rust/src/generated/rpc.rs | Regenerated output: adds #![allow(dead_code)] to avoid CI failures from unused crate-private items. |
| rust/src/generated/api_types.rs | Regenerated output: adds #![allow(dead_code)] to avoid CI failures from unused internal generated types. |
Copilot's findings
- Files reviewed: 2/4 changed files
- Comments generated: 0
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The Go generator used discriminator accessor names like
Kind,Type, orIsRemotedirectly. That preserves a useful generated API, but it can collide when a discriminator property is also emitted as a Go struct field. This change keeps the existing accessor name unless an actually emitted variant field would conflict, then uses an unexported union-prefixed method name.The Rust generator could expose public RPC methods whose params or results resolve to internal generated schemas. This keeps those methods crate-private and allows intentionally unused generated internal support items.
Validation
nodejsdependencies from the lockfile and regenerated Go/Rust against@github/copilot1.0.57.cd go && go test -run '^$' ./...cd rust && cargo +nightly-2026-04-14 fmt --all -- --config-path .rustfmt.nightly.tomlcd rust && cargo test --no-runGenerated by Copilot