fix: support type aliases in binding files (#172) - #174
Merged
Conversation
Using a type alias (e.g. `pub type Amount = i64;`) as a parameter or
struct field type in an r2g binding file used to panic codegen
(`Option::unwrap()` on a missing struct entry) or emit references to a
nonexistent `AmountRef`.
- rust2go-common: expand non-generic type aliases (with chain resolution
and cycle detection) in struct fields and trait signatures at parse
time; generic arguments are expanded recursively.
- rust2go-common: add ParamType::to_rust_ref_assoc rendering
`<T as ToRef>::Ref` and use it for response ref types on the
proc-macro side, which cannot resolve aliases itself.
- rust2go-macro: r2g_derive emits `<#ty as ::rust2go::ToRef>::Ref` for
non-primitive ref fields instead of assuming `{ty}Ref`.
- test: cover aliases in struct fields, sync/async trait params and
return types, plus unit tests for the alias expansion.
lirenjie95
force-pushed
the
fix/172-type-alias
branch
from
August 24, 2026 08:27
3b1c16d to
d2a9b99
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #174 +/- ##
==========================================
+ Coverage 82.84% 83.52% +0.68%
==========================================
Files 18 18
Lines 3503 3672 +169
==========================================
+ Hits 2902 3067 +165
- Misses 601 605 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Using a type alias (e.g.
pub type Amount = i64;) as a parameter or struct field type in an r2g binding file used to crash codegen (Option::unwrap()on aNonein rust2go-common) or emit references to a nonexistentAmountRef. This PR makes type aliases work in binding files.Fixes #172
Changes
rust2go-common/src/common.rs:RawRsFile::newnow expands non-generic type aliases at parse time: alias chains are resolved (type A = B; type B = i64;), cycles are reported with a clear panic message, and usages are expanded recursively inside generic arguments (e.g.Vec<Alias>). Expansion applies to struct field types and trait method params/return types.ParamType::to_rust_ref_assoc, rendering the ref type as<T as ::rust2go::ToRef>::Ref— this form is correct for both concrete types and aliases (the alias shares the underlying type'sToRefimpl).Vec<Alias>, struct fields, trait params/returns).rust2go-common/src/r2g.rs: useto_rust_ref_assocfor response ref types in generated callbacks (3 sites) — the proc-macro side cannot resolve aliases itself.rust2go-macro/src/lib.rs:r2g_deriveemits<#ty as ::rust2go::ToRef>::Reffor non-primitive ref fields instead of assuming a{ty}Reftype name.test/: end-to-end coverage —pub type UserId = u64;used in a struct field (BalanceRequest), a sync trait method, and an async#[drop_safe]method with bare-alias params/return; Go impl + regenerated bindings + Rust tests.Testing
gen.goexpands alias fields touint64_tand Go signatures use*uint64.cargo fmt --check,cargo clippy --workspace --all-features --all-targets -- --deny warnings, and the full test suite (workspace, with mem-ring tested separately due to the known unrelated workspace feature-unification issue) all pass locally.