I say it can be done and it’s not that hard and it’s a small and self-contained patch
Conversation
The hardest part is actually understanding/language lawyering the C standard
2
I'd like to see this as a Cargo crate. It could be a self contained C compiler callable from build.rs crates.
1
1
I think the cool thing about rustc doing it is you wouldn't need to have the intermediate output and could actually have compiler errors referring to C code instead of intermediate output that a human didn't write.
1
Only other thing that annoys me is that Rust code ends up not being able to use inline variants of C functions automatically and that would be a lot harder than just handling declarations. Going to be a major perf hit for Rust modules in the Linux kernel without using LTO builds.
1
Wait, what? You’re claiming that giving rustc a first-class notion of all of the C code wouldn’t help?
1
Well, I'm assuming there's quite a difference between being able to understand the declarations and a full understanding of how to compile C code with support for all the commonly used GNU extensions, etc.
1
Despite all the extensions and asides from C's ABSOLUTELY BONKERS "declarators" syntax, C frontends can be surprisingly cheap in terms of size and throughput. As long as we don't need serious codegen this can probably go nicely in a crate.
1
1
It would be compiled into Rust, or if it was part of the compiler into the same intermediate format as Rust. It shouldn't need a separate code generation backend.
There's a big difference in levels of support for C code though.


