It's been done, but what comes out is terrible Rust. Everything is unsafe types with C semantics.
An intelligent C to Rust translator would be a big win. You'd need to annotate the input C with info about how long arrays are and such, to guide the translator. It might be possible to use an LLM to analyze the code and provide annotations. Usually, C code does have array length info; it's just not in a form that the language ties to the array itself. If you see
char* buf = malloc(len);
the programmer knows that "buf" has length "len", but the programmer does not. Something needs to annotate "buf" with that info so that the translator knows it. Then the translator can generate Rust: let mut buf = vec![0;len];
The payoff comes at calls. C code: int write_to_device(char* buf, size_t len)
is a common idiom. LLMs are good at idioms. At this point, one can guess that this
is equivalent to fn write_to_device(buf: &[u8]) -> i32
in Rust. Then the translator has to track "len" to make sure that assert_eq!(buf.len(), len);
is either provably true, or put in that assert to check it at run time.
So that's a path to translation into safe Rust.Funding could probably be obtained from Homeland Security for this, given the new White House level interest in safe languages and the headaches being caused by the cyber war. Is CVS still down?