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

Đang mở Phù hợp với người mới
#246 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
83/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust, typescript
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với compiler/compiler/Compiler/Sources/Generation/Rust/RustTypes.swift và đọc RustType.rustNestedBorrowedType, sau đó kiểm tra cách xử lý các kiểu nullable. Tái hiện lỗi bằng một mảng các chuỗi tùy chọn hoặc một mô hình generic chứa một chuỗi tùy chọn, rồi biên dịch Rust được tạo ra. Hoàn tất khi các kiểu được tạo ra sử dụng Option<valdi_core_rust::StringRef<'_>> và biên dịch mà không gặp các lỗi trait bound đã nêu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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)>".

Ngôn ngữ chính
C++
Star
16.4k
Fork
539
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Snapchat/Valdi

Tất cả issue của Snapchat/Valdi

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.