| ▲ | Animats 3 hours ago | |||||||||||||||||||
> "Tbh they could've just hooked up zig translate-c to c2rust". Have you ever seen what comes out of c2rust? It's awful. It relies on a library of functions which emulate unsafe C pointer semantics with unsafe Rust. A few years ago, when I was struggling with bugs in OpenJPEG (a JPEG 2000 decoder), someone tried running it through c2rust. The converted unsafe rust segfaulted at the same place the C code did. It's compatible, but not safe. Main insight: don't do string manipulation in C or unsafe Rust. It's totally the wrong tool for the job. | ||||||||||||||||||||
| ▲ | dathinab 2 hours ago | parent | next [-] | |||||||||||||||||||
> Have you ever seen what comes out of c2rust? It's awful. It relies on a library of functions which emulate unsafe C pointer semantics with unsafe Rust. which is somewhat close to what their port produced... like their goal was from the get to go to have a mostly exactly the same as zig "just in rust" which implies mostly unsafe rust and all the soundness/memory issues zig has (plus probably some more due to AI based port instead of a tool like c2ruts) the thing is if you don't keep things mostly 1:1 with all the problems that has there is absolutely no way to review that PR or catch the AI going rogue with hallucinations etc. With a mostly 1:1 port you can at least check if things seem mostly the same. but it also means this is just step 1 of very many, with the other being incrementally fixing soundness, removing unsafe and (hopefully) making the code more idiomatic... (to got to the actual question of why?, I think the answer is doing this port using AI is likely way easier/faster then first writing a tool which need in depth understanding of the languages, especially given that some features in zig do not map 1:1 in rust and fuzzily mapping is what LLMs are good at and human hand written tools tend to be very bad at). | ||||||||||||||||||||
| ▲ | swiftcoder 3 hours ago | parent | prev | next [-] | |||||||||||||||||||
> The converted unsafe rust segfaulted at the same place the C code did. It's compatible, but not safe That is indeed the point of c2rust. It gives you a baseline that is semantically identical to the original codebase, and with that passing the full test suite, bug-for-bug, you can then start gradually adopting rusty idioms to improve the memory safety of the codebase. | ||||||||||||||||||||
| ||||||||||||||||||||
| ▲ | Animats 3 hours ago | parent | prev | next [-] | |||||||||||||||||||
The module with the code mentioned is at [1] This is awful. They have some internal string format borrowed from a Zig library where the address of the item is in the low end of a pointer and the length is at the high end. Why are they doing that in 2026? It lets you save a few bytes at best. It doesn't enforce the Rust rule that strings must be strict UTF-8. It's totally alien to the safe way Rust handles strings. [1] https://github.com/oven-sh/bun/blob/main/src/bun_core/string... | ||||||||||||||||||||
| ||||||||||||||||||||
| ▲ | wrs 3 hours ago | parent | prev | next [-] | |||||||||||||||||||
What they’ve done here isn’t safe either, and doesn’t have the consistent translation of rust2c. | ||||||||||||||||||||
| ▲ | xienze 2 hours ago | parent | prev [-] | |||||||||||||||||||
Sure, but the point remains. They could've used Claude to build a Zig to Rust converter, ended up with something that was both deterministic _and_ beneficial to the wider community. | ||||||||||||||||||||