Skip to content

support safe fn in imports #118

@Wasabi375

Description

@Wasabi375

I want to use safe extern functions added with rust 1.82: https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-extern.html

#[stabby::import(canaries = "", name = "library")]
#[allow(improper_ctypes)]
unsafe extern "C" {
    pub safe fn unstable_fn(v: &[u8]);
}

but I get the following compiler error:

error: custom attribute panicked
  --> examples/dynlinkage/src/main.rs:20:1
   |
20 | #[stabby::import(canaries = "", name = "library")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: called `Result::unwrap()` on an `Err` value: Error("expected `extern`")

The problem is that this crate uses syn version "1.0" which is almost 3 years old. This means that supporting any new rust features would require an upgrade syn version 2.

I'd be happy to create a PR.

In that case I would also like to improve the error reporting. Right now errors are generated using panics which is fine but it means that errors are reported at the macro invocation (#[import]) instead of the exact line where the error originates.
That could be improved with the use of syn::Error::new(span, "error message").to_compile_error() https://docs.rs/syn/latest/syn/struct.Error.html#method.into_compile_error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions