Skip to content

New lints: Safe items inside unsafe extern #975

@obi1kenobi

Description

@obi1kenobi

A new feature in Rust 1.82+ is the ability to define safe items inside an unsafe extern block:
https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#safe-items-with-unsafe-extern

unsafe extern {
    pub safe static TAU: f64;
    pub safe fn sqrt(x: f64) -> f64;
    pub unsafe fn strlen(p: *const u8) -> usize;
}

Making a previously-safe item become unsafe is a major breaking change, since it now requires unsafe at the point of use.

At least two lints, and possibly more:

  • safe extern static became unsafe
  • safe extern fn became unsafe

I believe we'll also need additional schema in the adapter to model extern items and show which items are safe vs unsafe. This shouldn't be too difficult to add, though it's an extra step compared to "just writing a lint." For folks new to contributing to Trustfall, I'd recommend first writing another lint that doesn't need this extra step before moving to this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: new or existing lintE-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: Mentorship is available for this issue.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions