docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0110: attribute on the wrong item

The attribute does not apply to this kind of item: #[export_name] on a generic or bodiless function, #[track_caller] on main, an attribute on a statement that only #[cfg] may take. Move it to an item it applies to, or remove it.

nabi
#[link_name("abs")]
fn my_abs(x: i32) -> i32 { x }
error[E0110]: `#[link_name]` cannot be attached to a function; it goes on an extern function
  --> main.nabi:1:1
   |
 1 | #[link_name("abs")]
   | ^^

Put the attribute on a function in an extern block:

nabi
extern "C" {
    #[link_name = "abs"]
    fn my_abs(x: i32) -> i32;
}
println(f"{unsafe { my_abs(-2) }}");
2

Related: E0109 malformed attribute

Found a mistake? Edit this page on GitHub. Last updated