This isn't limited to C. If you run compiles as root, game over.
fn main() {
let shadow = include_str!("/etc/shadow");
println!("{}", shadow);
}
That's why OpenBSD ports clusters uses unprivileged users for fetching and building (with no network access/chroot).