subtype,
@subtype@insufferable.tools avatar

Why are compilers like this.

// <a href="http://main.rs" rel="ugc">main.rs</a>
#![no_main]
#![no_std]

#[no_mangle]
pub unsafe extern "C" fn foo() -> i32 {
    return 0;
}

$ rustc -O --target=wasm32-unknown-unknown <a href="http://main.rs" rel="ugc">main.rs</a> -o main.wasm
error: `#[panic_handler]` function required, but not found

error: aborting due to 1 previous error

but then

#![no_main]
#![no_std]

use core::panic::PanicInfo;

#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
    loop {}
}

#[no_mangle]
pub unsafe extern "C" fn foo() -> i32 {
    return 0;
}

$ rustc -O --target=wasm32-unknown-unknown <a href="http://main.rs" rel="ugc">main.rs</a> -o main.wasm
$ wasm2wat main.wasm -o main.wat
$ cat main.wat
(module
  (type (;0;) (func (result i32)))
  (func $foo (type 0) (result i32)
    i32.const 0)
  (memory (;0;) 16)
  (global $__stack_pointer (mut i32) (i32.const 1048576))
  (global (;1;) i32 (i32.const 1048576))
  (global (;2;) i32 (i32.const 1048576))
  (export "memory" (memory 0))
  (export "foo" (func $foo))
  (export "__data_end" (global 1))
  (export "__heap_base" (global 2)))

Where’s the panic that you wanted so much, rustc? And no, -Cpanic=abort changes nothing.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • Hentai
  • doujinshi
  • announcements
  • general
  • All magazines