Skip to content

Update #[host_fn] to match Rust's extern block rules since 1.82 #78

@MolotovCherry

Description

@MolotovCherry

Since rust 1.82, it was decided that extern blocks should be unsafe, and safe fn variants was also added to it.

// I assert all items in extern block are correct
unsafe extern {
    // safe fn
    pub safe fn foo();
    // unsafe fn
    pub unsafe fn bar();
    // default unsafe fn
    pub fn foobar();
}

In light of these changes, I think it makes sense to allow #[host_fn] to more closely match the new way of doing things. The current way #[host_fn] does things matches the old Rust behavior before the change.

On < 1.82 <= 2021 the old way is done. On >= 1.82 <= 2021 the new way is supported but not enforced (but is strongly encouraged). On 1.85* >= 2024, the new way is required
* the version when 2024 was released

In the context of #[host_fn]:

  • unsafe extern signifies the writers assertion that all items in the extern block are correct
  • in combination with the above, we can now allow safe fn since we have made a safety assertion

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