rustriscv

How to fix "unsafe attribute used without unsafe" in custom attribute macro?


project: https://github.com/xiaguangbo/picorv32_and_rust

error code:

program_picorv32ec/project/src/main.rs

#[picorv32asm::entry]
fn main() -> ! {
    loop {}
}

error message:

$ cargo build
   Compiling picorv32asm v0.1.0 (/home/xiaguangbo/linux/project/custom_rv32_rust/program_picorv32ec/picorv32asm)
   Compiling project v0.1.0 (/home/xiaguangbo/linux/project/custom_rv32_rust/program_picorv32ec/project)
   Compiling picorv32entrymacro v0.1.0 (/home/xiaguangbo/linux/project/custom_rv32_rust/program_picorv32ec/picorv32asm/picorv32entrymacro)
error: unsafe attribute used without unsafe
--> src/main.rs:6:1
  |
6 | #[picorv32asm::entry]
  | ^^^^^^^^^^^^^^^^^^^^^ usage of unsafe attribute
  |
  = note: this error originates in the attribute macro `picorv32asm::entry` (in Nightly builds, run with -Z macro-backtrace for more info)
help: wrap the attribute in `unsafe(...)`
  |
6 | unsafe(#[picorv32asm::entry])
  | +++++++                     +

error: could not compile `project` (bin "project") due to 1 previous error

It doesn't work either if you follow the compiler's prompts.

I think other projects can also be written like this, such as wch rust project.


Solution

  • delete `edition = 2024` for program_picorv32ec/picorv32asm/picorv32entrymacro/Cargo.toml