Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't generate #[main] and #![feature(main)] as it was removed #678

Closed
kkysen opened this issue Sep 25, 2022 · 2 comments
Closed

Don't generate #[main] and #![feature(main)] as it was removed #678

kkysen opened this issue Sep 25, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@kkysen
Copy link
Contributor

kkysen commented Sep 25, 2022

When the C main function is not int main() (such as void main()), c2rust transpile marks the transpiled fn main as #[main] and adds #![feature(main)] to the file. However, #[main] and #![feature(main)] have been removed in Rust for a while now since 2017 (in rust-lang/rust#29634) and are now both errors. We should stop emitting both of these. Given Rust no longer supports it, I don't think we should try to support non-standard main functions in C, which are implementation-defined anyways. In the specific case of void main() from #661, as well as other signatures that return void instead of int, we could still support them by just returning () from fn main.

@kkysen kkysen added the bug Something isn't working label Sep 25, 2022
@bytewife
Copy link
Contributor

Hey, I am re-running the culprit code in #661 and it appears that it transpiles main.c fine, and rustc compiles and runs main.rs as expected. I'm also unable to find where #[main] might be generated in /c2rust-transpile, so I believe this issue is no longer valid.
main.c:

#include <stdio.h>
void main() {
     // printf() displays the string inside quotation
     printf("Hello, World!");

}

main.rs:

#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case, non_upper_case_globals, unused_assignments, unused_mut)]
extern "C" {
    fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
}
unsafe fn main_0() {
    printf(b"Hello, World!\0" as *const u8 as *const libc::c_char);
}
pub fn main() {
    unsafe { main_0() }
    ::std::process::exit(0i32);
}
ivy:~/projects/c2rust_test_c is 📦 v0.1.0 via C v14.0.0-clang via △ v3.25.1 via 🦀 v1.68.0-nightly via 🐏 9GiB/16GiB took 24s450ms  cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/test`
Hello, World!%   

@kkysen
Copy link
Contributor Author

kkysen commented Feb 1, 2023

Thanks for checking this. #661 must've been using an old version of c2rust transpile, and I didn't check myself.

#[main] was removed in 2e4ef2a.

@kkysen kkysen closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants