Rust codegen: RustType.rustNestedBorrowedType produces uncompilable Option<&str> for nested nullable strings

Open Beginner friendly
#246 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust, typescript
Domain
backend

Research direction

Start with compiler/compiler/Compiler/Sources/Generation/Rust/RustTypes.swift and read RustType.rustNestedBorrowedType, then check its handling of nullable types. Reproduce with an array of optional strings or a generic model containing an optional string and compile the generated Rust. Done means the generated types use Option<valdi_core_rust::StringRef<'_>> and compile without the reported trait bound errors.

Written by the indexing model from the issue text.

Description

Found while reviewing https://github.com/Snapchat/Valdi/pull/211 (native Rust code generation). Not blocking that PR.

RustType.rustNestedBorrowedType produces uncompilable Option<&str> for nested nullable strings

File: compiler/compiler/Compiler/Sources/Generation/Rust/RustTypes.swift

When a TypeScript signature uses an array of optional strings ((string | undefined)[]) or passes an optional string to a generic model (Boxed<string | undefined>), the generated Rust code fails to compile with unsatisfied trait bounds on &str. RustType.rustNestedBorrowedType only converts .string to valdi_core_rust::StringRef<'_> and falls through to rustBorrowedType for all other cases.

For .nullable(.string), rustBorrowedType returns Option<&str>, so ArrayRef<'_, Option<&str>> and BoxedRef<'_, Option<&str>> are emitted instead of Option<valdi_core_rust::StringRef<'_>>. Because &str does not implement ValdiDeserialize or ValdiToOwned in valdi_core_rust, ArrayRef::get, ArrayRef::to_vec, and generic BoxedRef::to_owned all fail trait-bound checks in rustc.

Add a case .nullable(let inner): branch in RustType.rustNestedBorrowedType that returns "Option<\(inner.rustNestedBorrowedType)>".

Dominant language
C++
Stars
16.4k
Forks
539
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Snapchat/Valdi

All issues in Snapchat/Valdi

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.